Symbolic Math Toolbox | ![]() ![]() |
Symbolic Objects
The Symbolic Math Toolbox defines a new MATLAB data type called a symbolic object or sym
(see the MATLAB topic Programming and Data Types for an introduction to MATLAB classes and objects). Internally, a symbolic object is a data structure that stores a string representation of the symbol. The Symbolic Math Toolbox uses symbolic objects to represent symbolic variables, expressions, and matrices.
The following example illustrates the difference between a standard MATLAB data type, such as double, and the corresponding symbolic object. The MATLAB command
returns a floating-point decimal number:
On the other hand, if you convert 2 to a symbolic object using the sym
command, and then take its square root by entering
MATLAB gives the result 2^(1/2)
, which means 21/2, or , using symbolic notation for the square root operation, without actually calculating a numerical value. MATLAB records this symbolic expression in the string that represents
2^(1/2)
. You can always obtain the numerical value of a symbolic object with the double
command:
When you create a fraction involving symbolic objects, MATLAB records the numerator and denominator. For example:
MATLAB performs arithmetic on symbolic objects differently than it does on standard data types. If you two fractions that are of data type double
, MATLAB gives the answer as a decimal fraction. For example:
If you add the same fractions as symbolic objects, MATLAB finds their common denominator and combines them by the usual procedure for adding rational numbers:
The Symbolic Math Toolbox enables you to perform a variety of symbolic calculations that arise in mathematics and science. These are described in detail in Using the Symbolic Math Toolbox.
![]() | Getting Started | Creating Symbolic Variables and Expressions | ![]() |