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 .
This syntax does not create the symbolic variable x in the
MATLAB® Workspace.
Create a polynomial expression from a symbolic vector of coefficients. If you do not specify a polynomial variable, poly2sym uses x.
syms abcd
p = poly2sym([a,b,c,d])
p =
Create a polynomial expression from a symbolic vector of rational coefficients.
p = poly2sym(sym([1/2,-1/3,1/4]))
p =
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.
Create a polynomial expression from a numeric vector of integer coefficients.
p_coeffs = [1 4 5 4 4];
p = poly2sym(p_coeffs)
p =
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 =
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 =
Take the product of the factored form of the polynomial.
p_new = prod(p_elem)
p_new =
Expand the polynomial and confirm that the result is the same as the original expression.
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.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.