Instructions for Use of Maple in Mathematics 244

The computer program Maple is a powerful tool which can help you solve a wide range of mathematical problems: it can differentiate, integrate, and otherwise manipulate mathematical formulas, perform arithmetic calculations, plot curves and surfaces in two and three dimensions, solve differential equations, and carry out a variety of other useful mathematical operations. At Rutgers, Maple is available on the student computer eden. The instructions in this handout are for a special version of Maple, called xmaple, which is customized to run under the X-windows system. This means that they apply when you are working on an x-terminal connected to eden. Maple is also available on the Windows PCs and Macintoshes in the public labs. Although the commands you use to do mathematics with Maple will be the same on all these machines, there are differences among computers, such as in the way that files are opened, saved, and printed.

Table of Contents

Getting started:

From an x-terminal in one of the public labs (e.g., in ARC) you should log in to eden, then start Maple by typing the command xmaple & (note that ``xmaple'' is in lower case; typing the & allows you to continue using your xterm window for other purposes while Maple is running). A Maple window will open. At the top of the Maple window is the Menu Bar, consisting of a row of menu buttons ( File, Edit etc.). Underneath the row of menu buttons is the Tool Bar, most of which are shortcuts to menu commands. Directly below the Tool Bar is the Context Bar, which consists of more buttons which are shortcuts to menu commands. If you place the mouse pointer on any of these buttons and hold down the left mouse button, a rough idea of what the button does will appear at the bottom of your Maple window. Finally, below the Context Bar is a window with the label Untitled (1). You can now give an instruction to Maple by placing the mouse pointer in this window (just to the right of the prompt >), typing a Maple command, and then typing a carriage return. Maple carries out the command and prints a response. For example, if you type 1 + 1;, Maple will respond with 2. Note that you must type a semicolon after each Maple command, to indicate that you have finished entering the command.

Since you will not be given a Maple manual, you should learn to use Maple by using the built in Help facility. To get help on a particular topic, such as the plot command, type, after the prompt >, the command ?plot;. A window will open describing the basic structure of the command and giving examples of its use. To close this window when you have finished with it, click the left mouse button on the rectangle in the upper left corner of the window and then drag the mouse pointer down, releasing the button when Close is highlighted. Another way to invoke Help is to place the mouse pointer on the word Help at the far right of the Menu Bar, click the left mouse button, and drag the mouse pointer down, releasing the button when the desired item (such as Topic Search) is highlighted. We shall refer to this process as choosing Topic Search from the Help menu. Fill in the Topic box, click the left mouse button on the item that you want, and then click on OK.

To continue, you will need to know some basic commands and syntax of Maple.

Return to the Table of Contents


The operations addition, subtraction, multiplication, division, and exponentiation are indicated by +, -, *, /, ^ respectively. All grouping of expressions is done with the left and right parentheses ( and ). The product xy must be written x*y, not xy or x y; if you type xy, Maple assumes you are referring to a variable called ``xy''. Thus, to enter the expression
(2 x +y 2)/(2 x + e x) +1 into Maple, you type:

(2*x +y^2)/(2*x + exp(x)) + 1;

Note that the exponential function is built into Maple and is referred to as exp. Similarly, Maple knows the functions log, sin, cos, tan, and many more standard functions.

When operating on integers, Maple does exact arithmetic, rather than using decimal approximations. To get a decimal approximation, use the Maple command evalf. The Maple command evalf(4/7,20); produces a 20 digit approximation to 4/7. Typing only evalf(4/7); will produce a 10 digit approximation--as will typing 4.0/7.0;.

Return to the Table of Contents


To help you do algebraic manipulations, Maple has the commands expand, factor, and simplify, which you can learn about by using the Help facility. You can also solve algebraic equations by using the commands solve and fsolve.

Return to the Table of Contents

User-defined Functions and Expressions:

In Maple, x^2 - 2*x +3 is an expression. You can assign a name to this expression for future use by typing g:= x^2 - 2*x +3;. Expressions can contain several variables, as in h:= y*t - sin(y). To evaluate an expression at a particular value, use the Maple command subs. For example, subs(x=2,g); will produce the value 3. Maple also has a construct called a function, with the syntax f:=x -> x^2 - 2*x +3;. We will use these only occasionally.

Return to the Table of Contents


The basic plotting command in Maple is plot. This command has many forms--for example, several functions can be plotted at once--so you should look carefully at the examples given at the end of its Help page to get some idea of its flexibility. There are many other plotting commands in Maple; in Math 251 we used plot3d and implicitplot and in this course we will use dfieldplot, odeplot, and DEplot (see the section on Differential Equations for a description of these commands). Before using the plot3d and implicitplot commands, as well as some other plotting commands, you must first issue the command with(plots): To use the commands for solving and plotting solutions to differential equations, you must first issue the command with(DEtools): It is frequently useful to enlarge the size of a plot. To do this, place the mouse pointer in the region occupied by the plot and click the left mouse button. This places a box around the plot and changes the Menu Bar and Control Bar so that new options are offered to manipulate the plot. The plot is resized by placing the mouse pointer at one of the small dots along the edge of the box and dragging the pointer. To enter additional commands, move the mouse down to the next prompt > and click the left mouse button. When viewing three dimensional plots, it is useful to view the plot from different viewpoints. First, place a box around the plot by moving the mouse pointer in the region occupied by the plot and clicking the left mouse button. Now, place the mouse pointer inside the box and while holding down the left mouse button, move the mouse pointer to different positions. A cube will appear which rotates as the mouse pointer moves. When you are at the desired viewpoint, hold down the right mouse button and choose Redraw. Explore the effects of using the Axes and other commands on the Menu Bar. (Note that each time a change is made, you must also use Redraw.)

Return to the Table of Contents

Differentiation and Integration:

In addition to performing basic calculations and evaluating standard functions, Maple can also differentiate and integrate functions. The diff command differentiates expressions. For example, diff(x*sin(x), x); differentiates x sin(x) with respect to x, and either diff(x*sin(x), x, x); or diff(x*sin(x),x$2); gives the second derivative. If you have typed g:=x^2*y;, then diff(g,x); is the first partial derivative of x2 y with respect to x and diff(g,x,y); is the mixed second partial derivative.

The command for both definite and indefinite integration is int. If Maple cannot evaluate a definite integral exactly, numerical integration may be used. Type ?int and ?int[numerical] for details on integration in Maple.

Return to the Table of Contents

Differential Equations:

Maple has a special set of commands to deal with differential equations. To access these, you must first type with(DEtools): Maple can obtain exact solutions of some differential equations and can obtain numerical solutions in cases in which it can not find an exact solution. The basic command for this is dsolve. There are four types of solutions this command can be used to find: exact, series, lapace and numerical . To plot the direction field of a single first order differential equation or a system of two autonomous first order equations, the commands dfieldplot or DEplot may be used. The standard plot command is used to graph exact solutions of differential equations found by the dsolve command. To plot the numerical solutions found by dsolve, the command odeplot may be used. Another alternative which directly plots numerical solutions to differential equations is the DEplot command. However, this command only gives a graph of the solution. It cannot be used to give the value of a numerical solution at a particular point.

Consider the differential equation d2y/dx2-y=x3. To describe this equation in Maple, we need to communicate that the unknown solution y is a function of x, and to describe the relevant derivatives of y with respect to x. To communicate to Maple that y is the dependent variable and x is the independent variable, we write y(x) instead of y when referring to this variable. Since the first derivative is diff(y(x),x)}, the second diff(y(x),x$2), etc., the differential equation d2y/dx2-y=x3 should be expressed to Maple as diff(y(x),x$2) -y(x)=x^3 . Notice that Maple echoes it back in symbolic form. To use this equation later we give it a name by typing de:=diff(y(x),x$2) -y(x)=x^3; so that the symbol de will refer to this equation. We can use the commands rhs and lhs to refer to the right or left side of the differential equation. To place other conditions on y(x), we group additional equations together with de inside braces. For example, the initial value problem d2y/dx2-y=x3, y(0)=1, y'(0)=2 can be described to Maple via ivp:={de,y(0)=1,D(y)(0)=2}; . Note the use of D as another notation for differentiation. Any conditions on higher derivatives at a point are described via the D notation as well, for example D(D(y))(0)=3.

Once a differential equation has been described to Maple, Maple can attempt to find its general solution, particular solutions, or to plot solutions. We briefly describe the relevant functions here. Find more about a function by typing ?functionname. For example ?dsolve will tell you all about the Maple function dsolve.

Brief summary of relevant Maple commands for Differential Equations

dfieldplot produces a plot of the direction field of a single first order differential equation or a system of two first order autonomous differential equations.

dsolve(de,y(x)); or dsolve(ivp,y(x)); In these basic forms, dsolve will attempt to solve the differential equation or the initial value problem for y(x) described in ivp, returning a formula for y(x) if possible. In the first form, arbitrary constants _C1, etc. will be used to express a general solution.

soln:= dsolve(ivp,y(x),numeric); In this form dsolve finds an approximate solution to the initial value problem described in ivp. The output soln is a Maple procedure. To get the value of this approximate solution at a particular point, e.g., x=2.5, type soln(2.5);. Because the solution is returned as a Maple procedure which produces output of the form [x= 2.5, y(x) = 6.437], the plot command cannot be used directly to graph the approximate solution. Instead, use the odeplot command. Sometimes it is useful to convert the approximate solution from the form of a Maple procedure into a standard function that just returns the y-value. This can be done by typing yapprox:= u-> subs(soln(u), y(x));. A graph of the approximate solution over the interval 0 < x < 5 can then be obtained by typing plot(yapprox, x=0..5);.

odeplot is used to plot numerical solutions of differential equation obtained from using the numeric option of dsolve.

DEplot may be used to plot numerical solutions of differential equations with a set of initial conditions. In the case of a single first order equation or a system of two first order autonomous equations, it can also be used to plot the direction field of the equation, with or without solution curves. In fact, the default option is to also produce the direction field; to suppress the direction field, one must add the option arrows = NONE. For computing the numerical solution at a particular point, the numeric option of dsolve should be used. The default numerical method used by the DEplot command is the classical fourth order Runge-Kutta method with a fixed step size. For some problems, the default step size may be too large to produce an accurate solution. This may be corrected by using the stepsize option. In general, the default method used by DEplot is a poor choice of method, so it is better to use the command with the option method=rkf45, which is the default method for the numeric option of the dsolve command.

Examples of use of Maple commands for Differential Equations

with(plots): with(DEtools):
de1:= diff(y(x),x) = - y(x) + 1/(1 + exp(x));
dfieldplot(de1,y(x), x=-1..5,y= -6..4);
DEplot(de1, y(x), x=-1..5, initval,y=-6..4);

Linear Algebra: To use Maple's linear algebra commands, you first enter with(linalg): To see a list of commands in this package, type with(linalg);, i.e., use a semicolon instead of a colon. In this course, we will only use a few of Maple's linear algebra commands: matadd to add two matrices, multiply to multiply a matrix times a vector, linsolve to solve the linear system of equations A x = b, det to find the determinant of a matrix, and eigenvects to find the eigenvalues and eigenvectors of a matrix.

Return to the Table of Contents

Maple Worksheets:

The window which appears when you start Maple is called a Maple worksheet. To complete each computer assignment in Mathematics 251 you are asked to turn in an edited printout of your work; such a printout can be obtained by editing, and then printing, your worksheet. The printout should include only the numerical, symbolic, and graphical output of Maple which is appropriate for the solution of the problems assigned, plus text material in which labels are provided for graphical output and explanations added. Maple includes various editing capabilities which should enable you to produce neat and coherent output, and which we now describe.

To remove an unwanted portion of your Maple worksheet (e.g., a region containing commands that you typed incorrectly or that were not directly relevant to the solution of the exercises), select the region to be deleted by clicking the left mouse button at the beginning, then dragging the mouse across to the end of the portion of the worksheet you wish to delete. The region should now be highlighted. Then choose Cut from the Edit menu. To copy a region to a new location, select the region as above, but now choose Copy from the Edit menu. Then click the left mouse button in the position in which you wish to insert your selected region and choose Paste from the Edit menu.

To insert text, such as a label for a plot, into your worksheet, click the mouse at the beginning or end of the plot and choose Text Input from the Insert menu. Now type your label. To continue using your worksheet, move the mouse pointer down to the next prompt > and click the left mouse button. If there is no prompt, insert one by clicking on the prompt symbol > in the Tool Bar Menu.

Sometimes it is useful to be able to place a comment after a Maple command, rather than insert text elsewhere in the worksheet. To do this, enter the sharp symbol #. Everything typed on a line following this symbol will be considered by Maple to be a comment, and therefore not executed.

To make your worksheet less cluttered, it is a good idea to have Maple suppress the output of various commands, e.g., the command with(plots) or a command given to assign a name to a plot. To do this, end the command with a colon (:), instead of a semicolon (;).

Return to the Table of Contents

Printing your Maple Worksheet:

To print your Maple worksheet, choose Print from the File menu or click on the print button in the Tool Bar (this is the fourth button from the left). A panel will appear with the options ``Output to File'' and ``Print Command'' at the top. Clicking on ``Print Command'' directs your output to the printer, while clicking on ``Output to File'' places your output in a file, whose name is given in the adjacent box (the default is If you wish to change this name, click in the box and type in a new name. Since the file will be a postscript file, the file name should have the form When you have finished making your choices, click on the ``Print'' button.

Return to the Table of Contents

Saving your Maple Worksheet:

If your work is interrupted, you can save your work so that you can later resume where you left off. To save your Maple worksheet, choose Save As from the File menu. Then type the name of the file in which you wish to save your worksheet in the Selection box where the mouse pointer is. (First delete the asterisk.) The file name should have the form something.mws. After you have typed the filename, click on ``OK'' to save the file. Once you have named the worksheet and saved it in a file, you can save further changes by choosing Save from the File menu. Maple automatically keeps track of the filename.

Return to the Table of Contents

Opening a Previously Saved Worksheet:

To open a previously saved worksheet, choose Open from the File Menu. Click on the name of the file you wish to open and then click on OK. If you wish to close one of your open worksheets, make it active by clicking in it, and then select Close from the File menu. Maple will prompt you to save the worksheet if you have changed it since the last save.

Return to the Table of Contents

Ending your Maple Session:

To end your Maple session, choose Exit from the File menu. A box will open, reminding you that all unsaved work will be discarded. If you have saved what you need or wish to exit anyway, click on ``Exit.''

Return to the Table of Contents

Obtaining Copies of the Labs in Worksheet Form:

In some of the labs, you will be asked to simply execute a string of Maple commands to learn what they do. To avoid retyping these commands, you can first obtain a modified copy of the lab in worksheet form. This modified copy will omit instructions and problems and contain only strings of Maple commands you are asked to execute. Once you obtain this file, you can access it by following the instructions in the section Opening a Previously Saved Worksheet: To obtain the file lab0.mws, for example, login to eden, and before starting up Maple, type cp /eden/u8/falk/math251/lab0.mws lab0.mws If you look at the files in your home directory (by typing ls), you should see the file lab0.mws. Now start up Maple and open the file lab0.mws .

Return to the Table of Contents

Useful Commands and Techniques:

If Maple gets hung up in a calculation or is taking too long, click the mouse on the stop button in the Tool Bar menu (fifth button from the right).

Any Maple command previously entered in your worksheet can be re-executed without retyping it in a new location. Simply move the mouse to the position of the command you wish to execute and hit the Return key.

It is often useful to be able to refer later to the result of a computation--the output of some command--in a simple way. To make this possible, simply assign the output of the command to a variable. For example, if you enter a:= evalf(2*Pi); then you can later square the result of evalf(2*Pi); by typing a*a;.

You can assign a name to a plot just as described above for assigning a name to an expression. Several previously named plots can then be displayed on the same graph by using the command display. Type ?plots[display] for details.

If you assign the name a as above and then continue your Maple session, you may want to reassign the name a to another expression. To do so, first unassign a by typing a:='a';. To clear all the assigned variables in a Maple session, type restart;. One common problem is to try to use such a variable without unassigning it, forgetting that is has already been assigned a value. A simple way to avoid this is to issue the restart command before beginning a new problem. This will not change anything on your screen.

Return to the Table of Contents

Getting Help From Other Students:

The purpose of the Maple assignments is partly to learn about Maple, a very useful program for symbolic, numerical, and graphical computations, and partly to help you understand the material in the course. Just as with other homework assignments, it is permissible and helpful to discuss the Maple labs with other students. However, the Maple labs you are turning in are being graded and will be part of your final course grade. It is therefore expected that the work you hand in is your own in the sense that you have personally input everything that appears on your Maple worksheet, using notation that you have determined, in a style and layout that is your own, and with text comments that reflect the way you finally understand what is being asked. In light of the above, it seems highly unlikely that any two students would turn in nearly identical assignments, and if such an event occurs, the students involved would be considered in violation of the policy on academic integrity and subject to university sanctions.

Return to the Table of Contents

Last modified January 6, 1999 by Richard S. Falk,