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.)
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 OIT 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 Office of Information Technology (OIT) and from the labs in the School of Engineering. You are welcome to use other computer platforms and suitable software (such as Matlab or Mathematica - which may be installed on OIT PCs, or the OSS Maxima, see, e.g., FOSSWIN or Maxima) that you may be familiar with, but I cannot provide instructions on how to use those.
The instructions below refer to Maple 11, depending on your operating system and GUI (graphical user interface) there may be some differences. The following should probably work on a PC running Windows, on a Sun workstation running Solaris and using the CDE (the "Common Desktop Environment") or Java desktop, on a Linux box with X11, and on a Mac running OS X. Obviously all these must have the appropriate version of Maple installed. Other systems may behave in slightly different ways.
1. Activating Your Account.
Every student at Auburn University has an account on the OIT computers. Your GID (global ID) is the first part of your e-mail address. You will also need your password, this is the password that allows you to log into any of the public-access OIT computers on campus. Should you have trouble with your account or encounter other network-related problems, call the OIT helpdesk at 844-4944, or send email to firstname.lastname@example.org.
2a. Logging Onto a PC and Starting Maple.
Log onto an OIT PC (e.g., in one of the Parker Hall Labs) using your global id and password When the system is up click the "Start" button (in the lower left corner of the screen). Choose "Programs" from the submenu and then "Maple11" from the submenu and then again "Maple 11" from the submenu (that is Start->Programs->Maple 11-> Maple11). This action should bring up a window titled "Maple 11" with a subwindow titled "Untitled (1)". The subwindow is a so-called Maple Worksheet, or Maple Document (depending on the mode you are in); this is where you will enter Maple commands and where Maple's responses will be displayed. You may also have a shortcut to Maple on your desktop.
2b. Logging In and Starting Maple on Unix-Like (Mac, Linux, Solaris) Computers.
Log onto the computer. Depending on your environment, figure out how to start Maple, there may be a link to Maple on your desktop, or it will be in you applications directory, or open a Terminal window and in it type the command
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 11" with a subwindow titled "Untitled (1)". The subwindow is a so-called Maple Worksheet or Maple Document (depending on the mode you are in); this is where you will enter Maple commands and where Maple's responses will be displayed.
2c. 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 and other window managers.
3. Your First Maple Session.
Note: A good place to start is the documentation, you may want to look at Getting Started , and also see the Maple Quick Reference Card which can be accessed from the Help pull-down menu.
In my opinion it is easier (at least initially) to use Maple in worksheet mode (and use only 1-D input, but you should experiment and see which you like better, to switch to worksheet mode insert the Maple prompt
Now lets try it: 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:
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:|
(the derivative of with respect to ). Next, enter the command
|>||plot(sin(x),x=0..10); which should cause Maple to generate a plot of on the interval [0,10]|
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:
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 with respect to 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 to , 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:|
(Try it!) The explanation is that Maple thinks of as a (strangely named) constant rather than a function of .
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 , just move the cursor back to the command that you used earlier to plot , change to , 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-v for copy and Ctrl-v for paste, Cmd-c and Cmd-v, if you are using a Mac).
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. Navigate to the correct directory (might be on the h drive). On a Windows PC pull the "Drives" menu at the bottom of the dialog box (by clicking on the arrow) and select h:\\labservXX\homes. This will put you in your home directory and allow you to save your worksheet. On other machines just 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 *.mw to something like session1.mw (for convenience the name should end with .mw). 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.mw).
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 "Maple11-> Preferences", or "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" on a Unix box) 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 (again different platforms are slightly different). 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, but you already knew this, and again different platforms and window managers will be different.
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: OIT charges you five cents (this may be an old figure and out of date) 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.
You may also be able to print to a file. In particular, on Unix-like platforms you may be able to print to a Postscript or PDF file. On Unix-like platforms 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 .mw). 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
and hit Return. This causes the file to be sent to your default printer.
You can print several Postcript files simultaneously by typing, for example,
lp session1.ps session2.ps session3.ps
The last command will print all the files in your current directory that begin with session and end with .ps (so use very carefully).
It is possible to print hardcopies of a worksheet directly, without first creating a Postscript file. 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 or PDF 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, or opening the PDF in an Acrobat reader, or some other PDF viewer.
You should be aware that Postcript files use up relatively large amounts of disk space (PDF files are better); 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 .mw source files, using the "Print" menu. Of course you should keep the source files!) To remove a file named session1.ps from your computer's disk, go into a Terminal window, type
and hit Return. The system may ask you whether you really want to remove the file. If so, type
(for "yes") and hit Return (remember this is a Unix machine, once deleted the files are gone for good, if that scares you use your file browser and trash can which may be safer). 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.
You can also export your worksheets and into several different formats, e.g., HTML, LaTeX (if you know what LaTeX is, you don't need to read this document).
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" or "Maple11->Preferences" 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 Unix-like machines if you just click on the "Print" button, the graph will be saved as a Postscript file named untitled-plot.ps or maybe it will be printed. 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: If 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.
You can also export your graphs and into several different formats, e.g., gif, jpeg, or eps.
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. There may also be context sensitive menus you can access when you mouse over a graph.
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.
Some of this is a bit dated, since now Maple has two modes Document and Worksheet, you can also toggle back and forth using "Text" and "Math", try it.
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 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);|
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 Unix-like machine, on a 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, on a Mac choose Log Out from the Apple menu, and on otehr machines, just figure out what you need to do and do it.
To find out More on Maple.