Accelerating the pace of engineering and science

# Documentation

## Symbolic Objects

### Overview of Symbolic Objects

Symbolic objects are a special MATLAB® data type introduced by the Symbolic Math Toolbox™ software. They enable you to perform mathematical operations in the MATLAB workspace analytically, without calculating numeric values. You can use symbolic objects to perform a wide variety of analytical computations:

• Differentiation, including partial differentiation

• Definite and indefinite integration

• Taking limits, including one-sided limits

• Summation, including Taylor series

• Matrix operations

• Solving algebraic and differential equations

• Variable-precision arithmetic

• Integral transforms

Symbolic objects are symbolic variables, symbolic numbers, symbolic expressions, symbolic matrices, and symbolic functions.

### Symbolic Variables

To declare variables x and y as symbolic objects use the syms command:

`syms x y`

You can manipulate the symbolic objects according to the usual rules of mathematics. For example:

`x + x + y`
```ans =
2*x + y```

You also can create formal symbolic mathematical expressions and symbolic matrices. See Create Symbolic Variables and Expressions for more information.

### Symbolic Numbers

Symbolic Math Toolbox software also enables you to convert numbers to symbolic objects. To create a symbolic number, use the sym command:

`a = sym('2')`

If you create a symbolic number with 15 or fewer decimal digits, you can skip the quotes:

`a = sym(2)`

The following example illustrates the difference between a standard double-precision MATLAB data and the corresponding symbolic number. The MATLAB command

`sqrt(2)`

returns a double-precision floating-point number:

```ans =
1.4142```

On the other hand, if you calculate a square root of a symbolic number 2:

`a = sqrt(sym(2))`

you get the precise symbolic result:

```a =
2^(1/2)```

Symbolic results are not indented. Standard MATLAB double-precision results are indented. The difference in output form shows what type of data is presented as a result.

To evaluate a symbolic number numerically, use the double command:

`double(a)`
```ans =
1.4142```

You also can create a rational fraction involving symbolic numbers:

`sym(2)/sym(5)`
```ans =
2/5```

or more efficiently:

`sym(2/5)`
```ans =
2/5```

MATLAB performs arithmetic on symbolic fractions differently than it does on standard numeric fractions. By default, MATLAB stores all numeric values as double-precision floating-point data. For example:

`2/5 + 1/3`
```ans =
0.7333```

If you add the same fractions as symbolic objects, MATLAB finds their common denominator and combines them in the usual procedure for adding rational numbers:

`sym(2/5) + sym(1/3)`
```ans =
11/15```

To learn more about symbolic representation of rational and decimal fractions, see Estimate Precision of Numeric to Symbolic Conversions.