An Introductory Guide To Maple
An Introductory Guide To Maple
Prepared By Mark H. Holmes Department of Mathematical Sciences Rensselaer Polytechnic Institute Troy, NY 12180
Table of Contents
1. INTRODUCTORY DEMONSTRATION OF MAPLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 EXAMPLE MAPLE SESSION (USING RELEASE 7.00)................................................................... 3 2. TOOLBARS AND PALETTES. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 WORKSHEET TOOLBAR ........................................................................................................ 5 CONTEXT BAR FOR MAPLE INPUT......................................................................................... 6 CONTEXT BAR FOR TEXT REGIONS....................................................................................... 6 PALETTES........................................................................................................................... 7 CONTEXT BAR FOR 2-D PLOTS ............................................................................................. 8 CONTEXT BAR FOR 3-D PLOTS ............................................................................................. 9 3. MAPLE COMMANDS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 OPERATORS (?+)................................................................................................................ 10 CONSTANTS (?PI)............................................................................................................... 10 ELEMENTARY F UNCTIONS (?EXP) ....................................................................................... 10 COMMANDS USEFUL IN CALCULUS I................................................................................... 10 COMMANDS USEFUL IN CALCULUS II.................................................................................. 16 4. EDITING COMMANDS IN A MAPLE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 5. IDIOSYNCRASIES AND FEATURES OF MAPLE. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 6. A COMMON ERROR. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
The next two pages are the Maple session in which the above problem is solved. To include it in this document, which was created using MS Word, a copy of the session was saved using the RTF (Rich Text Format) option listed under the File/Save menu.
Holmes 8/16/01
Session Starts Example Maple Session (using release 7.00) We first enter the expression y = 2*x^2 - 13*x - 24 . Note the way powers and multiplication are expressed here. > y := 2*x^2 - 13*x - 24; Maple has echoed our command. Also, note that in Maple one uses the symbols := to indicate assignment. In this example the name y has been assigned to the polynomial 2*x^2 - 13*x - 24 . Hereafter we can refer to the polynomial simply as y . Let's experiment with y a little before solving the problem. First, we can try evaluating y at x = 0 . This can be accomplished as follows: > x := 0; To find out what value Maple now assigns to y we enter... > y; We get the expected result. However, we are now stuck with x set to zero. To return it to its old unevaluated self, use the following command > x := 'x'; To check that y has returned to the quadratic expression we started with, enter the following command... > y; There is another way to evaluate y which doesn't require us to unevaluate x afterwards. This is the substitution command (subs) and it is: > subs( x = 0 , y); If you ever forget the specifics of a command you can use the on-line help, which is accessed using the ? symbol. To find out about subs we use the following (a semicolon isn't necessary)...
Holmes 8/16/01
> ?subs The Maple response hasn't been given here but you can find out what it is easily enough by simply entering this command. We now return to the original problem of solving the equation. To get an idea of what the solutions are, let's plot y from x = -3 to x = 10 . This is done using the plot command... > plot( y, x=-3..10, title=`Plot of y = 2*x^2 - 13*x - 24`);
Perhaps the most unusual aspect of the plot command is the way the x interval is entered. Also, note we have used back quotes ( ` ` ) around the title of the plot. In the above plot we can see that one root is between -2 and 0 while the other is very near 8 . To find out exactly what they are we use the solve command... > solve( y = 0 , x);
So, Maple has given us answers we expected based on the above plot. Note that in this command we have specified the equation (y = 0) and the variable to solve for (x). Session Ends
Holmes 8/16/01
Insert text at the cursor. Insert a new execution group after the cursor. Remove the section enclosing the selection.
Save the active worksheet. Print the active worksheet. Cut the selection to the clipboard. Copy the selection to the clipboard. Paste the clipboard contents into the current worksheet. Undo the last operation. Redo the previously undone operation. Insert nonexecutable Standard Math in a text region. Toggle the display of nonprinting characters. Restart Maple. Enclose the selection in a section or subsection. Go backward or forward in the hyperlink history. Cancel the computation in progress. Set the zoom magnification to 100, 150, or 200%.
Holmes 8/16/01
Toggle the input display between Standard Math and Maple notation. Toggle the expression type between executable and nonexecutable.
Correct the syntax of the expression. Execute the current expression. Execute the worksheet.
Displays the text style. Change the text style by selecting the text then selecting a text style from this list. Displays text font. Change the text font by selecting the text then selecting a text font from this list. Displays text point size. Change the text point size by selecting the text then selecting a size from this list. Bold the selected text. Italicize the selected text. Underline the selected text. Align the text to the left, center, or right side.
Holmes 8/16/01
Palettes
One very useful feature of Maple is the availability of palettes. These are listed under the View/Palettes menu as shown in the figure below. By clicking on the buttons on the palettes, you can build or edit mathematical expressions without having to remember the Maple command syntax.
Holmes 8/16/01
Displays the plot coordinates of the selected point. Changes the curve style to Line. Changes the curve style to Point.
Changes the curve style to Patch w/o grid. Specifies the type of axes as Boxed, Framed, Normal, or None. Toggles projection between Constrained and Unconstrained.
Holmes 8/16/01
Displays the angle for theta and phi. Change the curve or surface style to Patch. Change the curve or surface style to Patch w/o grid. Change the curve or surface style to Patch and contour Change the curve or surface style to Wireframe.
Change the curve or surface style to Contour. Change the curve or surface style to Hidden line. Change the curve or surface style to Point. Change the axes style to Boxed, Framed, Normal, or None. Toggle the projection between Constrained and Unconstrained.
Holmes 8/16/01
3. Maple Commands
The following pages contain a listing of the Maple commands you will need for calculus (plus a few extras). However, this listing is not intended to replace the manual but only serve as a guideline, and perhaps a quick reference. For more extensive assistance it is recommended that you use the on-line help (see the ? command described below). As a reminder, a semicolon ( ; ) or colon ( : ) must follow every command. Also, anything on a line following the symbol # is ignored by Maple (this is one of the ways comments are added to a Maple session).
Operators (?+)
addition: + subtraction: multiplication: * division: / exponentiation: ^ or ** repetition: $ Example: diff( x^5 , x$3) yields 60 x2
Constants (?Pi)
: Pi : infinity 1 : I
> %;
This gives the previously computed result. Maple remembers the previous three (i.e., you can use % and %% and %%%). f := sin(2); g := 6*%; h := %*%%;
Returns x to a variable (note back quotes are not used here). Arrow notation to define f as a function of x . For help on this use ?-> . f := x > 3*x + 5; f(2); # gives 11 f := 'f'; # unassigns the above definition for f g := (x,y) > x*y^2;
> diff(f,x$n); Finds the nth derivative of f with respect to x . diff(f, x); diff(f, x$3); diff(f,x,x,x); diff(x^3, x); diff(t^3, t$3); f := x > 2*x^3 + 5; diff(f(x), x); # this gives the first derivative f # this gives the third derivative f # this also gives the third derivative f # gives 3 x # gives 6 # gives 6 x2
> Digits := n; Sets the number of digits used for floating point numbers to n ( the default is 10). Note the capital D in this command. > evalf(f); Evaluates the expression f using floating point arithmetic. evalf(1/4 + sqrt(33)/4); evalf(Pi, 20); > expand(f); # gives 1.186140662 # gives 3.1415926535897932385
Expands the expression f using the laws of algebra and trigonometry. expand( ln((x + 2)/x^2) ); expand( (s + 1)*(s + 3) ); # gives ln((x + 2)/x2 ) # gives s2 + 4 s + 3
> factor(f);
11
Holmes 8/16/01
Solves the equation f = a for x . The answer is given in decimal form. Usually fsolve returns a single real root, but for some polynomial and transcendental equations it will find all real roots. # gives 1.000000000, 2.000000000 # gives 3.448217240 # This solves f(x) = a for x1 < x < x2 .
fsolve(x^2 3*x + 2, x); fsolve(r^3 + 4 = 45, r); fsolve(f = a, x, x1..x2); > int(f, x);
Finds the indefinite integral of f with respect to x . The arbitrary constant of integration is not included in the answer. int(x^2, x); # gives 1/3 x3
Finds the definite integral of f from a to b . When this command is followed by evalf(%) the integral is evaluated numerically. # gives 8/3 # gives 1/2 erf(1) 1/2 # gives .7468241330
Plots rectangular boxes used to approximate the definite integral of f over a < x < b. Height of each box is determined by value of f at left end of each subinterval; n specifies the number of boxes.
with(student): leftbox(sin(x),x=0..Pi/2,10); > leftsum(f, x = a..b, n); Finds the approximation of definite integral of f over a < x < b when leftboxes are used; n specifies number of boxes).
# gives .9194031700
Finds the limit of f as x a . On some expressions it is best to use the expand command first before using limit. # gives 1 # gives # gives
12
Holmes 8/16/01
Plots rectangular boxes used to approximate definite integral of f over a < x < b . Height of each box determined by value of the function in middle of each subinterval; n specifies the number of boxes.
with(student): middlebox(sin(x), x = 0..Pi/2, 10); > middlesum(f, x = a..b, n); Finds approximation of definite integral of f over a < x < b using middleboxes; n specifies the number of boxes (or subintervals). with(student): middlesum(sin(x), x = 0..Pi/2, 10); evalf(%); # gives 1.001028825 > plot(f, x = x1..x2, title = `Example`); Plots the graph of f for x1 < x < x2 . Note the backquotes around the plot title.
plot(cos(x), x = 0..Pi); # this plots y = cos(x) for 0 < x < plot(cos(x), x = Pi..Pi, title=`y=cos(x)`, color=YELLOW); # this plots y = cos(x) for < x < plot(f,x=2..4,0..1, title=`y=f(x)`); # this restricts the plot to 2 < x < 4, 0 < y < 1 > plot({f, g}, x = x1..x2, title=`TEST` ); This is used for plotting 2 (or more) graphs on the same axes. # this plots y = x2 and y = sin(x) # for 0 < x < , 1 < y < 3
plot([sin(t),cos(t),t= Pi..Pi], title = `A Circle`); plot([f, g, t = 0..1], 2..3); # this restricts 2 < x < 3 plot([f, g, t = 0..1], 2..3, 0..5); # now 2 < x < 3, 0 < y < 5 plot([r, t, t = 0..1],coords=polar); # plots the polar equation r = r(t) plot({[f,g,t=0..1], [F,G,t=1..3]}, title=`A Couple of Curves`); # this plots two parametric curves > plot(L, x = x1..x2, title=`TEST` ); The plot command can also be used to plot point plots.
L1 := [[0,0],[1,1],[2,1],[2,0],[1,-1],[0,0]]; plot(L1, x=0..2, style=point); L2 := [[ n, sin(n)] $n=1..10]; plot(L2, x=0..15, style=line, symbol=circle); 13 Holmes 8/16/01
> quit
Quit Maple. If this doesn't work try the combination ;;;quit . Plots rectangular boxes used to approximate the definite integral of f over a < x < b . Height of each box determined by the value the function at the right side of each subinterval; n specifies the number of boxes.
with(student): rightbox(sin(x), x = 0..Pi/2, 10); > rightsum(f, x = a..b, n); Finds the approximation of the definite integral of f over a < x < b when rightboxes are used; n specifies the number of boxes.
# gives 1.076482803
> simplify(f); Simplifies the expression f . On some expressions it is best to first use the expand command before using simplify. simplify(16^(1/2) + 6); > simpson(f, x = a..b, n); # gives 10
Finds approximation of the definite integral of f over a < x < b using Simpson's rule; n specifies number of subintervals (it must be even).
# gives 1.000003392
This solves f(x) = a for x . This command produces exact solutions, if available, while fsolve produces numerical answers.
solve(sin(x) + y = 2, x); # gives arcsin(y 2) solve(x^2 + 2*x*y = 1, x); # gives y + (y+ 1) 1/2 , y (y+ 1)1/2 sol := solve(x^2 9 = 0, x); sol[1]; # gives 3 sol[2]; # gives 3 solve({x + y = 1, 2*x + y = 3}, {x,y}); # gives {y = 1, x = 2}
14
Holmes 8/16/01
Substitutes x0 for x in the expression f . Note that x0 can be either a numerical value or an algebraic expression. It is not necessary to use x:='x' after this command. # gives y6 + 9 y3 # gives 1 + cos(Pi)
subs(x = y^3, x^2 + 9*x); subs(x = 0, y = 1, z = Pi, x + y + cos(z)); > sum(f, i = m..n);
Finds the approximation of the definite integral of f over a < x < b using trapezoidal rule; n specifies the number of subintervals.
# gives .9979429868
15
Holmes 8/16/01
Converts a vector v to a list that can then be used in plot3d. Converts x from radians to degrees. # gives 180 degrees
v1 := vector([1, 2, 3]); v2 := vector([2, 3, 4]); crossprod(v1, v2); # gives [ 1, 2, 1 ] > display({F, G}); Command used to display multiple plots on the same axes.
with(plots): C := plot3d([ cos(t), sin(t), t ], t = 0..Pi, s=0..1, grid = [35, 2]): P := plot3d([x, y, x + Pi/2], x = 1..1,y = 0..2): S := plot3d( sin(x + y), x = 0..2, y = 1 .. 1): display( {C, P, S}, title = `A Curve and a Couple of Surfaces` ); > dotprod(v, w); Calculates the dot product of the vectors v and w .
# gives 1 + 2 y # gives a + 2 b
> evalm(a*v + b*w); Calculates av + bw where a,b are scalars and v,w are vectors. v:=vector([ 1, x, y ]); w:=vector( [1, 0, 2] ); u:=vector( [1, 0, q] ); evalm(2*v 3*w); # gives [ 1, 2 x, 2 y 6 ] evalm(v + w u/2); # gives [ 5/2, x, y + 2 1/2 q ]
Command with(linalg): must appear somewhere in the Maple session before this command is used.
16
Holmes 8/16/01
> mtaylor(f, [x, y], n); Computes the multivariate Taylor series of f to order n 1, in the variables x and y . readlib(mtaylor): mtaylor(sin(x + y), [x, y], 2);
# gives x + y
> norm(v, 2); Calculates the length of the vector v . v := vector( [1, 2, 3] ); norm( v, 2 );
# gives 141/2
> plot3d(f, x = a..b, y = c..d); Plots z = f(x, y) for a < x < b and c < y < d . You can modify and print the plot using menus on the plot window. plot3d( sin(x + y ), x = 1..1, y = 1..1 ); plot3d( [ r*sin(s), cos(s), r + s ], r = 0..1, s = Pi..Pi ); # The above is used when the surface is described parametrically. plot3d( cos(x + y), x = 12..12, y = 12..12, grid = [35, 35], orientation = [85, 30], axes = BOXED, title = `Example`); plot3d( [t*s, exp(s), s], t = 2..1, s= 0..3, view = [1..1, 0..3, 1..2] ); > taylor(f, x = a, n); Computes the Taylor series, up to degree n 1, of f with respect to x about the point x = a . The defaults are a =0 and n = 6 . taylor(sin(x) , x ); taylor( exp(x) , x , 4 ); taylor( ln(x) , x = 1 , 3 ); > vector([x1, , xn]); # gives x 1/6 x3 + 1/120 x5 + O(x6 ) # gives 1 +x + 1/2 x2 + 1/6 x3 + O(x4 ) # gives x 1 1/2 (x 1)2 + O((x 1)3 )
# gives 4
Command with(linalg): must appear somewhere in the Maple session before this command is used.
17
Holmes 8/16/01
18
Holmes 8/16/01
you can increase the value of Digits, although you should be aware that this can increase the computing time. You may now be wondering how you will be able to tell if you should be worrying about roundoff error. Well, there is no way to answer this that will cover all situations but if you are suspicious of the accuracy of the answer just increase the value of Digits to see if the answer is affected. For example, suppose you get an answer like 1 + 0.2x 10I . If you think the answer should be real valued then you would be suspicious of this result. You might also be suspicious because Maple normally keeps 10 digits and this answer says the solution is complex but it is the eleventh digit where the I appears. In either case it would be worth increasing Digits to see what happens to the result. One other thing, if you believe roundoff may be a problem try entering the numbers as fractions rather than in decimal form (e.g., use 13/10 instead of 1.3). This is because in certain situations fractions are treated differently than numbers in decimal form. := vs > In Maple you can enter f(x) = x2 as f := x^2 or as f := x > x^2 . The first is called an expression and the second a "function". Note that if you use the expression form then you refer to the formula using just f whereas for the "function" form you must refer to it as f(x) . To illustrate the differences we have the following: Definition: Evaluate at x = 2: Differentiate: Integrate: f := x^3 + 1; subs(x = 2, f); diff( f , x); int( f , x = 0..1); f := x > x^3 + 1; f(2); diff( f(x) , x); int( f(x) , x = 0..1);
; vs : If you want Maple to display the response then use a semicolon (;) after the command. If you don't want to see the response (e.g., maybe it is so long that it is unintelligible to a human) then use a colon (:) after the command. Back Quotes vs Quotes Back quotes ( ` ) are used to identify text to go into a command, such as the title for a plot (e.g., title = `Plot`). Quotes ( ' ) are used, among other things, to return a variable to unevaluated status and to undefine a "function" (e.g., x := 'x' ). sqrt() One source of potential trouble is the square root function. To illustrate, if you enter the expression sqrt(f^2) then Maple will return f . This is OK but what if f is negative and you expect sqrt(f^2) to be positive? For example, Maple states that sqrt(sin(x)^2) = sin(x) . This is positive if sin(x) is positive and negative if sin(x) is negative. A simple way to make sure the result is nonnegative is to use something like abs(sqrt(f^2)) . However, it is recommended that you do not do this unless absolutely necessary. The reason is that integration formulas and solutions for equations are limited if the abs() function is present.
19
Holmes 8/16/01
I, Pi, O, etc Like any good computing system, Maple has a certain collection of well used mathematical constants and functions available. These have special symbols and you cannot use them for other tasks. So, for example, Maple reserves I to represent the square root of -1 and Pi for . You can get a listing of these special symbols by using the help commands ?I or ?Pi .
6. A Common Error
It is inevitable that you will occasionally have trouble getting your ideas across to Maple and this can quickly lead to a very frustrating situation. It is impossible to anticipate every possibility but there is one that is quite common. It occurs when a variable has already been assigned and you try to use it again in another context. To illustrate this, consider the following short Maple session... > f := x^3 + 1; f := x 3 + 1 > x := 1; x := 1 > plot(f, x = 0..1); Error, (in plot) invalid arguments > g := x^2 1; g := 0 The assignment x := 1 appearing in this session has a profound effect on the last two commands. From the plot command we get an error message (which is good). Similarly, in the last command, g is not a quadratic but simply a constant. If this is what was desired then fine. However, if you expected to see a cubic in the plot and a quadratic for g then x has to be unassigned its earlier value. This is accomplished by issuing the command (before the plot command): > x := 'x'; If you are not sure whether or not you have assigned a value to a variable you can always check. For example, for the variable x you issue the command: > x; If the reply is just x: = x then it is unassigned. This simple test will work unless x has been defined earlier to be a vector or an array. In this case you use the command: > print(x); This also works to find out if x has been given a numerical value (such as 6). 20 Holmes 8/16/01