coeffs
Coefficients of a polynomial in one or more variables.
Category: Mathematics > Formula Manipulation and Simplification
Syntax
c = coeffs(p, x)
Returns the coefficients of p as a polynomial in x, lowest power first.
[c, t] = coeffs(p, x)
Also returns the terms t that each coefficient multiplies.
Description
coeffs first expands p and then collects the terms by power of x. Terms with a zero coefficient are skipped, which is why the second output is useful: it says which power each coefficient belongs to. Coefficients that depend on other symbols stay symbolic.
Input arguments
p- Symbolic polynomial expression.
x- Variable (or vector of variables) of the polynomial.
Output arguments
c- Row vector of coefficients; they may contain the other symbols.
t- Row vector of the powers of
xmatchingc.
Example
Coefficients with their terms
syms x
[c, t] = coeffs(3*x^2 + 2*x + 1, x)
coeffs(x^3 + 2*x, x)
Output
c =
[1, 2, 3]
t =
[1, x, x^2]
ans =
[2, 1]
Notes
Only the single-variable form with an explicit variable was checked in MatLivre; the multivariable form with a vector of variables is not supported.