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
whose elements are not the ratios of small integers, so sym(E)
reproduces the floating-point representation in a symbolic form:
[3060513257434037*2^(-50), 3184525836262886*2^(-51)] [2473854946935174*2^(-51), 3944418039826132*2^(-54)]
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
F = [2.718281828459045534884808, 1.414213562373094923430017] [1.098612288668110004152823, .2189591863280899719512718]
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 | ![]() |