| ||||||||||||||||||
Functions for Polynomials
The following functions are intended for use with polynomials. A polynomial in one variable is an expression of the form:
anxn + an-1xn-1 + ... + a1x
+ a0
The coefficients ai are often numbers, but do not necessarily have to be. For example, the
expression ax2y + bxy2 can be viewed as a polynomial in the main
symbol x or as a polynomial in the main symbol y, or even as a polynomial
in a or b.
degree(poly, symbol)
This returns the value of the highest power of the specified symbol in the polynomial, or n
in the first example, and either 1 or 2 in the second
example, depending on the choice of symbol. Note that if the polynomial is 0, this function will return
the symbol Minus infinity.
coeff(poly, symbol, n)
This function returns the coefficient of the nth power of the symbol in the polynomial.
For example,
coeff(a*x^2*y + b*x*y^2, a, 1) returns the coefficient of a as x^2*y.
showpoly(p, symbol)
This is not a function but a command. It rearranges the structure of an expression so that it is displayed more clearly as a polynomial, in order of decreasing powers of the specified symbol. For example,
showpoly(a*x^2*y + b*x*y^2 + c*x^2*y^2, y) displays its result as a polynomial
in y shown in descending powers of y multiplied by the corresponding coefficients,
thus: y^2*(b*x + c*x^2) + y*a*x^2.
showseries(p, symbol)
This is not a function but a command. It rearranges the structure of an expression so that it is displayed more clearly as a power series, in order of increasing powers of the specified symbol. This may be useful when viewing Taylor series.
Example:
showseries(a*x^2*y + b*x*y^2 + c*x^2*y^2, y) displays its result as a series in y shown
in ascending powers of y multiplied by the corresponding coefficients,
thus: y*a*x^2 + y^2*(b*x + c*x^2).
collect(expression, symbol, ...)
This function collects together similar terms. It takes two or more arguments, the first one being the expression to work on. Each of the remaining arguments may be a symbol, an expression, or a list of symbols or expressions.
Examples:
collect(a + a*sin(x) + b*sin(x) + a*cos(x), a) collects together terms that
contain a as a factor. The result is b*sin(x) + a*(1 + cos(x) + sin(x)).
collect(a + a*sin(x) + b*sin(x) + a*cos(x), sin(x)) collects together terms that
contain sin(x) as a factor. The result is a + a*cos(x) + (a + b)*sin(x).
collect(a + a*sin(x) + b*sin(x) + a*cos(x), a, sin(x)) collects together terms that
contain a or sin(x) as a factor. Terms that contain
both a and sin(x) are collected separately. The result
is a*(1 + cos(x)) + a*sin(x) + b*sin(x).
It may sometimes be an advantage to first apply the function 'expand' to the expression to be worked on:
collect(a+b*a+x*a+b*x+3*a*(b+x), a, b) yields a*b + b*x + a*(1 + 3*b + 4*x)
But:
collect(expand(a+b*a+x*a+b*x+3*a*(b+x)), a, b) yields 4*a*b + b*x + a*(1 + 4*x)
Division of Polynomials
The functions polyquot and polyrem (polynomial quotient and remainder) take two or three arguments: two polynomials and an optional symbol. These functions divide the first polynomial by the second polynomial, and return the quotient or remainder. There is a similar function polydiv which returns a list of the quotient and remainder.
Example:
polydiv(-10 - 5*x + 2*x^2, x-4) returns the list [3 + 2*x, 2] which shows
that the quotient is 3 + 2*x and the remainder is 2. Multiplying the quotient
by the divisor and adding the remainder gives the original dividend, thus:
expand((3 + 2*x)*(x - 4)) + 2 gives -10 - 5*x + 2*x^2.
An optional third argument indicates which is the main symbol when there are more than one.
For example, taking x as the main symbol, polydiv(a+2*a*x, x+a, x) gives the
list [2*a, a - 2*a^2].
However, when taking a as the main symbol, polydiv(a+2*a*x, x+a, a) gives [1 + 2*x, -x - 2*x^2].
gcd(expr1, expr2)
This function finds the greatest common denominator of two expressions, which may be integers.
Examples:
gcd(143*a*b, 195*b*c) gives the result 13*b.
gcd(a^2 + a*b^2 + a*c + b^2*c, a*b + b^3 + a*c + b^2*c) gives a + b^2.
factors(poly)
This factorises a polynomial with numeric coefficients. Only one symbol should appear in the polynomial, and the coefficients should be integers or fractions (not decimals or complex numbers). If the polynomial cannot be factorised, the result is the original polynomial.
Examples:
factors(2*a^2 + 5*a + 2) gives the result (2 + a)*(1 + 2*a).
factors(2*a^2 + 5*a + 3) gives the result (1 + a)*(3 + 2*a).
factors(2*a^2 + 5*a + 4) gives the result 4 + 5*a + 2*a^2.
expand(expression)
This expands an expression by multiplying out products. For example, the
expression (3+x)*(2+x) is automatically simplified
to (2 + x)*(3 + x) butexpand((3+x)*(2+x)) produces 6 + 5*x + x^2.
polyexpand(poly1, poly2, symbol_1, symbol_2)
Given two polynomials poly1 and poly2 in symbol symbol_1, this function
creates a polynomial in symbol_2 in which symbol_2 represents poly2.
Examples:
polyexpand(15 + 6*x + 4*x^2 + x^4, 3 + 2*x + x^2, x, v) creates a polynomial
in v, namely:
2*v + v^2 + 2*x - 4*v*x.
polyexpand(3 + 14*x + 16*x^2 + 8*x^3, 3 + 2*x, x, v) returns the
polynomial -9 + 10*v - 5*v^2 + v^3.
When the second polynomial is of the form x-a, the polynomial expansion is the same as
the Taylor series expansion of the first polynomial
about a.
Example:
polyexpand(1 + x + x^2 + x^3, x - 1, x, v) returns the polynomial 4 + 6*v + 4*v^2 + v^3.
polydecomp(poly)
This function attempts to decompose a polynomial into two polynomials such that when the second polynomial is substituted for the main variable in the first polynomial, the result is the original polynomial.
Example:
polydecomp(1 - x^2 + x^4) returns the list [1 - x + x^2, x^2].
Note that the decomposition is not necessarily unique, and may not exist. Some polynomials may be decomposed in several ways, others cannot be decomposed at all. In the latter case, the original expression is returned.
Examples:
polydecomp(3 + 3*x^2 + x^4) returns the list [3 - 3*x + x^2, 3+x^2]. However, the
polynomial could also have been decomposed into [1 + x + x^2, 1 + x^2] .
polydecomp(4 + 6*x + 4*x^2 + x^3) fails to find a decomposition, so it returns the original
polynomial, 4 + 6*x + 4*x^2 + x^3.
Partial fractions
The function partfract accepts a polynomial in one variable with numeric coefficients and returns its partial fraction expansion. Note that the coefficients in the denominator must be integers or fractions, and not decimals or complex numbers.
Examples:
partfract((x^2 + x + 1)/(x^2 + 5*x + 6)) returns 1 + 3/(2 + x) - 7/(3 + x).
partfract((1+2*y+3*y^2) / (1+2*y+y^2)) returns 3 + 2/(1 + y)^2 - 4/(1 + y).
