Introduction to MapleV.4 in the Undergraduate Computer Lab

by James A. Carlson and Jennifer M. Johnson
Department of Mathematics, University of Utah
September, 1997

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

For the previous version of this document see Intro to MapleV.3

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.

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.

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 As window appears with the name *.mws in the Filename box. If you want to save your Maple file under the name hw1 (for example), then put the cursor in the filename box between the * and the .mws extension. Backspace to delete the * and type hw1. Then press the return key or click on the OK box at the top of the Save As window.

If this process was successful the name hw1.mws should appear at the top of the Maple window. Maple adds the .mws extension to identify the saved file as a Maple file. Keep your file names simple. Use only letters and numbers and don't use any special symbols. In particular, avoid using spaces, periods, and hyphens.

Be careful about reusing a file name from a previous session. For example, if last week you made a file named Lines.mws and this week you open a new Maple session and call it Lines.mws also, this will ERASE the file you created last week. Notice that the Save As window lists the Maple files in your current directory, so you can see which names you have already used.

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 the given system 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.)

Back to Table of Contents


Plotting Curves in Maple

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 y = -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.

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 y = -x/2 + 5/4 and we can graph these lines 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 anywhere on the plot. A box will appear around the plot (and the menu items and tool bars at the top of the window will change as well). Now click on the intersection point of the two lines with the left mouse button. The coordinates of this point will appear in a box in the upper left.

With the left mouse button click on one of the black dots at the edge of the box surrounding your plot. While holding down the mouse button, drag to make the box bigger (or smaller). Release the mouse button when your box is the desired size. This will enlarge (or shrink) the plot. Try this now.

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 at the top of your Maple 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); 
To delete a plot from your worksheet just click on the plot to enclose it in a box and then hold down the Control Key (probably labelled Ctrl) while you hit the Delete Key.

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 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. These examples are quite useful for figuring out how to get Maple to work for you.

Now suppose you want to figure out how to compute square roots in Maple. One approach is simply to type

 
> ?square root; 
Sometimes this will work, but not in this case. Maple doesn't find the help page you need.

Instead you can use the options Topic Search in the Help menu of your Maple window. Try this now. Click in the box labelled topic and type s. Maple has found lots of help pages on topics that start with the letter 's'. Now type the next letter, in this case q. Now Maple lists three help files on topics that begin with the letters 'sq' and the command we want is probably sqrt. Click on that topic and press Enter and the help file for the square root function appears. Now you can scroll down to the examples at the end of the file to see how this function is used.

For a more general search, to find all help files that contain a particular phrase, you can use the option Full Text Search in the Help menu of your Maple window. Select this option now, type square root in the Word(s) box, and hit return.

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 plot of the plane, but without axes it is difficult to understand. We cannot see how the plane lies in 3-space.

Click anywhere on the plot. A box appears around your plot as we saw above when we learned to use plot to draw curves in the plane. We can shrink or enlarge the plot as we did there. In addition new, plot-related menus appear at the top of the Maple window.

Choose the option Normal in the Axes menu. The plane disappears and is replaced with a 3-d box. Click on the icon labelled R to redraw the plane 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. Alternatively, 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. To do this, click anywhere on the plot, hold down the mouse button and drag. The plot will be replaced by a 3-d box that we can rotate. Then release the mouse button and click on the redraw icon (labelled R).

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. You can cut and paste these sample plot commands into your Maple session to see what these surfaces look like.

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

 
> ?index
and click on the link function in the window that appears. Then choose a function, say Gausselim from the list to get more information.

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. For example to delete a computation or a plot, just move the cursor into the command that produced the computation or click on the plot. Then while holding down the Control key, press the Delete key. You could discover this by looking at the Edit menu. You can learn the key commands for editing from the menus.

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.

As an example, add explanatory comments to the sample Maple session we did above. Enter the commands

> solve({ 3*x + 2*y = 5, 2*x + 4*y = 5});
> solve({ 3*x + 2*y = 5.0, 2*x + 4*y = 5});
> solve( 3*x + 2*y = 5, y);
in your Maple window. To add explanatory comments between the first and second commands, move the cursor into the first command. Then click on the icon containing a Maple prompt [> . A new command line should appear and the cursor will be on this new line. To enter text instead of Maple commands, click on the icon labelled T . Now you can type something like "Find the intersection point in decimal form:" and it will appear as ordinary text. Notice the three pull-down menus at the top of the Maple window (when you are in Text mode) that allow you to control the size and style of the text you enter.

Back to Table of Contents


Printing Your Maple Session

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 :=).

Shortcut: In the Edit menu, select the option Execute and then select the option worksheet

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