Nth nonzero coefficient of a polynomial
MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.
MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.
nthcoeff(p
,n
) nthcoeff(f
, <vars
>,n
)
nthcoeff(p, n)
returns the n
th
nonzero coefficient of the polynomial p
.
nthcoeff
returns the n
th
nonzero coefficient with respect to the lexicographical ordering.
The "first" coefficient is the leading coefficient
as returned by lcoeff
,
the "last" coefficient is the trailing coefficient as
returned by tcoeff
.
A zero polynomial has no terms: nthcoeff
returns FAIL
.
A polynomial expression f
is first converted
to a polynomial with the variables given by vars
.
If no variables are given, they are searched for in f
.
See poly
about
details of the conversion. FAIL
is returned if f
cannot
be converted to a polynomial.
The result of nthcoeff
is not fully evaluated.
Evaluation can be enforced by the function eval
. Cf. Example 2.
We give some self explaining examples:
p := poly(100*x^100 + 49*x^49 + 7*x^7, [x]): nthcoeff(p, 1), nthcoeff(p, 2), nthcoeff(p, 3)
nthcoeff(p, 4)
nthcoeff(poly(0, [x]), 1)
delete p:
We demonstrate the evaluation strategy of nthcoeff
:
p := poly(3*x^3 + 6*x^2*y^2 + 2, [x]): y := 4: nthcoeff(p, 2)
Evaluation is enforced by eval
:
eval(%)
delete p, y:

A polynomial of
type 
 

A list of indeterminates of the polynomial: typically, identifiers or indexed identifiers 

A positive integer 
Element of the coefficient domain of the polynomial. An expression
is returned if a polynomial expression is given as input. FAIL
is
returned if n
is larger than the actual number
of terms.
p