Main Content

poly2sym

Create symbolic polynomial from vector of coefficients

Description

example

p = poly2sym(c) creates the symbolic polynomial expression p from the vector of coefficients c. The polynomial variable is x. If c = [c1,c2,...,cn], then p = poly2sym(c) returns c1xn1+c2xn2+...+cn.

This syntax does not create the symbolic variable x in the MATLAB® Workspace.

example

p = poly2sym(c,var) uses var as a polynomial variable when creating the symbolic polynomial expression p from the vector of coefficients c.

Examples

Create Polynomial Expression

Create a polynomial expression from a symbolic vector of coefficients. If you do not specify a polynomial variable, poly2sym uses x.

syms a b c d
p = poly2sym([a, b, c, d])
p =
a*x^3 + b*x^2 + c*x + d

Create a polynomial expression from a symbolic vector of rational coefficients.

p = poly2sym(sym([1/2, -1/3, 1/4]))
p =
x^2/2 - x/3 + 1/4

Create a polynomial expression from a numeric vector of floating-point coefficients. The toolbox converts floating-point coefficients to rational numbers before creating a polynomial expression.

p = poly2sym([0.75, -0.5, 0.25])
p =
(3*x^2)/4 - x/2 + 1/4

Specify Polynomial Variable

Create a polynomial expression from a symbolic vector of coefficients. Use t as a polynomial variable.

syms a b c d t
p = poly2sym([a, b, c, d], t)
p =
a*t^3 + b*t^2 + c*t + d

To use a symbolic expression, such as t^2 + 1 or exp(t), instead of a polynomial variable, substitute the variable using subs.

p1 = subs(p, t, t^2 + 1)
p2 = subs(p, t, exp(t))
p1 =
d + a*(t^2 + 1)^3 + b*(t^2 + 1)^2 + c*(t^2 + 1)
 
p2 =
d + c*exp(t) + a*exp(3*t) + b*exp(2*t)

Input Arguments

collapse all

Polynomial coefficients, specified as a numeric or symbolic vector. Argument c can be a column or row vector.

Polynomial variable, specified as a symbolic variable.

Output Arguments

collapse all

Polynomial, returned as a symbolic expression.

Tips

  • When you call poly2sym for a numeric vector c, the toolbox converts the numeric vector to a vector of symbolic numbers using the default (rational) conversion mode of sym.

Version History

Introduced before R2006a

See Also

| |