Maple on Athena (AC-72)
> commands-typed-here response-printed-hereMost of these extra lines were removed to reduce size and improve overall readability of this document.
athena% add mapleThe add command attaches the maple locker to the directory /mit/maple and appropriately modifies your environment -- in particular, it adjusts both your program search path (PATH) and your manual-page search path (MANPATH) variables to let you run maple and access the Maple man pages.
To run maple, just type the following command:
athena% maple
or if you are on an X Windows machine and still want to use ttymode:
athena% maple.tty
In X Windows, you can work with many different worksheets. This allows you to have many separate calculations going on at one time. (When you change the value of a variable in one worksheet, however, its value changes in all of the worksheets.) Worksheets can be created and saved just as tty sessions can; for more information on this, see Restoring, Saving, and Ending Sessions.
If you are running an X-windows session, then a few moments after you enter the command maple, a new window will appear with Maple running in it.
If you are accessing Maple on a plain-text format (e.g., over dialup), you will just see a startup message and prompt similar to this:
|\^/| Maple 6 (SUN SPARC SOLARIS)
._|\| |/|_. Copyright (c) 2000 by Waterloo Maple Inc.
\ MAPLE / All rights reserved. Maple is a registered trademark of
<____ ____> Waterloo Maple Inc.
| Type ? for help.
>
Unlike in X Windows, you do not work with worksheets in the tty environment.
There are several to invoke help on Maple. In X, the help button is on the right. From the command line, the simpler and recommended way is to preface a topic with a question mark. To get help on the help system itself, type either of these commands:
> ? > ?helpTo get an index of topics, just type:
> ?indexTo get a quick overview of maple, try:
> ?introFor help on a specific function, you can use the help function call. Your query must conform to Maple's statement syntax, which will be explained later in this document. As an example, to get the help on help:
> help(`help`);
A Maple user's group exists which corresponds by electronic mail. To subscribe, send mail to majordomo@daisy.waterloo.ca with the subject subscribe maple-list. If you are unfamiliar with electronic mail before on Athena, it is explained in the document Electronic Mail on Athena. This document is available online in the Athena On-Line Help System (OLH). It is also available in hardcopy form at MIT Copy Tech
There also exists a Usenet newsgroup devoted to symbolic algebra and various mathematical software packages. The newsgroup name is sci.math.symbolic.
If you have not read netnews before, you may want to read the document Netnews on Athena. Like the mail document, this document is available both online on OLH and in hardcopy form from MIT Copy Tech.
>For Maple to understand what you type, your commands must conform to Maple's expectations for statements. In particular, your statement must be terminated by a semicolon (;) or a colon (:) for Maple to realize that you have completed it. The semicolon tells Maple to print out the result of evaluating the statement, while the colon tells it not to print the result. The terminator does not need to be typed on the same line as the rest of the statement, so if you forget it on one line you can type it on the next line. For example:
> 4+5:is a statement to add 4 and 5 but not to print the result. An equivalent statement is:
> 4+5 > :In this case, after the first line Maple will assume that you have not finished your statement. On seeing the colon on the next line, Maple will realize the statement is finished and evaluate 4+5. If you are using X Windows, it will give you the statement "Warning, premature end of input". You can avoid this by typing Shift-Return instead of Return.
You can put more than one statement on a line, just as you can break a statement across multiple lines. The requirement is that statements be terminated, not that they fit on a line.
There are two Maple statements that do not have to be terminated in this way:
> 4+5; > quit 9 > 4+5; quit 9 > 4+5; quit; 9
The first example produces a syntax error; the second example actually works, but prints out the error message noted:
> 4+5: ?help
syntax error:
4+5:?help
^
>
> 4+
> ?help
[a help window appears]
Error, invalid types in sum
>
When using Maple in tty mode, you can access your history, or previous commands, by using the up arrow. This is accomplished in X with the cursor keys; however, you must enter all of the lines for recalculation. Previous versions of Maple used " to redisplay the previous result; the current version uses %.
Maple has a number of pre-defined global variables. When you choose names for your own variables, you should avoid the predefined ones. They are there to help you control how Maple works. This is discussed further in the section on Some Predefined Symbols.
> 4+5;#This is an example of a commentgives the output:
9Since a comment is not a statement, it does not need to be terminated. It only causes the remaining input on the line to be ignored.
It is possible to control how much information is echoed in Maple. The echo level can be set with the interface function. An echo level of four causes comments and statements to be echoed. For more information on how to control various user-interface settings, type:
> ?interface
> 4+2*3; 10because 2*3 is evaluated before the addition. Other useful operators are:
> 2/3; 2/3 > 2.0/3.0; .6666666667This gives you the flexibility to choose between approximate or exact answers to many mathematical questions.
> x := 2 + 5; x := 7 > x; 7The programming variable x now is a label for the result of 2+5.
To clear a variable, you can type:
> unassign('x');
> x;
x
or:
> x := 'x'; > x; x
The other kind of Maple variable is a mathematical variable or an unassigned variable. These exist in the sense of algebraic unknowns, as in the case of:
> z := 2+y; z := 2 + yHere, y is a mathematical variable, and z is a programming variable because an expression has been assigned to it. If we now assign a value to y, y becomes a programming variable, and is no longer an algebraic unknown:
> y := 5; y := 5 > z; 7An equation is different from an assignment statement. Consider the difference between:
> a := 2; a := 2; > b = 2; b = 2In the first case we are assigning the value 2 to the variable a. In the second case, we are making the assertion that b is in fact already equal to 2. We can evaluate this assertion using the evalb function (evalb is used to evaluate a Boolean expression; eval is used to evaluate a general expression):
> # First, see what the value of b is: > b; b > # So b is a mathematical variable. Try the evaluation: > evalb(b=2); false > # Now assign the value 2 to b: > b := 2; b := 2 > b; 2 > # So b is now a programming variable. Evaluate the assertion again: > evalb(b=2); true > # Now assign the assertion to a (which replaces the old contents of a): > a := b = 2; a := 2 = 2 > evalb(a); trueThe last part of the example shows that you can assign an expression to a variable. Maple statements are built of zero or more expressions of various types connected in various ways. Thus b=2, and abs(4) are both expressions, while evalb(b=2) is a composite expression built from evalb(...) and b=2. Finally, evalb(b=2) and (c = 3); is a statement, because it is built from (boolean) expressions and is terminated.
Double quotes are used to construct strings, as in:
> a := "This is a string"; a := "This is a string" > a; This is a string
Single quotes are used to delay evaluation, as in:
> a := 1; x := 'a' + b; a := 1 x := a + b
Backquotes are used to form symbols or names:
> `This is a name!` := 1; This is a name! := 1In the previous section, a mathematical variable was also described as an unassigned variable. Unassigned variables have their own name as their value. This is the default condition for a variable until you assign it a value. To turn an assigned variable (i.e., a programming variable) back into an unassigned variable (i.e., a mathematical variable), you must assign it its own name. As an example:
> # r hasn't been used, so its an unassigned variable: > r; r > # Now make r an assigned variable: > r := 2; r := 2 > r; 2 > # Now try to give r its own name: > r := r; r := 2 > # That didn't work, because the r on the right side of the > # assignment statement was evaluated prior to the assignment. > # Assign the name of the variable by delaying evaluation: > r := 'r'; r := r > r; r > # r is now a mathematical variable once more.This shows the function of the apostrophe (right-quote). It delays evaluation of an expression.
Maple generally performs what is called "full evaluation". You have seen an example of this already. Here it is again:
> z := 2+y; z := 2 + y > y := 5; y := 5 > z; 7Once "y" had been assigned a value, you didn't have to do anything to tell Maple that "z" could be completely evaluated to a number instead of an algebraic expression. Every time Maple evaluates a statement, it checks to see if it knows any other expressions that could be re-evaluated in light of the new information. An exception to automatic full evaluation is in procedures, which is discussed later.
> a := -2; a := -2 > abs(a); 2 > a; -2The result of taking the absolute value of "a" is returned as the result of the function abs(...). The variable "a" itself is not modified as a side effect. If you wanted to change the value of the variable, you would use:
> a := abs(a); a := 2Functions are a special case of procedures. Later in this document you will learn how to construct your own functions and procedures.
Integers are expressed as a string of one or more digits with an optional sign, like "-2" or "3870". Rational numbers are a signed ratio of unsigned integers, like "2/3" or "-8/30", and will be simplified by Maple:
> -8/30; -4/15Floating point numbers contain an explicit decimal point, and any integer or rational expression that contains such a decimal point will be evaluated as floating point:
> 2/3; 2/3 > 2.0/3.0; .6666666667Maple has a global variable named "Digits" that you use to control the accuracy of floating-point operations. The initial setting for Digits is 10 but you can change it by assigning it some other value:
> Digits:=5; Digits := 5 > 2.0/3.0; .66667 > Digits:=10; Digits := 10 > %%; .66667 > 2.0/3.0; .6666666667Notice that the value of Digits does not control the display of floating point values, it controls their calculation. If you calculate something with one value for Digits, then change Digits to a new value, then only future floating-point operations will reflect the change.
You can perform conversions between various Maple datatypes. For example:
> convert (2/3, float); .6666666667
See ?convert for more information on the convert command.
Another way is to force evaluation of expressions in the type you want. For example to convert a rational expression to floating point, you could use the evalf function:
> evalf(2/3); .6666666667 > evalf(2/3, 5); .66667As you can see, evalf also provides a way to temporarily control the accuracy of floating-point calculations. See ?eval for information on other Maple evaluation functions.
An example of a package is linalg, the Maple linear algebra package. To use a package, you initially read it into memory using the with command:
> with(linalg): Warning, the protected names norm and trace have been redefined and unprotected(If you terminate the line with a semicolon instead of a colon it will also give a bracketed list of functions.) When Maple loads a package, it checks to see whether any of the new function names will replace an existing function. If so, it gives you a warning. For instance, since linalg has a function to compute the trace of a matrix that is called "trace", which is the same name as the debugging command "trace", a warning was generated. The new function is available for use, but the previous function of the same name is no longer accessible. (To get it back you can always use "restart" but this will clear all of your variables as well.)
There is a way to avoid this problem if you want access to both functions. The technique will allow you to use a single function of a package without loading the entire package into memory. To specify the function, you use the "long form": libname[funcname](...) where funcname is the function you wish to use, libname is the package it is contained in, and (...) is the argument list. For example:
> A := array(1..2,1..2,[[1,2],[3,4]]);
[1 2]
A := [ ]
[3 4]
> linalg[trace](A);
5
For example, if you want to save variables a, b, and c:
> save a,b,c,"filename.m"
When you specify a filename with the extension ".m", Maple saves your work in "Maple internal format". This format can be read in more quickly by Maple when you restore your work later on, but is not human-readable. You restore the information with the command:
> read "filename.m";To save information in a human-readable format (Maple language format), you can type:
> save a,b,c,"filename"
This saves the specified items as a series of assignment statements.
To save an entire worksheet, select File, followed by Save As. For more information on formats, consult Maple's online help. (Prior to Maple 7, the save command could also be used without specifying variables, to save an entire session; this is no longer the case.)
There are two reasons why only a limited number of automatic simplifications are performed:
> 4^(1/2) + 3; 1/2 4 + 3 > simplify (%); 5 > simplify (%% + sin(x)^2 + cos(x)^2, trig); 1/2 4 + 4See ?simplify for the various simplification options.
The expand command forces distribution of multiplication over addition. For instance:
> f := (x + y) * (x - y); f := (x + y) (x - y) > expand(f); 2 2 x - ySince expand turns f into x^2 + y * x - x * y - y^2, the automatic simplifications turn the expression into x^2 - y^2.
For more information on simplification, see ?simplify, ?expand, ?factor, ?normal, and the Learning Guide section 26 on "Expression Mamipulation".
The global variable "printlevel" is a particularly handy one to know. By setting "printlevel := 0;" you turn off the automatic printing of your commands; setting "printlevel := 1;" is the default behaviour. See ?printlevel for the effect of other settings.
> # Be sure that the index variable is a mathematical variable.
> # If i had a value (say, 3), it would be meaningless to say
> # something like "sum 3 squared for 3 from 1 to n" when you
> # meant to say "sum i squared for i from 1 to n":
> i;
i
> # This is an example of a sum over an indefinite (non-negative)
> # index range:
> x; # Just to be sure, we want to see if x is a mathematical variable.
x
> sum(x^i, i);
i
x
-----
x - 1
> # These are examples of definite sums:
> sum(i, i = -2 .. 5);
12
> sum(x**i, i = 0 .. 3);
2 3
1 + x + x + x
> # Take the first-order derivative of an expression w.r.t. x: > diff(3*x^2, x); 6 x > # Take higher-order partial derivatives by specifying a sequence > # of variables. Derivatives are taken in the same order as the > # variable sequence: > diff(y * x^2 + y, x, y); 2 xDefinite and indefinite integration are performed using the int command, in the same way as described for the sum command:
> # An example of indefinite integration: > int( cos(x), x ); sin(x) > # An example of definite integration: > int( x^2, x=0..2 ); 8/3 > # An example where Maple can't find the solution: > int(exp(-x^2)*ln(x),x); / | 2 | (-x ) | e ln (x) dx /When Maple is unable to find the solution to a problem, it returns a "prettyprinted" version of the original command expression. Sometimes this will be because Maple doesn't know how to solve the problem, but more often it will be because either no solution exists or the original command/query was not posed properly.
> # Compute some terms of the Taylor series for cos(z) at z=0: > taylor(cos(z),z=0); 2 4 6 1 - 1/2 z + 1/24 z + O(z ) > # The default number of terms in the expansion is controlled by > # the global variable Order, which is initially set to 6: > Order := 9; Order := 9 > taylor(cos(z),z=0); 2 4 6 8 9 1 - 1/2 z + 1/24 z - 1/720 z + 1/40320 z + O(z ) > # You can also specify the expansion order to taylor(..): > taylor(cos(z),z=0,4); 2 4 1 - 1/2 z + O(z )There is also a series function for a more general method of series expansion. See ?series, ?taylor, and ?asympt for more information on series-expansion facilities.
> limit(cos(x+Pi/2)/x,x=0);
-1
> limit(sin(1/y^2),y=0);
-1 .. 1
> limit(a*cos(x+Pi)/x,x=0);
a cos(x)
lim - --------
x -> 0 x
> limit(1/x, x=0, real);
undefined
> # Solve a single equation with one unknown and one solution:
> solve(exp(x) = 1);
0
> # Solve a single equation with a constant, an unknown, and two solutions:
> solve(x^2 = a, x);
1/2 1/2
a , - a
> # An expression like "x+y" is implicitly assumed to be equal to 0:
> solve ({x + y});
{x = -y, y = y}
> # Solve a system of equations simultaneously:
> solve ( {x+2*y=3, y+1/x=1}, {x,y});
{x = -1, y = 2}, {x = 2, y = 1/2}
The function for solving differential equations is dsolve. For full
details on using it, see ?dsolve. Here is a simple example:
> deq := diff(y(x),x) + y(x) = 0; / d \ deq := |---- y(x)| + y(x) = 0 \ dx / > dsolve(deq, y(x)); y(x) = _C1 exp(-x)As the various solve functions need to specify solution constants, they generate names like "_C1", "_C2", etc.
> # x and y are mathematical variables:
> x,y;
x, y
> solset := solve({x + 2 * y = 3, y + 1/x = 1}, {x, y});
solset := {x = -1, y = 2}, {x = 2, y = 1/2}
> assign (solset[1]); x,y;
-1,2
When there is a choice of solutions to assign, and you haven't specified a
particular choice by subscripting a particular solution in the set, assign will
chose one solution to apply to the independent variables.You can make temporary assignments to mathematical variables using the function subs. This allows you to evaluate an expression for a given set of values, without turning the mathematical variables into programming variables. Given that Maple generally applies full evaluation, this is an important feature. By giving subs a sequence of variable bindings and an expression, you can "test" the expression with those values:
> # z is a programming variable: > z; z > f := cos(z); f := cos(z) > # Now, to see what f(2) is: > subs(z=Pi, f); cos(Pi) > # Force evaluation to simplify the result: > eval(%); -1 > # Now check to see the value of z: > z; z
> f := (a*b)/(c*d), c^d: > print(f); a b d ---, c c d > lprint(f); a*b/c/d c**dYou can also plot expressions in Maple. Two-dimensional plots are generated using the plot command, which works both in tty- and X-sessions. The basic syntax of the plot command is plot (function, range), or plot (f(x), x=a..b). For instance:
> x := 'x'; > plot (cos(x), x = 0..Pi);
For a parametric plot, use the syntax plot ([fx, fy, range]). For example:
> plot ([sin(t), cos(t), t = -Pi..Pi]);
To generate 3-D plots you use the plot3d command, which only works in X-sessions. To utilize the plotting features to the fullest, you may need to understand the basics of writing Maple procedures, but simple plots can be generated without this knowledge. For more details on plotting commands, you can see ?plot and ?plot3d, or consult the Graphics chapter of the learning guide.
To look at the i-th part of an expression, you use op(i, expression), where i evaluates to a non-negative integer.
Example:
> e1 := op1 + op2 + op3: > e2 := op1 * op2 * sin(op3): > op(2, e1); op2 > op(3, e2); sin(op3)As you can see, the operands of the expression are returned, not the operators that connect them. This is because Maple categorizes expressions into "types". For instance, "a+b+c" is of type "+" and has three operands; "a+b*c" is also of type "+" and has only two operands, one of which is of type "*" and itself has two operands. The whattype function tells you the type of an expression; type is a boolean test that allows you to check for a particular type of expression. For example:
> whattype(e1); + > whattype(e2); * > type(e1+e2, `+`); true > type(expand(e1*e2),`+`); trueTo find out the number of operands in an expression, you use nops(expr). For example:
> expand(e1*e2);
2 2
op1 op2 sin(op3) + op1 op2 sin(op3) + op1 op2 sin(op3) op3
> nops(%);
3
Sets and lists are also Maple types. A set is just a sequence of items between "{" and "}" symbols; it is the same as a mathematical set, in that the sets {a, b, c}, {b, c, a}, and {a, a, b, c, a} are all the same. A list is a sequence of items between "[" and "]" symbols. The above, were they lists, would not be the same; a list is ordered in the order in which it was created, and duplicate values appear more than once in the list. Their Maple type names are "set" and "list".
To access particular items of sequences, sets, and lists all you have to do is subscript them:
> w0 := a1, a2, a3:
> w0[1];
a1
> w1 := {a1, a2, a3};
w1 := {a1, a2, a3}
> w1[2];
a2
> w2 := [a1,a2,a3];
w2 := [a1, a2, a3]
> w2[1..2];
[a1, a2]
The last example uses a "range". A range is valid Maple type and is used to
describe a range of values. Unlike sequences, sets, and lists, you can not
subscript a range.There are a number of operations that work on sequences, sets, and lists. See the Maple help sections on their type names for more information.
> tab := table([key=100, name=joeuser, address=mit]);
tab := table([
key = 100
name = joeuser
address = mit
])
> tab[name];
joeuser
> tab[phone] := `x0-0000`;
tab[phone] := x0-0000
> tab;
tab
> op(tab);
table([
phone = x0-0000
key = 100
name = joeuser
address = mit
])
The example shows that tables are one of Maple's exceptions to the use of full
evaluation. Tables, arrays, and procedures use what is referred to as "last
name evaluation". In essence, variables access these objects by reference, not
by value. To directly access the value (to copy it, for instance), you need to
use the op function described earlier.An array is much like a table, except that you specify an integer range of subscripts. For example:
> arr := array(1..2, 1..2); arr := array(1 .. 2, 1 .. 2, []) > arr[1,1] := 1: arr[2,2] := 2: > print(arr); [ 1 arr[1, 2] ] [ ] [ arr[2, 1] 2 ]
for variable from start by change to finish while
condition do
statement-sequence
od;
and:
for variable in expression while condition do
statement-sequence
od;
The statement-sequence is repeated for each distinct value of
"variable" while "condition" is true. The "for ...",
"from ...", "by ...", "to ...", and "while ..."
clauses are all optional. If "from start" or "by
change" are not specified, they default to a value of 1.In the first case, "variable" is initially assigned the "start" value (so "variable" can be either a mathematical or programming variable prior to use in the loop). With each successive loop if "variable" is less than or equal to "finish" then "variable" is incremented by "change"; if the "while" condition is also true then the statement sequence is repeated. If either the "to" or "while" conditions are false, the loop terminates.
In the second case, "variable" is successively assigned the component parts of the expression. This form of the for statement is just a more convenient way of expressing something like:
for variable to nops(expression) while condition do
statements that use op(variable, expression)
od;
Example:
> listsum := 0: > for i in [1,2,3,4,5] while i < 5 do > listsum := listsum + i: > od: > listsum; 10
if condition then
statement-sequence
elif condition then
statement-sequence
...
elif condition then
statement-sequence
else
statement-sequence
fi;
The elif and else portions are optional; there may be more than
one elif clause in a row. The (boolean) condition in the
if section is evaluated; the corresponding statement-sequence is
evaluated if the condition is true. If the condition is false,
control passes to the next elif or else clause. If no
condition is true and there is no else clause, no action is
taken.Example:
> printlevel := 0: > for x by 3 to 20 do > if isprime(x) then > print(x, `is prime`); > elif type(x, odd) then > print(x, `is odd non-prime`); > else > print(x, `is even non-prime`); > fi; > od; 1, is odd non-prime 4, is even non-prime 7, is prime 10, is even non-prime 13, is prime 16, is even non-prime 19, is prime > printlevel := 1:
>> break;The break statement is used in for and while loops to terminate iteration of the loop altogether. Flow of control resumes with the statement following the body of the loop.
Example:
> printlevel := 0: > listsum := 0: > for i in [1,2,3,4,5] do if i >= 5 then break fi; > listsum := listsum + i; > od; > listsum; 10 > printlevel := 1:
>> next;The next statement is used in for and while loops to terminate the current iteration of the loop. Flow of control resumes with evaluation of the loop condition.
Example:
> printlevel := 0: > listsum := 0; > for i in [1,2,3,4,5] do > if type(i, odd) then > next; > fi; > listsum := listsum + i; > od; > listsum; 6 > printlevel := 1:
> f := (x,y) -> x^2 + y^2;
2 2
f := (x,y) -> x + y
> f (1,2);
5
For more complicated functions, the procedure statement can be
used. Its syntax is:
proc (name-sequence)
local name-sequence;
global name-sequence;
options name-sequence;
statement-sequence;
end;
The proc (name-sequence) is the procedure header, and
the name-sequence is a formal parameter list. These are the
internal variable names for values that you would pass during calls to
the procedure. The global and local name-sequence
are optional clauses listing the global and local variables, and options
name-sequence is an optional clause of settings that
influence the procedure's behaviour at runtime.Notice that there is no specification for the name of the procedure. Since procedures are objects that can be assigned to variables, the name of the variable you assign it to is used as the name of procedure. The value of the procedure is usually the value of the last expression evaluated. Other values may be returned by using explicit return, error return, or return through a parameter. See the Maple Programming Guide for more information on return types.
Example:
> # Out of curiosity, see if "x" is a mathematical
variable:
> x;
x
> f := proc(x)
> x^2 + 1;
> end;
f := proc(x) x^2+1 end
> f(2);
5
> x;
x
In this example, the global variable "x" is not affected by the formal
parameter "x", which is local to function "f".
Local variables also have one other very important distinction: they are not subject to the default full evaluation. This is because local variables commonly do not require full evaluation, so performance is improved by this exception to the general evaluation scheme.
Example:
> # Set value of global "a":
> a := 0;
a := 0
> g := proc(x)
> local a, b;
> a := b^2 + x;
> print(a);
> b := 2;
> print(`a:`, a, ` eval a:`, eval(a), ` a:`, a);
> end:
> g(2);
2
b + 2
2 2
a:, b + 2, eval a:, 6, a:, b + 2
> # So full evaluation doesn't happen to local variable "a", even
> # if evaluation is called. You'd have to assign the result of
> # "eval(a)" to "a" to update its value.
> a;
0
> # Just to check, the global variable "a" is not affected by
> # the local variable "a" in function "g".
You can force remember for particular argument values, whether or not option remember has been specified. You simply perform an assignment to the function with the appropriate parameter value. For example:
> h(2) := 3; h(2) := 3 > h(2); 3This is why it is necessary to use proc to define functions. It is tempting to try syntactic definitions like m(x) := x^2, but what you are really doing is stating something like "the value of function m at the string `x` has the value `x`^2", assuming "x" was a mathematical variable when you entered in the assignment statement. When you try to plot this pseudo-function, you will find that some forms of plotting (like parameterized 3-D plotting) do not work.
RETURN(value);This causes the procedure to terminate, returning the value specified.
ERROR(error-message-string);The "ERROR" must be in capital letters. When you use ERROR in procedures to indicate that something has gone wrong, you will see a message printed of the form:
Error, (in procname) error-message-stringAs is the case with Maple-detected errors, the computation is then interrupted and aborted.
> x1 := proc(tau, theta)
> (a + b*sin(tau))*cos(theta);
> end:
> y1 := proc(tau, theta)
> (a + b*sin(tau))*sin(theta);
> end:
> z1 := proc(tau, theta)
> b*cos(tau);
> end:
> torus1 := [x1,y1,z1]:
> x2 := proc(tau, theta)
> a + x1(tau, theta);
> end:
> y2 := proc(tau, theta)
> z1(tau, theta);
> end:
> z2 := proc(tau, theta)
> y1(tau, theta);
> end:
> torus2 := [x2, y2, z2]:
> plotranges := 0..2*Pi, 0..2*Pi:
> optionseq := scaling=CONSTRAINED, axes=NONE, numpoints=1600:
> plotboth := 'plot3d({torus1, torus2}, plotranges, optionseq)':
> a := 10: b := 3:
> # Now just use "plotboth" to plot the two surfaces
> plotsetup (window);
> plotboth;
Plots will display inline (which is the default) or in a separate
window according to the setting specified in a plotsetup ()
command, or under Options -> Plot Display.From the File menu in a plot window, use Print to print or save to a postscript file. To save to other file formats (or to save in tty), use plotsetup (devicetype, plotoutput="filename"). For example:
> plotsetup (jpeg, plotoutput="tori.jpg");
> mypackage[successor] := proc(n) n+1 end:A library is a collection of Maple objects (typically packages) stored on disk. Though the implementation can vary across platforms, on Athena a Maple library is a directory that contains files of source and files in "Maple internal format", otherwise known as ".m" files.
You need to tell Maple where your libraries will be. This is done with the global variable "_liblist". This variable contains a list of libraries (i.e., directory names) that you want to use in addition to the standard Maple library. Be sure you create the directories first from the athena% prompt before trying to use them in Maple. If you didn't create them before starting Maple, then enter an xterm and use a command like:
athena% mkdir ~/mylibrary athena% mkdir ~/mylibrary/srcto create the directories for your library and source off of your home directory.
Example:
> mylibrary := `/mit/joeuser/mylibrary/`: > _liblist := [ mylibrary ]:Now to place a package in a library, you need to save it as a ".m" file in one of the libraries (directories) in "_liblist". You should also place the source for package in the "src" subdirectory of the library. We are going to introduce the string concatenation "cat" operator to build the path names for the new library:
Example:
> save mypackage, cat(`mylibrary`,`mypackage.m`); > save mypackage, cat(`mylibrary`,`src/mypackage`); > # Now, lets see if we can load the package in: > with(mypackage); [successor]
mint filenameBe sure that the file is a source file, not a .m file that is in Maple's own internal format.
To help you debug programs while they are running, you use the Maple command trace and the global variable "printlevel". By setting "printlevel" to a high value, the values of statements nested in procedures and control structures is displayed, just as you see at the top level for statements you enter interactively. For example:
> testproc := proc(x) local s; if x > 2 then s := x-1; testproc(s) else x fi; end;
testproc := proc(x) if 2 < x then s := x-1; testproc(s) else x fi end
> printlevel := 17:
> testproc(4);
{--> enter testproc, args = 4
{--> enter testproc, args = 3
{--> enter testproc, args = 2
2
<-- exit testproc (now in testproc) = 2}
2
<-- exit testproc (now in testproc) = 2}
2
<-- exit testproc (now at top level) = 2}
2
> printlevel := 1:
The trace command is used to selectively trace calls and exits of a
particular procedure. You use trace(procname) to turn tracing on
for the procedure procname; you use untrace(procname) to
disable it. For example:
> trace(testproc);
testproc
> testproc(4);
{--> enter testproc, args = 4
{--> enter testproc, args = 3
{--> enter testproc, args = 2
2
<-- exit testproc (now in testproc) = 2}
2
<-- exit testproc (now in testproc) = 2}
2
<-- exit testproc (now at top level) = 2}
2
> untrace(testproc);
testproc
> testproc(4);
2
To learn more about debugging in Maple using trace and printlevel,
see ?trace, ?printlevel, and the Maple
Programming Guide. To learn more about Mint you can read the man page (once
you've added the maple locker) by typing the following command from the
athena% prompt:
athena% man mint
|
|
Comments and feedback to olh-suggest@mit.edu
|