Section 2: Algebraic Calculations
© 2000 Seattle Central Community College. Reproduced with permission
Maple is a "C.A.S" , i.e. a C omputer A lgebra S ystem. This means that Maple knows every rule of algebra that you know. As you progress through Calculus, Differential Equations and Linear Algebra you will find that Maple also has the essential operations from those subjects built into its large command set.
In this section you will learn how to enter an algebraic expression and substitute values in for the variables. Then you will learn the commands that allow you to expand, factor and simplify expressions.
> restart;
>
Example 1:
For our first example let's start with the expression
and assign it the name W.
> W:=3*x^2+8;
Suppose now that you want to substitute the value 4 for x in the expression
. The quickest way to do this is to use Maple's
subs( )
command. Here's what it looks like:
> subs(x=4,3*x^2+8);
Alternatively you can apply the subs( ) command to W.
> subs(x=4,W);
Example 2:
The subs( ) command works equally well with symbolic values:
To replace x by
in the expression
execute the following line. In this case we label the result M.
> W:=3*x^2+8;
> M:=subs(x=5+2*u,W);
And now to get Maple to "multiply out" this expression we use the expand( ) command.
> expand(M);
Example 3:
The
subs( )
command is very versatile. You can use it to evaluate expressions involving more than one variable.
Here we replace
by 7 and y by 12 in the expression
.
> U:=(2/5)*x^2+3*y;
> subs(x=7,y=12,U);
> evalf(%);
Example 4:
You can also use the
subs( )
command to substitute a value into an equation. This is the sort of thing you might want to do to test whether a particular value "satisfies" the equation. In the next few lines we substitute different values into the equation
. Are any of these values a solution to the equation?
Note we use " := " to assign the name and just "=" for the equation itself.
> eqn:=x^3-5*x^2+7*x-12=0;
> subs(x=3,eqn);
> subs(x=4,eqn);
> subs(x=5,eqn);
>
Exercise 2.1
Assign the name k to the expression
. Then assign the name M to the expression
.
Finally have Maple calculate
. Note: to get Maple to multiply the expression out use the
expand( )
command. That is enter: expand(3*M+6); You will learn more about the expand command in the next subsection.
Student Workspace 2.1
>
>
>
>
>
>
Answer 2.1
> k:=x^2+4*x-3;
> M:=k^2-9;
> 3*M+6;
> expand(3*M+6);
>
Exercise 2.2
Expand
using the
expand( )
command.
Student Workspace 2.2
>
>
>
>
Answer 2.2
> w:=(1+x)^4;
> expand(w);
or we can do this all in one step with:
> expand((1+x)^4);
>
Exercise 2.3
Let
. Find
P if
x = 0.01 , a =
,
,
, and
.
Student Workspace 2.3
>
>
>
>
Answer 2.3
> P:=a*x^3+b*x^2+c*x+d;
> subs(x=0.01,a=-1/5,b=2/5,c=0,d=13/15,P);
>
Exercise 2.4
Use the subs( ) command to check if any of the numbers: 1,2 or 3 is a solution to the equation:
Student Workspace 2.4
>
>
>
>
>
>
>
>
>
>
Answer 2.4
> eqn:=x^3-16*x^2+51*x-36=0;
> subs(x=1,eqn);
> subs(x=2,eqn);
> subs(x=3,eqn);
>
Therefore x=1 and x=3 are solutions of the equation. (In Section 5 you will learn how to solve equations using Maple.)
The principal use of the expand( ) command is to "multiply out" products of polynomial expressions. It can also be used to expand trigonometric and other more general functions.
Example 1:
Use the
expand( )
command to multiply out
.
> k:=(x+2)^2*(3*x-3)*(x+5);
> expand(k);
>
Example 2:
Maple applies some familiar trigonometric identities to expand
and
.
> expand(sin(2*x));
> expand(cos(2*x));
Try expanding the sine and cosine of some other integer multiples of x. For example:
,
, etc.
Example 3:
Here is a final example. Have Maple multiply out the expression:
> h:=x^(1/2)*(x^(3/2)+x^(-1/2));
> expand(h);
>
Exercise 2.6
Expand
for n =2,3 and 4.
Student Workspace 2.6
>
>
>
>
>
>
>
>
>
Answer 2.6
> expand((x+1)^2);
> expand((x+1)^3);
> expand((x+1)^4);
>
>
Example 1:
Factor the expression:
> w:=3*x^2-10*x-8;
> factor(w);
Or you can do it all on one line:
> factor(3*x^2-10*x-8);
Example 2:
First expand the expression
. Then apply the
factor( )
command to the result. Can you explain why the final result looks different than the original expression ?
> H:=2*(x-2)*(2*x^2+5*x+2)*(x+4);
> ans:=expand(H);
> factor(ans);
Example 3:
Maple can factor expressions with more than one variable.
Factor the expression:
> h:=x^2*y+2*x*y+y;
> factor(h);
Example 4:
If Maple can't factor an expression using rational numbers (i.e. integers and fractions) then it returns the input unchanged.
> factor(3*x^2-10*x-9);
Example 5:
The factor command is not limited to polynomials. It can be used to factor other forms.
Factor
.
> factor((sin(x))^2-(cos(x)^2));
Example 6:
If the factor command is used with a rational expression, the numerator and denominator are each factored and common factors are cancelled to simplify the expression:
> A:=(x^3-7*x^2+15*x-9)/(x^2+4*x+4);
> factor(A);
> B:=(x^3-7*x^2+15*x-9)/(x^2-4*x+3);
> factor(B);
The next example allows you to see the factored form without cancellation.
Example 7:
Maple's numer( ) and denom( ) commands allow you to isolate either the numerator or denominator of a fraction. Here we use these commands to examine the factors of the numerator and denominator separately (i.e. before cancellation of common factors).
> B:=(x^3-7*x^2+15*x-9)/(x^2-4*x+3);
> factor(numer(B)); factor(denom(B));
Exercise 2.8
Factor the expression
.
Student Workspace 2.8
>
>
>
>
Answer 2.8
> factor(3*x^4-2*x^3+22*x^2-18*x-45);
Exercise 2.9
Factor the expression
and then use the expand command to check the result.
Student Workspace 2.9
>
>
>
>
>
Answer 2.9
> ww:=x^(1/2)-x^(3/2);
> factor(ww);
> expand(%);
Example 1:
Consider the expression
. Maple can apply identities to simplify many lengthy mathematical expressions, such as trigonometric expressions.
> V:=cos(x)^5 + sin(x)^4 + 2*cos(x)^2 - 2*sin(x)^2 - cos(2*x);
> simplify(V);
Example 2:
Trigonometric expressions with arguments in multiples of some angle will be simplified to trig functions in the single angle if possible:
> simplify(sin(5*t)+sin(3*t));
Example 3:
The simplify( ) command can be used to add rational expressions.
Rewrite the sum
as a single fraction.
> M:=(1/(x+1))+(x/(x-1));
> simplify(M);
>
Exercise 2.11:
Simplify the expression
Student Workspace 2.11
>
>
>
Answer 2.11
> simplify(7/(x+2)+(3*x)/(x+2)^2);
Exercise 2.12
How does Maple simplify
? Whether or not this "simplified" form is of use to you will depend on what you plan to do with it.
Student Workspace 2.12
>
>
>
>
Answer 2.12
> h:=sin(3*t)-sin(7*t);
> simplify(h);