How to | Rearrange the Terms of a Polynomial
The Wolfram Language provides many functions to group terms in a polynomial, extract and sort the monomials, display them in various ways, and even process them as arbitrary expression structures.
Define a polynomial in
and exponentials of
:
p = x ^ 2 E ^ (2x) + 2x E ^ (2x) + x E ^ xCollect the powers of
:
Collect[p, x]Group terms that match the pattern; in this case terms that have the same exponential factors are grouped:
Collect[p, E ^ _]Apply Simplify to the coefficient of each term after collecting the terms:
Collect[p, E ^ _, Simplify]There are many ways to extract terms from an expression. Here is a polynomial in
:
poly = x ^ 2 - 3x + 2Get the coefficient of
(the constant term):
Coefficient[poly, x, 0]Get the same term by replacing
with zero, thus eliminating all terms that depend on
:
poly /. x -> 0Get the list of the monomials ordered from high to low powers of
:
MonomialList[poly, x]The polynomial will appear in the same order when displayed in TraditionalForm:
poly//TraditionalForm