sym2poly

Extracts the coefficient vector of a symbolic polynomial.

Category: Symbolic Computations in MATLAB > Conversion Between Symbolic and Numeric

Syntax

c = sym2poly(p)

Coefficients of p as a row of doubles, highest power first.

c = sym2poly(p, x)

Treats x as the polynomial variable.

Description

The vector has one entry per power from the degree down to zero, so it can be passed straight to polyval, roots or conv. Exact rational coefficients are converted to doubles.

An expression that is not a polynomial (for example sin(x)) gives the error "Not a polynomial", and symbolic coefficients such as y*x give an error since the output must be numeric.

Input arguments

p
Symbolic polynomial in one variable with numeric coefficients.
x
The variable (optional).

Output arguments

c
Row vector of doubles. Missing powers appear as zeros.

Example

Coefficients and missing powers

syms x
sym2poly(3*x^3 - x + 2)
sym2poly(x^2/2)
Output
ans = 1×4

     3     0    -1     2
ans = 1×3

    0.5000         0         0

See also

poly2sym coeffs polyval roots