Beruflich Dokumente
Kultur Dokumente
3
1.2.4 The Horner Command
The horner command is useful in preparing an expression for repeated numerical evaluation.
In particular, it write the expressionin a form that requires the least number of arithmetic
operations to evaluate.
Example 7. Re-write the polynomial from Example 6 in Horner form.
>>syms x
>>f=x4-2*x2+1
f =
x4-2*x2+1
>>horner(f)
ans =
1+(-2+x2)*x2
1.2.5 The Simple Command
The simple command takes a symbolic expression and re-writes it with the least possible
number of characters. (It runs through MATLABs various manipulation programs such as
collect, expand, and factor and returns the result of these that has the least possible number
of characters.)
Example 8. Suppose we would like a reduced expression for the function
f(x) = (1 +
1
x
+
1
x
2
)(1 + x + x
2
).
We use
>>syms x f
>>f=(1+1/x+1/x2)*(1+x+x2)
f =
(1+1/x+1/x2)*(x+1+x2)
>>simple(f)
simplify:
(x+1+x2)2/x2
radsimp:
(x+1+x2)2/x2
combine(trig):
(3*x2+2*x+2*x3+1+x4)/x2
factor:
(x+1+x2)2/x2
expand:
2*x+3+x2+2/x+1/x2
combine:
(1+1/x+1/x2)*(x+1+x2)
4
convert(exp):
(1+1/x+1/x2)*(x+1+x2)
convert(sincos):
(1+1/x+1/x2)*(x+1+x2)
convert(tan):
(1+1/x+1/x2)*(x+1+x2)
collect(x):
2*x+3+x2+2/x+1/x2
mwcos2sin:
(1+1/x+1/x2)*(x+1+x2)
ans =
(x+1+x2)2/x2
In this example, three lines have been typed, and the rest is MATLAB output as it tries
various possibilities. In returns the expression in ans, in this case from the factor command.