Graphics Programs Reference
In-Depth Information
a=
1
>> b = a/sym(2)
b=
1/2
MATLAB was designed so that some floating point numbers are restored
to their exact values when converted to symbolic. Integers, rational numbers
withsmall numerators and denominators, square roots of small integers, the
number π , and certain combinations of these numbers are so restored. For
example,
>> c = sqrt(3)
c=
1.7321
>> sym(c)
ans =
sqrt(3)
Since it is difficult to predict when MATLAB will preserve exact values, it is
best to suppress the floating point evaluation of a numeric argument to sym by
enclosing it in single quotes to make it a string, e.g., sym('1 + sqrt(3)') .
We will see below another way in which single quotes suppress evaluation.
Functions and Expressions
We have used the terms expression and function without carefully making a
distinction between the two. Strictly speaking, if we define f ( x ) = x 3
1, then
f (written without any particular input) is a function while f ( x ) and x 3
1
are expressions involving the variable x . In mathematical discourse we often
blur this distinction by calling f ( x )or x 3
1 a function, but in MATLAB the
difference between functions and expressions is important.
In MATLAB, an expression can belong to either the string or symbolic class
of data. Consider the following example:
>> f = 'xˆ3 - 1';
>> f(7)
ans =
1
Search WWH ::




Custom Search