Objectives: In this tutorial, we discuss the general properties of a computer algebra system as Maple and illustrate some of the basic commands. We also discuss programming in Maple with an illustration of the if .. then .. else command. After working through these materials, the student should be able to perfom some simple calculations using Maple and to write some programs in Maple utilizing the if .. then .. else command.
Computer Algebra Systems: A computer algebra system is a program that will perfom mathematical calculations in exact, symbolic form.
Examples from Maple. First, we will show some of the operations on numbers.

> 2/5 + 3/7;

[Maple Math]

Comments:

  1. Note that fractions are not converted to decimals.
  2. Also, note the presence of the semicolon at the end of the expression; it is required before the results of the calculation are shown.

> 4*(2/9)^5;

[Maple Math]

> 50!;

[Maple Math]

 > 3^500;

[Maple Math]
[Maple Math]
[Maple Math]

Comments:

  1. The three examples above show what is meant by exact arithmetic.
  2. What is also illustrated in the first example is that if you want to multiply two quantities, a and b, in Maple, then you must use a * b and not ab.
  3. ^5 indicates that the expression before the caret ^ is raised to the power 5.
  4. ! represents factorial.
  5. When the answer extends beyond a line as in the third example above, Maple uses the symbol \ to indicate this.

> factor(x^3-6*x^2-19*x+84);

[Maple Math]

> (a+b)^5;

[Maple Math]

> expand(%);

[Maple Math]

Comments:

  1. Maple can perform some of the operations encountered in algebra. The first command factor above tells Maple to factor the polynomial x3 - 6x2 - 19x + 84.
  2. Maple can use letters as constants as indicated in the next two commands shown above. In the second command above, we are asking Maple to raise the sum a + b to the fifth power. The third command above tells Maple to expand this expression. The symbol % to use the previous calculation. (Note that we wrote the previous calculation rather than the previous line! This distinction will be discussed later.)

Exercises:

 


Programming in Maple. It is also possible to program in Maple. For example, the following is a program defining a function that determines whether an integer is even or odd.

> parity:=proc(n)

> if(irem(n,2)=0) then RETURN(Even);

> else RETURN(Odd);

> fi;

> end:

Comments:

  1. This program defines a function which we have called parity. The first line of the program, parity:=proc(n) , defines the name of the program and indicates that it is a procedure which can be thought of as another name for a function. The n is the name of the variable that represents an element of the domain of parity.
  2. The Maple command irem(n,2) calculates the remainder of the division of n by 2.
  3. The second line of the program then states that if 2 divides n, then Maple must RETURN(Even). That is, Maple will respond with the word Even.
  4. If 2 does not divide n, then the program moves to the else statement on the next line. In this case, Maple will respond with the word Odd.
  5. The fourth line, fi;, indicates the end of the if .. then .. else statement.
  6. The fifth line, end:, indicates to Maple that this is the end of the program.

To test our function, we type

> parity(23);

 

Odd

> parity(122);

Even

Click here to read more about the if .. then .. else statement.


Exercises:
  1. Write a Maple program by modifying the program above and using the if .. then .. else statement that finds the maximum of two numbers.
  2. Write a Maple program by modifying the program above and using the if .. then .. else statement that finds the absolute value of a number. (Maple has a command, abs, that finds the absolute value of a number. Do not use this command in your program.)