Lab 8 (Friday): First steps with Maple

To initiate a Maple session type in the command line:
xmaple &

In the Friday, Oct. 28th lab we encountered our first introduction to Maple, a "symbolic computation" software package which enables us to perform a vast array of mathematical operations on the computer. We'll get into the details of Maple later in the course, but this "worksheet" (as Maple files are called) servers to give you an idea of what the software can do, and how it works. 

Remember that the problem we were working on involved computing the sum 

sin(x) + sin(2x) + ... + sin(Nx) 

In C, we had to code this problem from scratch, using a loop. Maple, on the other hand, already understands the concept of a "sum". So let's first define a function, f, which will serve as the "i-th" term in our sum. Note that "assignment" in Maple is performed using := whereas in C it was performed using just =. 

> f := sin(i*x);
 

(Typesetting:-mprintslash)([f := sin(i*x)], [sin(i*x)]) 

Every time you run a command in Maple, it must be in an "execution group" like the above. Also, Maple will output the result of your command (even if it's kind of obvious, like in this case). You can suppress this output by replacing the semi-colon at the end of the line with a colon. 

> x := Pi/4;
 

(Typesetting:-mprintslash)([x := 1/4*Pi], [1/4*Pi]) 

> N := 100;
 

(Typesetting:-mprintslash)([N := 100], [100]) 

Here I've chosen some suitable values for x and N. Note that Maple understands concepts like sin and Pi without having to access additional libraries, unlike C. However, there are still many sets of commands (called packages) which are not integral to Maple but which can be accessed through special commands, just like in C. 

> sum(f, i=1..N);
 

1+2^(1/2) 

Unlike the C version of this code, where we had to create the algorithm ourselves, in Maple we can take advantage of a command already present within the software to compute the sum. However, because we used a "special" number for x, we don't get a floating point number -- Maple can actually work out an exact solution in this case. Fortunately, we can ask it to give us the decimal equivalent as well. 

> evalf(%);
 

2.414213562 

The % is Maple's way of referring to the output of the last executed command (in this case, line immediately preceding it, namely the result of our "sum" command). 


To see exactly what we did in the lab on Friday (including a section on programming not covered in the above... we'll get to that later), you can download a Maple worksheet (readable by Maple), which will look like this when you load it into Maple.