collect coefficients of like powers
collect(a, x, form, func)
collect(a, x, func)
indeterminate, or a list or set of indeterminates, or an unevaluated function
(optional) name; `recursive` (default) or `distributed`
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 x1e1⁢x2e2⁢...⁢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.
Simplifying an expression by regrouping terms
f ≔ a⁢ln⁡x−ln⁡x⁢x−x
g ≔ ∫x2⁢ⅇx+ⅇ−xⅆx
Expanding a polynomial in one variable before using coeff
f ≔ x⁢x+1+y⁢x+1
g ≔ collect⁡f,x
Writing a multivariate polynomial in different forms
p ≔ x⁢y+a⁢x⁢y+y⁢x2−a⁢y⁢x2+x+a⁢x:
Note this returns a result that is order-dependent
But this does not
Applying a function to the coefficients
f ≔ a3⁢x−x+a3+a
Collect understands positive and negative rational powers
p ≔ yx+2⁢zx+x13−y⁢x13
Collect can simplify for general indeterminates (e.g. diff, D, sin).
DE ≔ ⅆ2ⅆx2⁢y⁡x⁢sin⁡x−ⅆⅆx⁢y⁡x⁢sin⁡y⁡x+sin⁡x⁢ⅆⅆx⁢y⁡x+sin⁡y⁡x⁢ⅆ2ⅆx2⁢y⁡x
Collect does not sort in general
Download Help Document
What kind of issue would you like to report? (Optional)