Activity 2: Getting started with Maple

Maple is a powerful program for doing all kinds of math. It is to be found in the ``Mathematics and Statistics"' folder on UCS Macintoshes. Open the folder, and double click on the Maple icon. We will be using Maple to do two things: basic computation and plotting. You should try typing in all the examples given here, and make up your own, to make sure you know what is going on.

Basic computation

At the Maple prompt (the ``>'' sign) type in the following:
> 2 + 2 ;

Note the semicolon! This tells Maple that you have finished entering things and would like it to give you an answer. When you hit `Enter' (the key at the lower-right corner of the keyboard) you should see a 4 on the next line, and a new prompt looking for more input. Maple will do all of the simple forms of computation you are familiar with and much more besides. Here are some examples (everything after a # is a comment. You do not have to type it, and if you do, it will not be read in by Maple):
> 10 - 5 ;  # 10 minus 5
> 25.5 * 4 ; # * means multiply
> 25.5 / 4 ; # / means divide
> 2^4 ; # 2*2*2*2, or 2 to the power of 4
You can group expressions with parentheses, just as you do in ordinary math notation:
> (284 + 44) / 88 ;

Note that the result of the last computation is a rational number (a fraction): We will see how to change this to a real number (decimal number) a little later. Maple cares a great deal about whether you forget a character such as ``;'' or ``or spell a word wrong, but it does not mind extra spaces inserted between words or characters (though not within words of course). So following expressions are treated the same:
> (284   +   44) / 88 ;
> ( 284+44 )/88;

Assigning a value to a variable

Often, we will want to save the result of some computation in a form that is easy to refer to. If we do this:
> a := (284 + 44) / 88 ;
a := 41/22

then the variable a now has the value > a ;
Here is another example:
> q := 9 ;
q := 9

> q + 3 ;

We may want Maple to evaluate a, that is, to tell us what the decimal value of is. We can do this by typing:
> evalf(a) ;

Maple will also calculate functions. It already knows common functions such as sine, cosine, and square root (sqrt). You will read more about functions below.
> sin(1.2) ;

> sqrt(2) ;

2 to the power of a half is the same thing as square-root of two. A handy way to get Maple to evaluate the last expression is as follows:
> evalf(") ;

The " refers to the last expression Maple evaluated. Thus evalf(") in this case is the same thing as evalf(sqrt(2)). The expression before the last one is "", etc. Maple also knows most common constants such as (enter this as Pi) and e (enter as E). You can use evalf() to get numerical values for these:
> E ;

>evalf(") ;

Exercises 1

Throughout this tutorial, you will be asked to perform some calculations yourself. When you enter these into Maple, you should copy and paste the input into a text file which you save in your student locker account. When you are done, you should email me the file. Details on editing a text file, saving it in your locker account, and including it in an email message will be given in lab. To allow the Macintosh to cut and paste from a Maple session, you must open the ``Format'' menu, choose ``Output'', and from that menu, choose ``Character''. In future, this sort of choice will be written simply as format->output->character.

Exercises are numbered. In order to be sure of getting a grade of B, you must do correctly all those without a star. Exercises numbered with a star (e.g. 1.4*) are somewhat harder (though they should be do-able). Doing these in addition will head you towards an A or A+. All exercises should be completed and mailed to me by Monday, Sept. 18. A grade of F for this activity will be awarded to all submissions thereafter. Perform the following calculations. Note that we are not using Maple syntax; that is, you will have to translate the English into appropriate Maple expressions in order to do the calculations.


Often, we want to know whether two numbers are equal, or whether one is larger or smaller than the other. In each case, the answer is either true or false. A test of this sort is called a boolean test, and there is a special functions called evalb() to do it:
> evalb(2.0 > 4.0) ;

> evalb(2.0 = sqrt(4.0)) ;

Comparisons like these are done one at a time. So, if we want to know whether 0.5 is between 0 and 1 (which it is), although we might write this as 0 < 0.5 < 1, in Maple we type:
> evalb(0 < 0.5 and 0.5 < 1) ;

The function evalb() understands the following operators:
=, <, >, <= (less-than-or-equal), >=, and, or, and not. Some more examples:
> evalb(3.4 < 2.7) ;

>evalb(not 3.4 < 2.7) ;

Exercises 2


One of the best things about Maple is that we can plot functions. A function takes a number or numbers (inputs) and produces a number (an output). For example, the function y = 3x takes a single number as input and produces a number which is three times as big. Let us call this function threetimes(). Then threetimes(4) = 12, threetimes(2) = 6, and so on. Let us look at this function. First we will assign the name threetimes to the function.
> threetimes := x -> 3*x ;
> threetimes(7) ;
The first line says that threetimes is a function which takes a single input (x) and produces a single output (3*x). Now type:
> plot(threetimes, 0..10) ;
This will show the value of threetimes for all input values between 0 and 10. The plot appears as a separate window on the screen. (You will have to wait a few seconds before the window appears.) When you are done with it, you can close the window (just as you would close any Macintosh window). This helps to free up some memory and is highly recommended. Try also simply typing
> plot(threetimes) ;
what is the difference? Here is a plot of the sine function from 0 to 25:
plot(sin, 0..25) ;
Functions can be all sorts of expressions. Suppose you are interested in the function which maps all numbers less than 5 to -1, and all numbers greater than or equal to 5 to +1. You can define this function using an if statement. This has the form:
if (some-condition) then some-action else some-other-action fi
Note that the statement ends with ``if'' spelled backwards. This is the usual way to end long statements in Maple. Note also that you will need parentheses around the condition so that Maple knows where it ends. Here is an example:
> funnyfunction := x -> if (x < 5) then -1 else 1 fi ;
> plot(funnyfunction) ;
You can plot more than one function on the same graph, by making the first argument to plot a list of functions. A list is enclosed in curly brackets ({}), and its elements are separated by commas:
> plot({cos, funnyfunction}, 0..10) ;

Exercises 3

Plot the following functions. For each function, print out the plot. You will be required to hand in the plots (with your name at the top of each page) at the lecture on Tues., Sept. 19, or beforehand. Paper submissions like this may always be given to me at any lecture before the due date, or during my office hours.

Investigating periodic functions

Which of the following functions are periodic? If they are periodic, approximately what is their period? Note that if you do not specify a range of values for x, Maple will choose -10 < x < 10. You should experiment to find suitable values for each function.

Exercises 4

Investigating phase

Finally, we will plot pairs of functions. Your job is to say which are in phase and which are out of phase.

Exercises 5