@sym: horner (p) ¶@sym: horner (p, x) ¶Convert a symbolic polynomial to Horner form.
The Horner form minimizes the number of arithmetic operators to evaluate the polynomial.
Example:
syms x
p = poly2sym ([2 4 6 8], x)
⇒ p = (sym)
3 2
2⋅x + 4⋅x + 6⋅x + 8
horner (p)
⇒ ans = (sym) x⋅(x⋅(2⋅x + 4) + 6) + 8
You can specify the variable as a second input:
syms x a p = expand((a+2)*(2*a+x)*(3*a+7)); horner(p, a) ⇒ ans = (sym) a⋅(a⋅(6⋅a + 3⋅x + 26) + 13⋅x + 28) + 14⋅x
See also: poly2sym.
Package: symbolic