horner

Horner nested polynomial representation

Syntax

horner(p)
horner(p,var)

Description

example

horner(p) returns the Horner form of the polynomial p.

example

horner(p,var) uses the variable in var.

Examples

collapse all

Find the Horner representation of a polynomial.

syms x
p = x^3 - 6*x^2 + 11*x - 6;
horner(p)
ans =
x*(x*(x - 6) + 11) - 6

Specify the variable in the polynomial by using the second argument.

syms a b y
p = a*y*x^3 - y*x^2 - 11*b*y*x + 2;
horner(p,x)
ans =
2 - x*(11*b*y + x*(y - a*x*y))
horner(p,y)
ans =
2 - y*(- a*x^3 + x^2 + 11*b*x)

Input Arguments

collapse all

Polynomial, specified as a symbolic expression or function, or an array of symbolic expressions or functions.

Variable, specified as a symbolic variable or an array of symbolic variables.

Introduced before R2006a