Application Center - Maplesoft

App Preview:

Maple Essentials: Section 2: Algebraic Calculations

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

section2.mws

Section 2: Algebraic Calculations  

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;

>   

The eval  command

Example 1

For our first example let's start with the expression   3*x^2+8   and assign it the name W.

>    W := 3*x^2+8;

W := 3*x^2+8

>   

Suppose now that you want to evaluate the expression   3*x^2+8  where x has the value 4. The quickest way to do this is to use Maple's eval  command. Here's what it looks like:

>    eval(3*x^2+8,x=4);

56

>   

Alternatively, you can apply the eval  command to W.

>    eval(W,x=4);

56

>   

Example 2

The eval  command works equally well with symbolic values:

To replace x  by 5+2*u  in the expression 3*x^2+8  execute the following line. In this case we label the result M.

>    W := 3*x^2+8;

W := 3*x^2+8

>   

>    M := eval(W,x=5+2*u);

M := 3*(5+2*u)^2+8

>   

And now to get Maple to "multiply out" this expression we use the expand  command.

>    expand(M);

83+60*u+12*u^2

>   

Example 3

The eval  command is very versatile. You can use it to evaluate expressions involving more than one variable. Here we replace x  by 7 and y  by 12  in the expression    U = 2/5*x^2+3*y  .

>    U := (2/5)*x^2+3*y;

U := 2/5*x^2+3*y

>   

Since U has two variables, the evaluating point then needs to be in a list, in square brackets [  ] separated by commas. Note x=7, y=12 are enclosed by a square bracket [ ].

>    q := eval(U,[x=7,y=12]);

q := 278/5

>   

As a floating-point (decimal) number, we have

>    evalf(q);

55.60000000

>   

Example 4

You can also use the eval  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   x^3-5*x^2+7*x-12 = 0   . 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;

eqn := x^3-5*x^2+7*x-12 = 0

>   

To see if 3 is a solution for eqn, execute:

>    eval(eqn,x=3);

-9 = 0

>   

Similarly, to see if 4 is a solution for eqn, execute:

>    eval(eqn,x=4);

0 = 0

>   

As you can see, since -9 is not equal to 0, 3 is not a solution to x^3-5*x^2+7*x-12 = 0 , and 0 = 0 indicates that 4 is in fact a solution. Again, 5 is not a solution as x^3-5*x^2+7*x-12 = 23  when x = 5 , which the following shows.

>    eval(eqn,x=5);

23 = 0

>   

Exercise 2.1

Assign the name k to the expression x^2+4*x-3  . Then assign the name M to the expression   k^2-9 .

Finally have Maple calculate 3*M+6  .

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.

255+180*u+36*u^2

Student Workspace 2.1

>   

>   

>   

>   

>   

>   

Answer 2.1

>    k := x^2+4*x-3;

k := x^2+4*x-3

>   

>    M := k^2-9;

M := (x^2+4*x-3)^2-9

>   

>    3*M+6;

3*(x^2+4*x-3)^2-21

>   

>    expand(3*M+6);

3*x^4+24*x^3+30*x^2-72*x+6

>   

Exercise 2.2

Expand   (1+x)^4  using the expand  command.  

Student Workspace 2.2

>   

>   

>   

>   

Answer 2.2

>    w := (1+x)^4;

w := (1+x)^4

>   

>    expand(w);

1+4*x+6*x^2+4*x^3+x^4

>   

or we can do this all in one step with:

>    expand((1+x)^4);

1+4*x+6*x^2+4*x^3+x^4

>   

Exercise 2.3

Let P = ax^3+bx^2+c*x+d  . Find   P  if   x = 0.01 , a =   -1/5   , b = 2/5 , c = 0 , and d = 13/15   .

Student Workspace 2.3

>   

>   

>   

>   

Answer 2.3

>    P := a*x^3+b*x^2+c*x+d;

P := a*x^3+b*x^2+c*x+d

>   

>    eval(P,[x=0.01,a=-1/5,b=2/5,c=0,d=13/15]);

.8667064667

>   

Exercise 2.4

Use the  eval  command to check if any of the numbers: 1,2 or 3 is a solution to the equation:

  x^3-16*x^2+51*x-36 = 0   

Student Workspace 2.4

>   

>   

>   

>   

>   

>   

>   

>   

>   

>   

Answer 2.4

>    eqn := x^3-16*x^2+51*x-36=0;

eqn := x^3-16*x^2+51*x-36 = 0

>   

>    eval(eqn,x=1);

0 = 0

>   

>    eval(eqn,x=2);

10 = 0

>   

>    eval(eqn,x=3);

0 = 0

>   

Therefore x = 1  and x = 3  are solutions of the equation. (In Section 5 you will learn how to solve equations using Maple.)

>   

The expand  command

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    (x+2)^2*(3*x-3)*(x+5) .

>    k := (x+2)^2*(3*x-3)*(x+5);

k := (x+2)^2*(3*x-3)*(x+5)

>   

>    expand(k);

3*x^4+24*x^3+45*x^2-12*x-60

>   

Example 2

Maple applies some familiar trigonometric identities to expand sin(2*x)  and cos(2*x)  .

>    expand(sin(2*x));

2*sin(x)*cos(x)

>   

>    expand(cos(2*x));

2*cos(x)^2-1

>   

Try expanding the sine and cosine of some other integer multiples of x . For example: sin(3*x)  , cos(6*x)  , etc.

>   

Example 3

Here is a final example. Have Maple multiply out the expression:    x^(1/2)*(x^(3/2)+x^(-1/2))

>    h := x^(1/2)*(x^(3/2)+x^(-1/2));

h := x^(1/2)*(x^(3/2)+1/(x^(1/2)))

>   

>    expand(h);

x^2+1

>   

Exercise 2.5

Expand   (x+1)^n   for n =2,3 and 4.

Student Workspace 2.5

>   

>   

>   

>   

>   

>   

>   

>   

>   

Answer 2.5

>    expand((x+1)^2);

1+2*x+x^2

>   

>    expand((x+1)^3);

1+3*x+3*x^2+x^3

>   

>    expand((x+1)^4);

1+4*x+6*x^2+4*x^3+x^4

>   

The factor  command

Example 1

Factor the expression: 3*x^2-10*x-8

>    w := 3*x^2-10*x-8;

w := 3*x^2-10*x-8

>   

>    factor(w);

(3*x+2)*(x-4)

>   

Or you can do it all on one line:

>    factor(3*x^2-10*x-8);

(3*x+2)*(x-4)

>   

Example 2

First enter in the expression   2*(x-2)*(2*x^2+5*x+2)*(x+4)  .

>    H := 2*(x-2)*(2*x^2+5*x+2)*(x+4);

H := 2*(x-2)*(2*x^2+5*x+2)*(x+4)

>   

Expand H using the exapand  command.

>    ans := expand(H);

ans := 4*x^4+18*x^3-8*x^2-72*x-32

>   

Then apply the factor  command to the result.

>    factor(ans);

2*(x-2)*(2*x+1)*(x+4)*(x+2)

>   

Can you explain why the final result looks different than the original expression ?

>   

Example 3

Maple can factor expressions with more than one variable.   For example, the expression   x^2*y+2*xy+y , that is,

>    h := x^2*y+2*x*y+y;

h := x^2*y+2*x*y+y

>   

factors to

>    factor(h);

y*(1+x)^2

>   

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);

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 sin^2*x-cos^2*x  .

>    factor((sin(x))^2-(cos(x)^2));

(sin(x)-cos(x))*(sin(x)+cos(x))

>   

Example 6

If the factor  command is used with a rational expression such as

>    A := (x^3-7*x^2+15*x-9)/(x^2+4*x+4);

A := (x^3-7*x^2+15*x-9)/(x^2+4*x+4)

>   

the numerator and denominator are each factored, as we see from

>    factor(A);

(x-1)*(x-3)^2/(x+2)^2

>   

The common factors in the expression

>    B := (x^3-7*x^2+15*x-9)/(x^2-4*x+3);

B := (x^3-7*x^2+15*x-9)/(x^2-4*x+3)

>   

are cancelled to simplify the expression, as we see from

>    factor(B);

x-3

>   

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.

For example, consider (x^3-7*x^2+15*x-9)/(x^2-4*x+3) .

>    B := (x^3-7*x^2+15*x-9)/(x^2-4*x+3);

B := (x^3-7*x^2+15*x-9)/(x^2-4*x+3)

>   

Here we use numer  and denom  commands to examine the factors of the numerator and denominator separately (i.e. before cancellation of common factors).

>    factor(numer(B));  
factor(denom(B));

(x-1)*(x-3)^2

(x-1)*(x-3)

>   

Exercise 2.6

Factor the expression 3*x^4-2*x^3+22*x^2-18*x-45  .

Student Workspace 2.6

>   

>   

>   

>   

Answer 2.6

>    factor(3*x^4-2*x^3+22*x^2-18*x-45);

(3*x-5)*(1+x)*(x^2+9)

>   

Exercise 2.7

Factor the expression     sqrt(x)-x^(3/2)       and then use the expand  command to check the result.

Student Workspace 2.7

>   

>   

>   

>   

>   

Answer 2.7

>    ww := x^(1/2)-x^(3/2);

ww := x^(1/2)-x^(3/2)

>   

>    factor(ww);

-x^(1/2)*(x^(1/2)-1)*(x^(1/2)+1)

>   

>    expand(%);

x^(1/2)-x^(3/2)

>   

The simplify  command

Example 1

Maple can apply identities to simplify many lengthy mathematical expressions, such as trigonometric expressions.  For example, c onsider the expression

cos(x)^5+sin(x)^4+2*cos(x)^2-2*sin(x)^2-cos(2*x)  

that is,

>    V := cos(x)^5+sin(x)^4+2*cos(x)^2-2*sin(x)^2-cos(2*x);

V := cos(x)^5+sin(x)^4+2*cos(x)^2-2*sin(x)^2-cos(2*x)

>   

which Maple simplifies to

>    simplify(V);

cos(x)^4*(cos(x)+1)

>   

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));

8*sin(t)*cos(t)^2*(2*cos(t)^2-1)

>   

Example 3

The simplify  command can be used to add rational expressions.

Rewrite the sum   1/(x+1)+x/(x-1)  , that is,

>    M := (1/(x+1))+(x/(x-1));

M := 1/(1+x)+x/(x-1)

>   

as a single fraction via

>    simplify(M);

(2*x-1+x^2)/(-1+x^2)

>   

Exercise 2.8

Simplify the expression 7/(x+2)+3*x/((x+2)^2)  

Student Workspace 2.8

>   

>   

>   

Answer 2.8

>    simplify(7/(x+2)+(3*x)/(x+2)^2);

2*(5*x+7)/(x+2)^2

>   

Exercise 2.9

How does Maple simplify sin(3*t)-sin(7*t)  ?  Whether or not this "simplified" form is of use to you will depend on what you plan to do with it.

Student Workspace 2.9

>   

>   

>   

>   

Answer 2.9

>    h := sin(3*t)-sin(7*t);

h := sin(3*t)-sin(7*t)

>   

>    simplify(h);

-4*sin(t)*cos(t)^2*(5+16*cos(t)^4-20*cos(t)^2)

>   

>