Documentation Center |
Coefficients of a polynomial
This functionality does not run in MATLAB.
coeff(p, <All>) coeff(p, <x>, n, <All>) coeff(p, <[x, …]>, [n, …], <All>) coeff(f, <vars>, <All>) coeff(f, <vars>, <x>, n, <All>) coeff(f, <vars>, <[x, …]>, [n, …], <All>)
coeff(p) returns a sequence of all nonzero coefficients of the polynomial p.
coeff(p, x, n) regards p as a univariate polynomial in x and returns the coefficient of the term x^n.
coeff(p, [x,...], [n,...]) regards p as a multivariate polynomial in x,... and returns the coefficient of the term x^n,....
If the first argument f is not element of a polynomial domain, then coeff converts the expression internally to a polynomial of type DOM_POLY via poly(f). If a list of indeterminates is specified, the polynomial poly(f, vars) is considered.
Coefficients of polynomial expressions f are returned as arithmetical expressions.
There are various ways to call coeff with a polynomial p of type DOM_POLY:
coeff(p) returns a sequence of all nonzero coefficients of p. They are ordered according to the lexicographical term ordering. The order in descending.
The returned coefficients are elements of the coefficient ring of p.
coeff(p, x, n) regards p as a univariate polynomial in the variable x and returns the coefficient of the term x^n.
For univariate polynomials, the returned coefficients are elements of the coefficient ring of p.
For multivariate polynomials, the coefficients are returned as polynomials of type DOM_POLY in the "remaining" variables.
coeff(p, n) is equivalent to coeff(p, x, n), where x is the "main variable" of p. This variable is the first element of the list of indeterminates op(p, 2).
coeff(p, [x1,x2,...], [n1,n2,...]) regards p as a multivariate polynomial in the variables x1,x2,... and returns the coefficient of the term x1^n1*x2^n2.... Variable and exponent lists must have the same length.
The returned coefficients are either elements of the coefficient ring of p or polynomials of type DOM_POLY in the "remaining" variables.
coeff(p, [n1,n2,...]) is equivalent to coeff(p, [x1,x2,...], [n1,n2,...]), where the variables x1,x2,... are the "main variables" of p, i.e., the leading elements of the list of indeterminates op(p, 2).
coeff(p, All) returns a sequence of coefficients of p including those equal to zero. The function returns the result in ascending lexicographical order. For univariate polynomial p, the call coeff(p, All) is equivalent to coeff(p, i) $ i = 0 .. degree(p).
coeff returns 0 or a zero polynomial if the polynomial does not contain a term corresponding to the specified powers. In particular, this happens for a univariate polynomial if n is larger than the degree of the polynomial.
coeff returns FAIL if an expression cannot be regarded as a polynomial.
The result of coeff is not fully evaluated. Evaluation can be enforced by the function eval. See Example 5.
coeff(f) returns a sequence of all non-zero coefficients:
f := 10*x^10 + 5*x^5 + 2*x^2: coeff(f)
coeff(f, i) returns a single coefficient:
coeff(f, i) $ i = 0..15
delete f:
We demonstrate how the indeterminates influence the result:
f := 3*x^3 + x^2*y^2 + 17*x + 23*y + 2
coeff(f); coeff(f, [x, y]); coeff(f, [y, x])
delete f:
The coefficients of f are selected with respect to the main variable x which is the first entry of the list of indeterminates:
f := 3*x^3 + x^2*y^2 + 2: coeff(f, [x, y], i) $ i = 0..3
The coefficients of f can be selected with respect to another main variable (in this case, y):
coeff(f, [y, x], i) $ i = 0..2
Alternatively:
coeff(f, y, i) $ i = 0..2
The coefficients of f can also be selected with respect to a multivariate term:
coeff(f, [x,y], [3,0]), coeff(f, [x,y], [2,2]), coeff(f, [x,y], [0,0])
delete f:
In the same way, coeff can be applied to polynomials of type DOM_POLY:
p := poly(3*x^3 + x, [x], Dom::IntegerMod(7)): coeff(p)
coeff(p, i) $ i = 0..3
For multivariate polynomials, the coefficients with respect to an indeterminate are polynomials in the other indeterminates:
p := poly(3*x^3 + x^2*y^2 + 2, [x, y]):
coeff(p, y, 0), coeff(p, y, 1), coeff(p, y, 2);
coeff(p, x, 0), coeff(p, x, 1), coeff(p, x, 2)
Note that the indeterminates passed to coeff will be used, even if the polynomial provides different indeterminates :
coeff(p, z, 0), coeff(p, z, 1), coeff(p, z, 2)
delete p:
The result of coeff is not fully evaluated:
p := poly(27*x^2 + a*x, [x]): a := 5: coeff(p, x, 1), eval(coeff(p, x, 1))
delete p, a:
To return all coefficients of a polynomial, use the All option:
p := poly(a*x^3 + b*x^2 + c*x + d, [x, y]): coefficients := coeff(p, All)
To revert the order of the resulting sequence, use the revert function. This function does not operate on sequences. To convert a sequence to a list, call revert for this list, and convert the result back to a sequence:
op(revert([coefficients]))
The All option also works for polynomial expressions:
p_expr := 2*x^5 + 5*x^2 + 10*x + 3: coeff(p_expr, All)
You can use the coeff function with the All option to compute scalar products of polynomials. For example, the following procedure computes a scalar product of two polynomials in an orthonormal basis. The coeff function extracts the coefficients of the polynomials and returns two lists of coefficients. The zip function multiplies the entries of these lists pairwise and returns a list. The op function accesses the entries of that list. Finally, the _plus function computes the sum of all products:
scalarProduct := proc(p, q) local lp, lq; begin lp := [coeff(p, All)]; lq := [coeff(conjugate(q), All)]; _plus(op(zip(lp, lq, _mult))); end_proc:
The following polynomials are orthogonal:
scalarProduct(poly(x^2 + 2), poly(x^3 + 2*x^2 - 1))
coeff(p, All) also works for multivariate polynomials and polynomial expressions:
p := poly(2*x^2*y + PI*x + y^2 - 2, [x, y]): coeff(p, All)
For a multivariate polynomial or polynomial expression, the order in which coeff returns the coefficients is such that the coefficient of the exponent vector [e_{1}, e_{2}, …] appears at position e_{1} d_{1} + e_{2} d_{2} + … + 1. For example, represent the coefficients returned for bivariate polynomial as a matrix:
A := matrix(degree(p, x) + 1, degree(p, y) + 1, [coeff(p, All)])
p |
A polynomial of type DOM_POLY |
x |
An indeterminate |
n |
A power: a nonnegative integer |
f | |
vars |
A list of indeterminates of the polynomial: typically, identifiers or indexed identifiers |
All |
The coeff function with this option returns all the coefficients of a polynomial or a polynomial expression including those equal to zero. The function returns the result in ascending lexicographical order. See Example 6 and Example 7. |
One or more coefficients of the coefficient ring of the polynomial, or a polynomial, or FAIL.