horner
Horner (nested) form of a polynomial.
Category: Mathematics > Formula Manipulation and Simplification
Syntax
R = horner(P)
Rewrites the polynomial P in nested multiplication form.
Description
Writing x^3 + 2*x^2 + 3*x + 4 as x*(x*(x + 2) + 3) + 4 evaluates the polynomial with only additions and multiplications and no powers. This takes fewer operations and is numerically better behaved, which is why it is the usual way to evaluate polynomials by machine.
Input arguments
P- Symbolic polynomial.
Output arguments
R- Equivalent expression with the nesting
x*(x*(a*x + b) + c) + d.
Example
Nested form of a cubic
syms x
horner(x^3 + 2*x^2 + 3*x + 4)
Output
ans = x*(x*(x + 2) + 3) + 4