Documentation |
Collect terms with the same powers
This functionality does not run in MATLAB.
collect(p, x, <f>) collect(p, [x1, x2, …], <f>)
collect(p, x) groups terms with the same powers of x in an expression p.
collect(p, [x1, x2, ...]) groups terms with the same powers of x_{1}, x_{2}, … in a multivariate expression p.
If you pass a function name f as a third argument to collect, the procedure collects the powers of x (x_{1}, x_{2}, … for multivariate expression). Then it applies the function f to the coefficients.
collect(p, x) presents p as a sum . The coefficients a_{i} are not polynomials in x. These coefficients can contain some terms with x, for example, sin(x) or .
collect returns a modified copy of a polynomial. The function does not change the polynomial itself. See Example 1.
If p is a rational expression in x, collect handles the numerator and denominator separately.
If p is a multivariate expression, collect(p, [x_{1}, x_{2}, …]) returns an expression in the following form:
.
The coefficients a_{i1, i2, …} are not polynomials in x. These coefficients can contain some terms with x_{1}, x_{2}, …, for example, .
If p is a rational expression in x_{1}, x_{2}, …, the collect command handles the numerator and denominator separately.
For polynomial expressions, collect internally calls two functions: poly and then expr. The function poly converts an expression p into a polynomial in the given unknowns. This function returns a polynomial with the terms collected by the same powers. Then expr converts this polynomial into a polynomial expression. See poly for more information and examples. When applied to a rational expression, collect handles the numerator and denominator separately.
You can use arbitrary expressions as indeterminates. See Example 2.
You can specify a function name instead of a variable. In this case, collect treats all calls of the function with different arguments as different variables. See Example 4.
collect does not recursively collect the operands of nonpolynomial subexpressions of p. See Example 2.
If p is not a polynomial expression, collect can return the unchanged expression p. See Example 5.
You can define a polynomial expression p and collect terms with the same powers of x and y:
p := x*y + z*x*y + y*x^2 - z*y*x^2 + x + z*x; collect(p, [x, y])
collect does not modify the original expression:
p
You can collect terms with same powers of x:
collect(p, [x])
If an expression contains only one indeterminate, you can omit the square brackets in the second argument of the function call:
collect(p, x)
To factor coefficients in a resulting expression, pass factor as a third argument to collect:
collect(p, x, factor)
collect does not modify nonpolynomial subexpressions even if they contain a given indeterminate. In particular, collect does not recursively handle the operands of a nonpolynomial subexpression:
collect(sin((x + 1)^2)*(x + 1) + 5*sin((x + 1)^2) + x, x)
collect accepts nonpolynomial subexpressions as indeterminates:
collect(sin((x + 1)^2)*(x + 1) + 5*sin((x + 1)^2) + x, sin((x + 1)^2))
collect normalizes a rational expression, and then handles the numerator and denominator separately:
collect(z/(x+y) + 3*z/(x+z), z)
If you specify the name of a function as an indeterminate, collect handles functions calls with different arguments as different indeterminates:
collect(a*f(1) + c*f(1) + f(2) + d*f(2), f)
collect(a*sin(x) + b*sin(x) + c*sin(y) + d*sin(y), sin)
p:= diff(besselJ(0, x), x $ 4); collect(p, besselJ); collect(p, besselJ, expand);
If p is not a polynomial expression, collect can return the unchanged expression p:
p := y^2*sin(x) + y*sin(x) + y^2*cos(x) + y*cos(x); collect(p, x)
The expression p is a polynomial expression in y. You can group the terms with the same powers in this variable:
collect(p, y)
p | |
x, x1, x2, … |
The indeterminates: typically, identifiers or indexed identifiers. |
f |
A function. |