Introduction to Maple in the Undergraduate Computer Lab

by James A. Carlson and Jennifer M. Johnson
Department of Mathematics, University of Utah
December, 1995

This document tells how to open a Maple file on the undergraduate lab machines, how to save and reopen files, how to print Maple sessions and plots, and introduces a few basic Maple commands. For further information about Maple commands see


Contents:

Back to Department of Mathematics home page

What is Maple?

Maple is a general purpose software package containing tools useful in the study of a wide variety of problems. We can use Maple like a calculator to carry out numerical computations or we can use the programming features of Maple to produce a more complicated sequence of computations. In addition to numerical computation, we can do symbolic or algebraic computations in Maple. This software package has built-in functions for solving many kinds of equations, for working with matrices and vectors, for differentiation and integration. It also contains functions which allow us to create visual representations of curves and surfaces from their mathematical descriptions.

Using a software package like Maple gives new ways to think about problems. For example, we can use the computer to run numerical experiments. This means that we can not only look at more realistic versions of standard problems, but we can easily look at many more examples, in the process developing a better intuitive feel for the essential features of a general problem and its solutions. Often these experiments suggest further questions or interpretations that might otherwise go unnoticed. Patterns that appear in these experiments give insight into and motivation for the standard approaches to these problems --- and frequently highlight the limitations of these methods.

In many situations the graphics features of Maple are a useful tool for visualizing the geometric ideas behind important definitions and standard techniques. Again, this goes a long way toward giving a better feeling for the essentials.

In the beginning computing can be frustrating because we are used to dealing with people, who are intelligent and cn undrstond whot u meen evn if it isn't quite right from a literal point of view. Anyway, you will soon get past this stage as the right moves become automatic. Eventually computers will be smarter and better designed, and this will make life easier for all of us.

Back to Table of Contents


Before you start learning Maple, it would be helpful if you familiarize yourself with the basics of the Xwindows system used on the lab machines. See the introduction.


Starting a Maple File

Move the cursor into the local window and type xmaple & to open a Maple window. Presently the ghost of a new window will appear in a kind of ``dotted outline form.'' Move the mouse to position this window and click with left mouse button when satisfied. (Try to place windows so that part of the title bar is visible for each window. Sometimes the mouse gets a bit wild and hard to control so you may end up with a window whose title bar is completely obscured. In that case, you can move and resize windows to get access to the title bar.) If you need help, ask! Getting used to the mouse and multiple windows can be very frustrating at first, especially if you are unwilling to get help when you need it.

Back to Table of Contents


Saving Your File

At the top of your Maple window you will see several menus. Click on the File menu with the left mouse button. To name a Maple file click on the option Save As with the left mouse button. A Save Session window appears: If the box labelled Selection near the bottom of this window is empty and you want to save your Maple file under the name hw1 (for example), then click anywhere in the Selection box with the left mouse button and type hw1. Then press the return key or click on the Save box at the bottom of the Save Session window. (It sometimes happens that the Selection box appears containing your full computer address. In that case you must place the cursor at the end of the name that appears in the box (after the /) and type your file name, etc.)

If this process was successful the name hw1.ms should appear at the top of the Maple window. Maple adds the .ms extension to identify the saved file as a Maple file. To avoid headaches you should use some care in naming your files. Keep it simple. Use only letters and numbers in your file names. Don't use any special symbols and in particular, avoid using spaces, periods, and hyphens.

All you have done so far is save a blank file. As you continue working you will need to update your saved file. Do this by clicking on the File menu and then the option Save in that menu. Do this frequently. Power failures or Maple memory failures can occur without warning at any time. In that case you will lose all work done since the last time you saved the file.

Back to Table of Contents


A Sample Maple Session

The following examples give an introduction to a few basic Maple commands and further technical details of using Maple in the Undergraduate Lab.

Example: Find the point of intersection of the two lines defined by 3x + 2y = 5 and 2x + 4y = 5 in the plane. Use Maple to find the intersection algebraically and graphically.

Solution: It is of course an easy matter to solve this system by hand, but for larger systems with more equations the help of a machine will be very welcome. The first line of your Maple window should contain the symbol >. This is called the Maple prompt. It is an indication that Maple is waiting for your next command. To solve in Maple, we write:

> solve( { 3*x + 2*y = 5, 2*x + 4*y = 5 } );

and Maple responds with this:

{ x = 5/4, y = 5/8 }

Except for minor (but important) differences of punctuation, we formulate the problem for Maple in the same way as we do for a fellow mathematician. Note that we give the system of equations as a set: a list of items separated by commas and enclosed by curly braces. This tells Maple to apply the function solve simultaneously to both equations. Typically, a Maple command takes a set as its argument if the order of the elements is not important --- in other words, since nothing about this problem changes if we give the equations in the other order, we give the list of equations as a set. The solution is also a set --- its elements are the simplified equations.

Notice that Maple commands end with a semicolon. Maple is very finicky about such things. It will not carry out any of your instructions until you end the command properly.

For the most part, spacing is not important in a Maple command, although generous use of the space bar makes your commands much easier to read.

If you made some typing mistakes in your command you may have gotten a syntax error. This means that Maple doesn't understand your command. With practice you will be able to use Maple's error messages to get clues about what kind of mistake you have made but at first they will probably be a bit mysterious. For example, you may see that you left out one of the * symbols or that you have typed = instead of +. To correct this kind of error you need not retype the entire command. You can use the arrow keys to move the cursor back into the line and then use the backspace key to erase your mistake. Insert the missing symbol and press Return. Maple will attempt to carry out your instructions. (You don't need to move the cursor to the end of the line. Maple will just look at the line the cursor is in.) Another common error is to forget to type the semicolon at the end of your command. You can move back into the line and add the semicolon as with the other typos. However, for a mistake like this you will probably have to enter the command twice before Maple gets it straight.)

Back to Table of Contents


Copying and Pasting with the Mouse

Often you will want to enter a command that is a small variation on an earlier command. In that case instead of retyping you can use the mouse to copy an old command and then paste it onto a new command line. Then you can move the cursor into the command and make modifications.

For example, notice that in our intersecting line problem Maple gave the result in fractional form. If possible, Maple tries to use algebraic methods to find solutions exactly. If we rephrase the question using decimals instead of integers for even one of the coefficients, then Maple approaches the question very differently and we get answers in decimal form:

> solve({3*x + 2*y = 5.0, 2*x + 4*y = 5});

gives (1.250000000, 0.6250000000) as the point of intersection.

Use the mouse to copy and modify the solve command above to get an answer in decimal form as described above.

You can paste repeatedly---the copied text stays in memory and anytime you press the middle mouse button it will be pasted at the current cursor position. (This can cause some problems for you if you accidentally hit the middle mouse button later on so you may want to copy some blank space to clear the copied text.)

Another way we could use the solve command is to solve the equation 3x + 2y = 5 for y as a function of x:

> solve( 3*x + 2*y = 5, y);

We see that the line 3x + 2y = 5 is the graph of the function f1(x) = -3x/2 + 5/2. Maple has a built-in command plot for producing graphs of curves in the plane. To obtain a graph of the line for x in [-2, 2] we use the command:

> plot( -3*x/2 + 5/2, x = -2..2);

In this command we see an example where spacing is important in Maple; no space is allowed between the dots in this command. A new window, called a plot window should appear in response to this command. This plot can be printed by itself or it can be pasted into your Maple window to be printed later (see below).

We have graphed the line given by the first equation and we can modify our work above to get a plot that contains both lines.

> solve( 2*x + 4*y = 5 , y);

tells us that the second line is the graph of the function f2(x) = -x/2 + 5/4 and we can tell Maple to graph f1 and f2 together:

> plot( {-3*x/2 + 5/2, -x/2 + 5/4}, x = -2..2);

Again notice the use of braces to tell Maple to apply the command plot to both functions. We see from the resulting plot that the lines meet at the point (5/4, 5/8)= (1.25, 0.625) as expected. Use the left mouse button to click on the intersection point; the coordinates of this point will then appear in the upper left corner of your plot window.

It is often a good idea to give your plot an explanatory title:

> plot( {-3*x/2 + 5/2,  -x/2 + 5/4}, x = -2..2, 
            title = `the lines 3x + 2y = 5 and 2x + 4y = 5`);
The quotation mark here is the backquote, located in the upper left corner of the lab keyboard; don't confuse it with the single quote. Also, note that this command is too long to fit on a single line. To enter a multiline command in Maple just press the Enter key instead of Return when you finish typing the first line of the command. When the command is complete and you are ready for Maple to carry it out, press the Return key.

You should be aware that Maple chooses the scale on the x-axis and the y-axis independently. To force Maple to use the same scale on both axes you can choose the option Constrained in the Projection menu in the plot window. Another way to achieve the same thing is to specify the range of variation for y in your Maple command:

 
> plot( {-3*x/2 + 5/2, -x/2 + 5/4}, x = -2..2, y = -2..2); 
or to specify the scaling option in your plot command:
 
> plot( {-3*x/2 + 5/2, -x/2 + 5/4}, x = -2..2, scaling = constrained); 
Back to Table of Contents


Printing a Plot

To give the printable version of your plot a name of your own choosing -- for example, intersection.ps -- click in the box labelled Output Filename, backspace to erase plotoutfile.ps and type intersection.ps instead. Then press Return or click to Confirm. Then print by typing print intersection.ps in your local window. This is useful if you want to delay printing. Any time you save a plot under the name plotoutfile.ps you replace the last plot you did with the new plot. So if you want to save several plots for later printing you need to give the files different names.

Remark: The extension .ps after a file name should mean that the file is a postscript file. All your plot files and the printable version of your Maple file are of this type. It is very helpful to indicate the file type with an appropriate extension as part of the file name.

Back to Table of Contents


Pasting a Plot into your Maple Window

Rather than printing the plot out separately you may prefer to include the plot in your Maple window and then print out your entire Maple session instead. This has the advantage that the plot appears with the commands that produced it. To do this

The plot should then appear in your Maple window. To continue working just use the arrow keys or click to move the cursor into the next command line. (It may happen that you don't see a Maple prompt > at the end of your file. You can get a new prompt by going to the Edit menu and selecting the option Insert Prompt. This can also be achieved using key commands---hold down the ``compose character'' key (referred to as ``Alt" in the instruction in the Maple menus) while you press the ``I'' key and a new prompt will appear below the line the cursor is in.)

Your plot will take up about half a page in the printed version. Often you won't need the plot to be so large. You can make the plot smaller (see directions above for resizing a window) before you paste it into your Maple file.

To get rid of a plot window click on the File menu in the plot window and choose the Exit option. If you change your mind and you want to get the plot back, just move the cursor into the command line that produced the plot and press Return.

Back to Table of Contents


Using Maple Help Files

In the example above we saw two ways to use the solve command in Maple. Are there others? We can ask Maple for more information about the solve command by typing ? solve or ?solve after the prompt. If we do this a help window will appear, containing a lot of (probably) incomprehensible information about the command solve. If you scroll to the end of the help window then you will see a list of examples. At first these examples won't be very easy to use but as you get more familiar with Maple these will become quite useful for figuring out how to get Maple to work for you.

Back to Table of Contents


Some Higher Dimensional Examples

So far we have looked at lines in the plane and we've seen an example of two useful Maple commands---plot and solve. Next we look at some three dimensional examples.

Example: Let P be the plane given by the equation 3x + y -2z = 2. Use Maple to plot this plane.

Solution: Maple has a built-in command plot3d for drawing surfaces in 3-space, but we have to describe the surface in the terms Maple expects. Although we can specify our plane with a linear equation as above, the command plot3d will not accept this description of P (we would get a syntax error). However, this plane can also be described as the graph of a function of two variables, namely as the graph of f(x,y) = (3x + y - 2)/2. From this description we can get a plot of P if we specify a range of x-values and of y-values over which to graph the function f:

 
> plot3d( (3*x + y - 2)/2, x = -3..3, y = -3..3); 
This command produces a 3d-plot window containing a graph of P, but without axes it is difficult to get any information from this picture. We cannot see how the plane lies in 3-space. At the top of the 3d-plot window are several menus. Choose the option Normal in the Axes menu. The plane disappears and is replaced with a box. Click anywhere in the plot window with the middle mouse button to redraw the plane P, now with axes. It is still difficult to interpret this picture because it is difficult to see how the axes as drawn relate to the plane. Try some other choices of axes style from the menu. The options Boxed and Framed are often better choices for surfaces. We can tell Maple to include axes by adding an option to our plot3d command. (This is a good chance to practice using the mouse to copy and modify an earlier command.)
 
> plot3d( (3*x + y - 2)/2, x = -3..3, y = -3..3, axes = boxed ); 
The surface in this case is very simple, but we also need to understand how this 2-dimensional object sits in 3-space. To get a better understanding of this we can turn the surface and look at it from different angles. Click on the plot with the left mouse button. The box should reappear. Hold down the left mouse button and drag to move the box. Click with the middle mouse button to redraw the plot. Experiment with different views of the plane. Experiment with the choices in the other menus as well. Recall that the option Constrained in the Projection menu forces Maple to use the same scale on all the coordinate axes.

Try ?plot3d to bring up the plot3d help file; the examples there give some more interesting surfaces.

Back to Table of Contents


Assignment Statements

Another important feature of Maple, assignment statements, are illustrated next. Assignment statements are used to store an expression or function or other quantity under a name.

Example: Use Maple to solve the system
3x + y -2 z = 1, 2x - 3y + 5z = 2, and 4x - 5y -3z = 3.

Algebraic Solution: We want to solve a system of equations so we define these equations in Maple, using the symbol :=(read "gets") to assign a name to each of them for future reference.

 
   > e1 := 3*x + y - 2*z = 1;  
     e2 := 2*x - 3*y + 5*z = 2; 
     e3 := 4*x - 5*y - 3*z = 3; 
Then to solve the system:
> solve({e1, e2, e3}); 
Warning: Assignment statements are the source of two very common and hard-to-spot syntax errors --- typing = instead of := and typing : = instead of :=.

Geometric Solution: We can solve the system above by finding the intersection of the three planes defined by equations e1, e2, e3 . To do this we need to plot these three planes together; the best approach is to describe each plane as the graph of a function of two variables and then use plot3d to produce the picture:

 
> f1 := solve( e1, z);
  f2 := solve( e2, z);
  f3 := solve( e3, z); 
> plot3d( {f1, f2, f3}, x = -2..2, y = -2..2, axes = boxed); 

Back to Table of Contents


Loading Packages

In our examples we have seen a few of the built-in features of Maple. For a list of the functions available in Maple type

 
> ?library 
In addition to this standard library of functions there are specialized packages of functions for working with special topics--- for example there is a collection of functions, called the linalg package for working with matrices and vectors and there is also a collection of plotting functions in the plots package. We will frequently use both these packages. To use the functions in these packages you must load them into Maple's working memory at the beginning of your Maple session using the with command.
 
> with(linalg);   # the warning you see is normal --- ignore it 
> with(plots); 
For more information type
 
> ?packages 
Back to Table of Contents


Editing Your Maple File

Often it will take more than one session at the computer to complete your analysis. You will need to save your work and come back to the lab and open your Maple file again to continue working. Often it will be useful to take with you a printed copy of your Maple session so you can think about what you have done so far and how you want to continue when you come back to the lab or so that you can talk to your instructor or your lab partner about any questions you may have.

Before you learn how to print your Maple session you should learn how to clean it up a bit. In the Edit menu of your Maple window you will find some useful commands for this purpose. For example the option Delete Cursor Region will delete whatever line the cursor is in. Note that holding down the "control" key while you hit the "delete" key will have the same effect. This gives you a quick way to erase your mistakes.

Also in the Edit menu you find the option Delete by Type. Choosing this option brings up another menu. Most of these choices are rather drastic and self-explanatory. Try the option Delete all Separators.

It is also a good idea to include some explanations with your work. There are two ways to do this. First you can use comments. In any command line, Maple ignores anything typed after the symbol #. So inserting a line like

> solve( 3*x + 2*y - 5*z = 1, z); # Get z in terms of x and y: 
makes your work much easier to follow. Notice that you can move anywhere you like inside your Maple window with the arrow keys or the mouse and the option Insert Prompt in the Edit menu allows you to insert a command line.

Also in the Edit menu you find the option Insert Text. This allows you to type some explanations into your Maple file. However, editing is very crude and there is no way to get decent looking mathematical formulas with Maple's text mode so if you want to say something complicated you may be better off with a handwritten note. Also be careful using Delete Cursor Region with text. Maple will delete the whole section of text rather than the line the cursor is in. (Try Display Region Boundaries in the View menu of your Maple window.)

Back to Table of Contents


Printing Your Maple Session

Alternatively, you could click on the option Printer Command in the Page Setup Dialog window to send your Maple session directly to the printer.

Back to Table of Contents


Ending Your Maple Session

Go to the File menu and choose the option Exit to end your Maple session. If your file contains results you will need later be sure to update with the Save option in the File menu before you quit.

Back to Table of Contents


Picking Up Where You Left Off -- Your Second Maple Session

In your work above you created a Maple file and saved it under the name hw1. Our task now is to reopen that file and get back to where we left off.

Your Maple window should now look like it did the last time you saved your file hw1. However, you are not quite ready to continue working. For example in your first session you made some assignments (using :=). Maple displays a record of these commands but it does not remember any of the assignments you made last time. Also, if you loaded a package of functions using with, the command will be there on your screen, but Maple will not have any of the functions of that package in its working memory.

The easiest way to get Maple to remember what happened last time is to go to the beginning of your file and hit the Return key until you get to the last line of the file. (You might want to use the arrow keys to skip the lines that displayed plots or requests for help files). This will ensure that Maple's memory of your last session is restored. The most important lines to re-enter are the lines where you loaded a package or read in a file (using the command with or read) or lines where you made assignments (using :=).

Remark: You will find it inconvenient to work with a Maple session file that is more than a few pages long. It is a good idea to start a new Maple file when you begin a new section of problems.

Back to Table of Contents