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

collapse all

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 = ax3+bx2+cx+d

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

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

x22-x3+14

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 = 

3x24-x2+14

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 = at3+bt2+ct+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)
p1 = d+at2+13+bt2+12+ct2+1
p2 = subs(p,t,exp(t))
p2 = d+cet+ae3t+be2t

Create a polynomial expression from a numeric vector of integer coefficients.

p_coeffs = [1 4 5 4 4];
p = poly2sym(p_coeffs)
p = x4+4x3+5x2+4x+4

Because poly2sym does not create the symbolic variable x in the workspace, create this variable by using syms. Find the roots of the polynomial by using solve.

syms x
p_roots = solve(p,x)
p_roots = 

(-2-2-ii)

The polynomial has 4 roots. To check if these roots are indeed the correct solution, you can reconstruct the original polynomial from the roots.

Find the factored form of the polynomial by subtracting each root from x.

p_elem = x-p_roots
p_elem = 

(x+2x+2x+ix-i)

Take the product of the factored form of the polynomial.

p_new = prod(p_elem)
p_new = x+22x-ix+i

Expand the polynomial and confirm that the result is the same as the original expression.

p_new = expand(p_new)
p_new = x4+4x3+5x2+4x+4

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

| |