Ryerson Crest Ryerson Header

MTH 207 Lab Lesson 5

Working with Functions


Up to Main Lab Page Next Lesson - Program Control Previous Lesson - Plotting

There are a number of Maple functions which allow use to manipulate expressions in various ways. They are mostly used for polynomials in the dependent expression, but can sometimes be used in more complicated situations.

These functions generally expect an expression as their first argument, since they need to know the name of the free variable. Thus we would call simplify(f(x),x); rather than simplify(f,x). Most of these functions have the syntax function(expression, variable name[, optional arguments]). Many of these functions only find thier real power when dealing with multivariate functions, though some of them are useful for functions of one variable.

FunctionSyntaxExplanation
expandexpand(expression)Distributes sums across products and applies certain algebraic rules
combinecombine(expression)Combines varibles in an expression using algebraic rules (opposite of expand).
simplifysimplify(expression)Simplifies an expression as much as possible.

Notes

When using these functions it is important to realise the mathematical limitations implicit in them.
You are encouraged to use the Maple online help for these functions.

Combine and Expand

Combine and Expand also implement a number of other identities, for example the trig identity
sin(a + b) = sin(a)cos(b) + cos(a)sin(b)
is implemented (from left to right in expand, right to left in combine).

Expand allows further expression as optional arguments which indicate that this expression should not be expanded. Some examples:
>expand(x*(x+1)*(x+2));
>expand(x*(x+1)*(x+2), x+1);
>expand(sin(x)*(x+cos(x)));
>expand(sin(a+b)*(a+cos(a+b)));
>expand(sin(a+b)*(a+cos(a+b)), sin(a+b));
>expand(sin(a+b)*(a+cos(a+b)), sin(a+b), cos(a+b));

Simplify

Simplify knows a set of simplification rules which it applies. If we wish only one rule to be applied we may use the optional rule argument simplify(expression, rule), wher rule is one of the following:
ln, power, radical, sqrt, trig.

Another optional argument uses the 'assume property' syntax. Thus we may tell Maple that the variables are assumed to have some special property.
The syntax is simplify(expression, assume=property), where property is one of
positive, real, integer, a range (as with the piecewise function)
There are other properties, see help on assume.
Consider the following example:
> g:=sqrt(x^2);

g := (x2)½
> simplify(g);
csgn(x) x

csgn allows for the posibilty that x is a complex variable.
> simplify(g, assume=real);
signum(x) x

signum gives the sign of x, so this is in fact |x|.
> simplify(g, assume=positive);
x
Only if x is positive is sqrt(x2) = x.
factorfactor(expression)Tries to factor a polynomial
collectcollect(expression, variable)Collects all occurences of the variable in expression.
coeffcoeff(expression, variable, n)Outputs the coefficient of (variable)n
normalnormal(expression)Puts a rational function in 'Simplified Normal Form'

Factor

Once again Maple is not magic, factoring a polynomial is equivalent to finding the roots of that polynomial, this is in general a hard problem. Factor will only work on low degree polynomials with integer or rational coefficients and roots. Many of the real uses of factor are beyond the scope of this course.
Try the following: (see if you can guess the answers first)
> factor(x^2+5*x+6);
> factor(x^2+5*x+6.0);
> factor(x^2+5/2*x+6/4);
> factor(x^2-2);
> factor(x^5+x^4-6*x^3-x^2-x+6);
> factor((x^2-1)/(x-1));
    1. Express (x + 1)(x2 + 2)(x2 + x + 1)(x - 1) as a polynomial in powers of x using teo different Maple functions.
    2. Express x6 - x5 - 7x4 - 13x3 - 24x2 - 12x - 16 as a product of linear and quadratic factors
    3. Express sin5x in terms of sin(x) and cos(x). Try Factoring the result.
    4. Express sin(5x) in terms of sin(x) and cos(x). Try Factoring the result.
    5. Think up your own functions.


Up to Main Lab Page Next Lesson - Program Control Previous Lesson - Plotting Top of this Lesson


Maintained by: P. Danziger, January 1998