Previous Page Next Page Contents

nthcoeff -- the n-th non-zero coefficient of a polynomial

Introduction

nthcoeff(p, n) returns the n-th non-zero coefficient of the polynomial p.

Call(s)

nthcoeff(p, <vars,> n <, order>)

Parameters

p - a polynomial of type DOM_POLY or a polynomial expression
vars - a list of indeterminates of the polynomial: typically, identifiers or indexed identifiers
n - a positive integer
order - the term ordering: either LexOrder or DegreeOrder or DegInvLexOrder or a user-defined term ordering of type Dom::MonomOrdering. The default is the lexicographical ordering LexOrder.

Returns

an element of the coefficient domain of the polynomial. An expression is returned if a polynomial expression is used as input. FAIL is returned if n is larger than the actual number of terms.

Overloadable:

p

Related Functions

coeff, collect, degree, degreevec, ground, lcoeff, ldegree, lmonomial, lterm, nterms, nthmonomial, nthterm, poly, poly2list, tcoeff

Details

Example 1

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) 
                                100, 49, 7
>> nthcoeff(p, 4)
                                   FAIL
>> nthcoeff(poly(0, [x]), 1)
                                   FAIL
>> delete p:

Example 2

We demonstrate how the indeterminates influence the result:

>> p := 2*x^2*y + 3*x*y^2 + 6:
   nthcoeff(p, [x, y], 2), nthcoeff(p, [y, x], 2)
                                   3, 2
>> p := poly(2*x^2*y + 3*x*y^2 + 6, [x, y]):
   nthcoeff(p, 1), nthcoeff(p, [y, x], 1)
                                   2, 3
>> delete p:

Example 3

We demonstrate the effect of various term orders:

>> p := poly(5*x^4 + 4*x^3*y*z^2 + 3*x^2*y^3*z + 2, [x, y, z])
                     4      3    2      2  3
             poly(5 x  + 4 x  y z  + 3 x  y  z + 2, [x, y, z])
>> nthcoeff(p, 1), nthcoeff(p, 1, DegreeOrder),
   nthcoeff(p, 1, DegInvLexOrder)
                                  5, 4, 3

The following call uses the reverse lexicographical order on 3 indeterminates:

>> nthcoeff(p, 1, Dom::MonomOrdering(RevLex(3)))
                                     3
>> delete p:

Example 4

We demonstrate the evaluation strategy of nthcoeff:

>> p := poly(3*x^3 + 6*x^2*y^2 + 2, [x]): y := 4: 
   nthcoeff(p, 2)
                                      2
                                   6 y

Evaluation is enforced by eval:

>> eval(%)
                                    96
>> delete p, y:

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000