Introduction to Maple

A. J. Meir

Copyright (C) A. J. Meir. All rights reserved.

This worksheet is for educational use only. No part of this publication may be reproduced or transmitted for profit in any form or by any means, electronic or mechanical, including photocopy, recording, or any information storage and retrieval system without prior written permission from the author. Not for profit distribution of the software is allowed without prior written permission, providing that the worksheet is not modified in any way and full credit to the author is acknowledged.

(This document is largely based on a similar document originally written by P. G. Schmidt.)

Orientation

The projects and some of the homework that will be assigned during the quarter require the use of a computer and appropriate software. I recommend the symbolic algebra package Maple and will provide detailed instructions on how to use it on DUC PCs (such as may be found in Parker 252, 254, and 256) or Sun workstations (such as may be found in School of Engineering computer labs). Maple is also accessible from other computer labs maintained by the Division of University Computing (DUC) and from the labs in the School of Engineering. You are welcome to use other computer platforms and suitable software (such as Matlab, Mathematica - which is installed on DUC's PCs, or Macsyma) that you may be familiar with, but I cannot provide instructions on how to use those.

The instructions below refer to Maple 6 and assume that you are working on a PC running Windows (and Maple), or a Sun workstation using the CDE (the "Common Desktop Environment"), or a PC with X-server software, such as, X-Win32. Other systems may behave in slightly different ways.

Getting Started

1. Activating Your Account.

Every student at Auburn University has an account on the DUC computers. If you have never activated your account, call the AU Voice Automated Information System at 844-5800 to do so. You will be provided with a user name and (temporary) password that allow you to log into any of the public-access DUC computers on campus. Should you have trouble activating your account or encounter other network-related problems, call the DUC hotline at 844-5555, send email to hotline@mail.auburn.edu, or go to the DUC office in 26 L Building.

2a. Logging Onto a PC and Starting Maple.

Log onto a DUC PC (in one of the Parker Hall Labs) using your global DUC id and password (if you are logging on for the first time you will be prompted to change your password; do so following the online instructions ). When the system is up click the "Start" button (in the lower left corner of the screen). Choose "Programs" from the submenu and then "Maple 6" from the submenu and then again "Maple 6" from the submenu (that is Start->Programs->Maple 6 -> Maple 6). This action should bring up a window titled "Maple 6" with a subwindow titled "Untitled (1)". The subwindow is a so-called Maple worksheet; this is where you will enter Maple commands and where Maple's responses will be displayed.

2b. Starting the Common Desktop Environment and Manipulating its Windows on a Sun workstation.

Log onto a Sun workstations. If you are logging in for the first time, the system may ask you to change your password. Do so, following the instructions on the screen.

Next, open a Terminal window: Move the cursor to the background of the screen, press the right mouse button, and select "Terminal" from the "Programs" menu (that is Programs -> Terminal...). Wait for the window to open and activate
it by moving the cursor into the window and clicking the left mouse button. You can now type Unix commands in the Terminal window. Type, for example,

ls

and hit the Return key. The system will respond by displaying a list of all the files in your current directory.

Most of the windows that appear on the screen can be resized and moved around with the mouse. Try the following operations on one of the windows on your screen (for example, the Terminal window that you just opened).

To move a window, move the cursor to the window's title bar, press the left mouse button, and drag the mouse (while holding down the left mouse button). To resize a window, move the cursor to one of the window's corners or edges, press the left mouse button, and drag the mouse. To enlarge a window to its maximum size, click on the right-most button in the window's title bar (using the left mouse button). Clicking on the same button again will restore the window's previous size. Clicking on the adjacent button in the title bar will shrink (iconize) the window to a small icon, which can be reopened by double-clicking on the icon. (If you iconized a window and don't see the icon anywhere on the screen, it is probably hidden behind one of the other windows. You can retrieve it by moving the other windows.) To bring a partially obscured window to the front, click on the title bar or anywhere on the outer rim of the window.

If a window contains more text than can be displayed at one time, you can scroll through its contents by clicking on the up/down arrows in the scroll bar near the window's right margin, by dragging the scroll bar slider with the mouse, or by clicking the left mouse button either above or below the slider in the scroll bar. (You can try this in a Terminal window that you filled up with text by repeatedly executing the
ls command.)

Clicking on the button in the upper-left corner of the window's title bar and selecting "Close" from the pull-down menu will close (exit) the window, i.e., make the window disappear for good. (You can try this on a Terminal window and then open a new one.)

To get help about the system (operating system, Unix commands, and windowing system - CDE) click on the up-arrow right above the icon with the question mark in the main window's tool bar and selct the item desired.

Go into a Terminal window, type
xmaple &
at the prompt, and hit Return. (The & is optional but recommended; it causes Maple to "run in the background" and frees up the Terminal window for other tasks.) This action should bring up a window titled "Maple 6" with a subwindow titled "Untitled (1)". The subwindow is a so-called Maple worksheet; this is where you will enter Maple commands and where Maple's responses will be displayed.

2c. Runing Maple remotely (from Mallard) on a PC with an X-Server.

On a university PC with X-Win32 software do the following. Log into the PC using your global id and password. From the lower tool bar select Start -> Programs -> AUNet -> X-Win32. Log into mallard (the university's Unix server again using your global id and global password). You should now have a mallard terminal window (if so, go to the next step). If you do not get a mallard terminal window (or if you close it or want to open another one) open the X-Win32 window and start a mallard session by selecting Session (while holding the mouse button down) select mallard (you will get a mallard terminal window).

Go into a Terminal window, type
xmaple &
at the prompt, and hit Return. (The & is optional but recommended; it causes Maple to "run in the background" and frees up the Terminal window for other tasks.) This action should bring up a window titled "Maple 6" with a subwindow titled "Untitled (1)". The subwindow is a so-called Maple worksheet; this is where you will enter Maple commands and where Maple's responses will be displayed.

2d. Other Operating Systems/Window Managers

If you read so far you should have gotten the gist of things and can probably figure out how to use other operating systems (Linux, MacOS) and other window managers.

3. Your First Maple Session.

Warning: Maple 6 is very similar to Maple V Release 5, but there are substantial differences between Maple V Release 5 and earlier versions of Maple. Before continuing, check the title bar of the Maple window to make sure you have the correct version. (What if you are getting an earlier version of Maple or no Maple at all? --- If you are working on a School of Engineering account, you may have to first enable access to Maple 6 by running user-setup and selecting the correct version of Maple. If you are working on a DUC account, try a different workstation in the lab or contact the DUC hotline to complain.)

Move the cursor into the window titled "Untitled (1)". Activate the Maple worksheet (by clicking on it). At the Maple prompt ( > ), type

> 2+3; (including the semicolon) and hit Return. Maple should respond with the obvious
answer and you will see:

5

You can now type a new command at the ( > ) prompt, for example,

> diff(sin(x),x); and execute it (by hitting Return). You will see:

cos(x)

cos(x) (the derivative of sin(x) with respect to x ). Next, enter the command

> plot(sin(x),x=0..10); which should cause Maple to generate a plot of sin(x) on the interval [0,10]

[Maple Plot]

If you feel like it, experiment with the plot command to graph some other functions or enter the following commands and guess what they cause Maple to do:

> int(sin(x),x);

> int(sin(x),x=0..Pi);

> limit(sin(x)/x,x=0);

> limit(sin(x)/x,x=infinity);

4. Editing Maple Commands.

Just like other programming language (or software package), Maple is extremely picky about syntax, spelling, and punctuation. If it doesn't "like" a command, Maple will respond with an error message. For example, ask Maple to differentiate cos(x) with respect to x by entering

> diff(cos x,x); (including the space), and Maple will complain about a syntax error:

Error, missing operator or `;`

You are supposed to enclose the argument of the cosine function (and of any function, for that matter) in parentheses. To correct the mistake, just move the cursor back into the previous command line (by clicking on the desired cursor position), change cos*x to cos(x) , and re-execute the command by hitting Return. If you erroneously typed

> diff(cosx,x); (without a space), Maple would not complain but, even worse, produce a "wrong" answer:

0

(Try it!) The explanation is that Maple thinks of cosx as a (strangely named) constant rather than a function of x .

Just like you can correct a mistyped or erroneous command without having to retype it from scratch, you can edit and re-execute any command that you previously entered. For example, to generate a plot of
cos(x) , just move the cursor back to the command that you used earlier to plot sin(x) , change sin to cos , and hit Return.


It is also possible (and often convenient) to copy a previous command (or parts of it) to a new command line (and then edit it, as needed). For practice, let's copy the last plot command: Highlight the command (by dragging the cursor along the text to be copied while holding down the left mouse button), then move the cursor to a new command line, click the left mouse button to position the cursor, and then the middle mouse button to copy the text. (Alternatively, you could have selected "Copy" and "Paste" from the "Edit" menu at the top of the main Maple window, or Ctrl-C for copy and Ctrl-V for paste).

5. Help.

Detailed information on the syntax and usage of all Maple commands is available through the "Help" menu at the top of the main Maple window. (Check out how it works.) The help page for a specific command can also be accessed directly from a command line. Enter, for example,

> ?plot; and Maple will display the help page for the plot command (in a separate window).

Specific examples for the proper usage of a command are usually found at the bottom of the relevant help page. You can copy these examples into your worksheet and execute them to see what they cause Maple to do (but don't worry about the details for now). If you don't need it any more, close the help window (by clicking on the button in its upper-left corner and selecting "Close" from the pull-down menu).

6. Loading and Saving Maple Worksheets.

You can save your current Maple worksheet at any time by selecting "Save As" from the "File" menu at the top of the main Maple window. Do this now. A dialog box will pop up, displaying a list of the directories under your home directory and a list of previously saved Maple files (if you have any) in the current directory. When you do this for the first time (and depending on the system you are on) the current directory may not be your home directory. If the current directory is not your home directory (or a subdirectory under it) you must first change directories. On a Windows PC pull the "Drives" menu at the bottom of the dialog box (by clicking on the arrow) and select h:\\labserv2\homes. This will put you in your home directory and allow you to save your worksheet. On a Sun or using X-Win32 navigate through the file system untill you get to your home directory.

Type a filename of your choice into the box in the upper-left corner of the dialog box, changing *.mws to something like session1.mws (for convenience the name should end with .mws ). Then click on "OK". This action will save your worksheet, under the chosen name, in the current directory.

Now make some changes in the worksheet; for example, type and execute a new command. To save the updated version of the worksheet under the same name as before, just select "Save" from the "File" menu. This will cause the old file to be overwritten. If you want to keep the old file and save the new version under a different name, select "Save As" and proceed as before.

Once saved, a worksheet can be reloaded at any later time. Try the following: Save your current worksheet and then close it by selecting "Close" from the "File" menu. One of the items on the "File" menu should now be the name of the worksheet that you just saved and closed. Select that item, and Maple will reopen the worksheet. To load a file that does not appear directly on the "File" menu, select "Open"; this will bring up a dialog box. Select the name of the file to be loaded from the list in the dialog box (or type the name directly into the appropriate box), then load the file by clicking on "OK".

Several worksheets can be open at the same time, but only the one on top of the stack will be active. To open a fresh worksheet, select "New" from the "File" menu. Do this now and execute a few commands (just like those in your first worksheet). Then save the new worksheet under a new name (for example,
session2.mws).

You can now switch back and forth between your worksheets and edit, save, close, and reopen them as desired.

Note: Save your worksheets repeatedly while you are changing them. Or set the "AutoSave" (look under the "File" menu) else, you could easily lose a lot of work if the system becomes corrupt (which is unlikely, but possible). Or if Maple crashes "dumps core" which I have succeeded in doing several times.

If the top worksheet fills up the entire Maple window, you will not be able to see any other worksheets underneath. However, you can reduce the size of all open worksheets and cascade them in such a way that at least the title bars are all visible. To do this, select the "Cascade" option from the "Window" menu. Still, only the top worksheet is active, but you can now activate any of the open worksheets by clicking on any visible part of its window.

A reduced-size worksheet can be moved around by clicking on its title bar and dragging the mouse while holding down the left mouse button. And the height and/or width of any reduced-size worksheet can be changed individually by clicking on one of its edges or corners and dragging the mouse while holding down the left mouse button.

There are three buttons in the upper right corner of each window. Clicking on the right button will close the window; clicking on the middle button will switch from reduced size to maximum size or vice versa; clicking on on the left button will iconize the window.

7. Printing Maple Worksheets.

To print a hardcopy of the currently active worksheet, select "Print" from the "File" menu. A dialog box will pop up. By default, the print job will be routed to a laser printer located in 256 PKH (assuming that you are working in one of the Parker Hall labs). Just click on "OK" to make this happen. There is also a "Print Preview" option on the "File" menu that allows you to preview the page layout of a worksheet or plot before printing.

WARNING: Begining DUC will charge you five cents per printed page, to be billed to your account at the bursar's office. But even if money is no object, you should avoid excessive printing. Save a tree! If at all possible, print only the final versions of your worksheets, graphs, and so forth. It may also save a lot of paper if you "demagnify" your worksheets before printing them. To magnify or demagnify a worksheet, select a suitable "Zoom Factor" from the "View" menu on the menu bar at the top of the main Maple window. Unfortunately, this may sometimes lead to print errors.

On the Sun or PC with X-Win32. To print a hardcopy of the currently active worksheet, select "Print" from the "File" menu. A dialog box will pop up, providing you with various print options. By default, the worksheet will be written to a Postscript file of the same name, but ending with .ps (instead of . mws ). Just click on the "Print" button to make this happen. Of course, you can change the name of the output file, but for convenience it should always end with .ps.

Once saved as a Postscript file, the worksheet can be printed on a laser printer. For example, to print a file named session1.ps , go into a Terminal window, type
lp session1.ps
and hit Return. This causes the file to be sent to your default printer. (It may be the printer in the basement of Parker Hall, assuming that you are working in the Parker Hall lab. The printout can be picked up at the window across the hall from Parker 100; an attendant is supposed to be present 24 hours a day, theoretically.)

You can print several Postcript files simultaneously by typing, for example,
lp session1.ps session2.ps session3.ps

or
lp session*.ps
The last command will print all the files in your current directory that begin with session and end with .ps.

It is possible to print hardcopies of a worksheet directly, without first creating a Postscript file, but I don't recommend this. Anyway, save some trees --- avoid excessive printing! If at all possible, print only the final versions of your worksheets, graphs, and so forth.

You can preview your Postscript file, and the way the printed version will look by finding the Postscript file in your File Manager and opening it by double clicking on its icon.

You should be aware that Postcript files use up relatively large amounts of disk space; they should be discarded after the hardcopies have been successfully printed. (There's no need to keep Postcript files for long --- they are easy to recreate from their .mws source files, using the "Print" menu. Of course you should keep the source files!) To remove a file named session1.ps f rom your computer's disk, go into a Terminal window, type

rm session1.ps
and hit Return. The system may ask you whether you really want to remove the file. If so, type

y

(for "yes") and hit Return. You can remove several files (Postscript or other) simultaneously, using the same syntax as with the lp command. Be careful, files removed are gone forever and cannot be retrieved.

8. Printing Graphs.

Frequently, you may want to print a hardcopy of a single graph rather than the entire worksheet that contains it. To do so, go to the "Options" menu at the top of the main Maple window and select "Plot Display" and "Window". This action has no immediate effect, but if you now re-execute one of the plot commands in your current worksheet, or type and execute a new one, the graph will appear in a small separate plot window (you may want to enlarge it). In fact, all subsequent plots will appear in separate windows, unless you go back to the "Options" menu and select "Plot Display" and "Inline", which would cause subsequent plots to be embedded in the worksheet again.

To print a hardcopy of a graph displayed in a plot window, proceed in exactly the same way as if printing a worksheet: Activate the plot window and select "Print" from the "File" menu, causing the usual print dialog box to come up.You may also want to change the page layout: Most graphs look better in "Landscape" than in "Portrait" format. You can select either one by choosing "Print Setup" from the "File" menu and clicking on the appropriate button (the default is "Portrait"). To suppress the page number, which would normally appear at the bottom of the hardcopy, deselect the option "Number Pages". There is also a "Print Preview" option on the "File" menu that allows you to preview the page layout of a worksheet or plot before printing.

On the Sun or PC with X-Win32. If you just click on the "Print" button, the graph will be saved as a Postscript file named untitled-plot.ps. You should change the filename to something like plot1.ps. You may also want to change the page layout: Most graphs look better in "Landscape" than in "Portrait" format. You can select either one by clicking on the appropriate button (the default is "Portrait"). To suppress the page number, which would normally appear at the bottom of the hardcopy, deselect the option "Number Pages". Finally, click on the "Print" button to create a Postscript file and send it to the laser printer in the usual way, using the lp command (in a Terminal window).

Note: After you clicked on the "Print" button, the graph may have disappeared from the plot window. If so, just click on the button in the upper-left corner of the plot window's title bar and select "Refresh" from the pull-down menu. This should restore the graph.

9. Customizing Graphs.

By default, the graphs that Maple embeds in a worksheet are fairly small. You can change that by enlarging the worksheet (and if necessary, the main Maple window). Enlarging the worksheet will increase the size of all subsequently generated graphs, but won't affect the type size used for other Maple output and commands.

It is also possible to change the appearance of an individual graph in a worksheet. To do so, click on the graph; this will create a bounding box, and a "Style" button will appear in the menu bar at the top of the main Maple window. You can resize the graph by dragging one of the dots on the bounding box. Moreover, you can change the style in which the graph is drawn by selecting "Line" or "Point" from the "Style" menu. If you selected "Line", you can change the "Line Style" (solid or dashed) and the "Line Width" (thin or thick). If you selected "Point", you can change the "Symbol" (dot, cross, circle, and so forth). There are also several options regarding the style of the coordinate axes; those can be selected from the "Axes" menu.

The "Style" and "Axes" menus are also available when a graph is displayed in a separate plot window (and of course, you can resize a plot window just like any other window on the screen).

10. Turning Your Worksheet Into a Document.

Maple features a built-in text editor. To enter text (such as commentary or remarks) into a worksheet, place the cursor at the beginning of a command line, in front of the > , go to the "Insert" menu, and select "Paragraph" and "Before" or "After". This will insert a blank line, in which you can type plain text, before or after the command line containing the cursor. The text you type will wrap around automatically when you reach the end of the line, but you can also force a line feed by hitting Return. (Incidentally, to force a line feed in a command line, you have to press the Shift and Return keys simultaneously --- just hitting Return would cause execution of the command rather than a line feed.)

In text mode, three special pull-down menus and several extra buttons appear in the context bar (the lowest bar at the top of the main Maple window). You can select from a variety of text styles, font styles, and font sizes, choose bold-face or italic fonts, underline text, and switch between left-justified, centered, and right-justified text. The default text style is "Normal". Other available styles are "Title"and "Author"; if selected (from the left-most pull-down menu in the context bar), they cause whatever text you enter to appear centered and in a special style suitable for the "top matter" of a document.

When you are typing text and come across a math formula, click on the "
S " button in the tool bar at the top of the main Maple window. Then type the formula just like you would type the corresponding Maple command. When finished, switch back to text mode by clicking on the "T" button in the tool bar.

For practice, insert the following heading and text at the beginning of your current worksheet (see below for detailed instructions):

An Interesting Function

by Whoever I. Am

In this paper we will determine the derivative and an antiderivative of the function y = exp(-x^2) and then plot its graph .

Insert a paragraph as described above, using the "Insert" menu; select the text style "Title" and type the heading; hit Return, select the text style "Author", and type
"by Whoever I. Am "; hit Return, select the text style "Normal", and type the first part of the sentence, up to the formula; click on " S " and type y=exp(-x^2) click on "T", and type the rest of the sentence; highlight the word "derivative" and click on " B "; highlight the word "antiderivative" and click on "I "; highlight the word "graph" and click on "u ". You can toggle the math input mode between "Standard math" and "Maple notation", executable and nonexecutable by using the x and Maple leaf

buttons on the left of the context bar.

Just as you can insert paragraphs of text anywhere in a worksheet, you can insert new command lines by placing the cursor in the desired position, going to the "Insert" menu, and selecting "Execution Group" and "Before Cursor" or "After Cursor". As a shortcut for the latter, just click on the "[> " button in the tool bar. For practice, insert one or more new command lines after the heading and text you just entered; then type and execute the following commands:

> y:=exp(-x^2); diff(y,x); int(y,x); plot(y,x=-5..5);

y := exp(-x^2)

-2*x*exp(-x^2)

1/2*sqrt(Pi)*erf(x)

[Maple Plot]

Any part of a worksheet can be deleted by highlighting it and clicking on the button with the scissors in the tool bar or by selecting "Cut" from the "Edit" menu. Of course, there are also buttons and menu items for "Copy" and "Paste" operations and various other editing functions.

11. Interrupting, Restarting, and Quitting.

To abort a Maple procedure that seems to be taking too much time, click on the button with the stop sign in the tool bar of the main Maple window. To clear Maple's internal memory, type

> restart; (followed by a colon or semicolon) in a command line;

this will not affect the appearance of your worksheet but cause Maple's computing engine to restart "with a clean slate".

To close a worksheet, plot window, or help window, select "Close" from the "File" menu of the main Maple window (or from the menu under the button in the upper-left corner of the window to be closed's title bar). To quit Maple altogether, select "Exit" from the "File" menu of the main Maple window.

To log out of your computer (PC), click on the "user-logged in" icon at the bottom left of the screen (next to the "Start" icon) and then on the "Yes" button in the dialog box that will pop up.

To log out of your workstation (Sun), click on the "Exit" button at the bottom of the screen in the main window's tool bar and select "OK" in the dialog box that will pop up.

To find out More on Maple.