Symbolic Math Toolbox    

Example: Using the Different Kinds of Arithmetic

Rational Arithmetic

By default, the Symbolic Math Toolbox uses rational arithmetic operations, i.e., Maple's exact symbolic arithmetic. Rational arithmetic is invoked when you create symbolic variables using the sym function.

The sym function converts a double matrix to its symbolic form. For example, if the double matrix is

its symbolic form, S = sym(A), is

For this matrix A, it is possible to discover that the elements are the ratios of small integers, so the symbolic representation is formed from those integers. On the other hand, the statement

returns a matrix

whose elements are not the ratios of small integers, so sym(E) reproduces the floating-point representation in a symbolic form:

Variable-Precision Numbers

Variable-precision numbers are distinguished from the exact rational representation by the presence of a decimal point. A power of 10 scale factor, denoted by 'e', is allowed. To use variable-precision instead of rational arithmetic, create your variables using the vpa function.

For matrices with purely double entries, the vpa function generates the representation that is used with variable-precision arithmetic. Continuing on with our example, and using digits(4), applying vpa to the matrix S

generates the output

and with digits(25)

generates

Converting to Floating-Point

To convert a rational or variable-precision number to its MATLAB floating-point representation, use the double function.

In our example, both double(sym(E)) and double(vpa(E)) return E.


  Variable-Precision Arithmetic Another Example