collect - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


collect

collect coefficients of like powers

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

collect(a, x)

collect(a, x, form, func)

collect(a, x, func)

Parameters

a

-

expression

x

-

indeterminate, or a list or set of indeterminates, or an unevaluated function

form

-

(optional) name; `recursive` (default) or `distributed`

func

-

(optional) procedure

Description

• 

The collect function views a as a general polynomial in x.  It collects all the coefficients with the same rational power of x.  This includes positive and negative powers, and fractional powers.  Note that the resulting expression is not necessarily sorted by powers of x.  To sort a polynomial see the sort function.

• 

There are four main purposes for using collect. Firstly, to "simplify" an expression by factoring out all terms of like powers in some indeterminate. Secondly, to expand a polynomial in a variable before applying the coeff function. Thirdly, to write a multivariate polynomial in different forms. Fourthly, to apply a function to the coefficients of a polynomial. The examples below show each of these uses.

• 

The second argument x can be a single indeterminate (univariate case) or a list or set of indeterminates x1, x2, ..., xn (multivariate case).  Sets can only be used if the distributed form is specified (see below).  The indeterminates can be names or unevaluated function calls but not sums or products or fractional powers.  To collect fractional powers, for example x just collect x.

• 

Two forms for the result are available.  The form is specified by the optional argument form. It may be the name `recursive` (the default) or the name `distributed`.

• 

The recursive form is obtained by first collecting the coefficients in x1, then for each coefficient in x1, collecting the coefficients in x2 and so on. If the indeterminates are specified as a set, their order is controlled by Maple and the results might differ from session to session. The distributed form is the form obtained by collecting the coefficients of x1e1x2e2...xnen.

• 

A function may be specified using the optional argument func. It is applied to the coefficients of the collected result. Often simplify or factor will be used.

• 

The following shorthand is supported:  often one wants to collect all the derivatives in an expression, or all the sine and cosines present in an expression.  If func is a name then collect(expr, func) will collect expr with respect to functions whose name is func.

Examples

Simplifying an expression by regrouping terms

falnxlnxxx

falnxlnxxx

(1)

collectf,lnx

axlnxx

(2)

gintx2expx+expx,x

gx2ⅇx2xⅇx2ⅇx+x2ⅇx2xⅇx+2ⅇx

(3)

collectg,expx

x22x+2ⅇx+x22x2ⅇx

(4)

Expanding a polynomial in one variable before using coeff

fxx+1+yx+1

fxx+1+yx+1

(5)

coefff,x,1

1+y

(6)

gcollectf,x

gx2+1+yx+y

(7)

coeffg,x,1

1+y

(8)

Writing a multivariate polynomial in different forms

pxy+axy+yx2ayx2+x+ax:

collectp,x,y,recursive

a+1yx2+a+1y+a+1x

(9)

collectp,y,x,recursive

a+1x2+a+1xy+a+1x

(10)

Note this returns a result that is order-dependent

collectp,x,y,recursive

a+1yx2+a+1y+a+1x

(11)

But this does not

collectp,x,y,distributed

a+1yx2+a+1xy+a+1x

(12)

collectp,x,y,distributed

a+1yx2+a+1xy+a+1x

(13)

Applying a function to the coefficients

fa3xx+a3+a

fa3x+a3+ax

(14)

collectf,x

a31x+a3+a

(15)

collectf,x,factor

a1a2+a+1x+aa2+1

(16)

Collect understands positive and negative rational powers

pyx+2zx+x13yx13

pyx+2zx+x13yx13

(17)

collectp,x

1yx13+y+2zx

(18)

Collect can simplify for general indeterminates (e.g. diff, D, sin).

DEdiffyx,x,xsinxdiffyx,xsinyx+sinxdiffyx,x+sinyxdiffyx,x,x

DEⅆ2ⅆx2yxsinxⅆⅆxyxsinyx+sinxⅆⅆxyx+sinyxⅆ2ⅆx2yx

(19)

collectDE,diff

sinx+sinyxⅆ2ⅆx2yx+sinxsinyxⅆⅆxyx

(20)

collectDE,sin

ⅆ2ⅆx2yx+ⅆⅆxyxsinx+ⅆ2ⅆx2yxⅆⅆxyxsinyx

(21)

Collect does not sort in general

collectx3y+x2y3+x+3,y

x2y3+x3y+x+3

(22)

sort,y

x2y3+x3y+x+3

(23)

See Also

coeff

sort