An Introduction To Mathematical Computation Using Maple V: Ronald S. Harichandran
An Introduction To Mathematical Computation Using Maple V: Ronald S. Harichandran
MATHEMATICAL COMPUTATION
USING MAPLE V
by
Ronald S. Harichandran
Professor and Chairperson
Acknowledgements
Mr. Scott Stowitts, a graduate student in civil and environmental enginering, assisted in the prepa-
ration of this guide while being supported by the DeVlieg Fellowship in 1993. The DeVlieg Fellow-
ship is administered by the Division of Engineering Computer Services at Michigan State
University.
September 1999
Table of Contents
1. Starting Maple on Sun Workstations Supported by DECS ........................................1
2. Basic Features .............................................................................................................1
2.1 Interface ....................................................................................................1
2.2 Maple Objects ...........................................................................................2
3. Algebraic Manipulations.............................................................................................4
4. Numerical Evaluation .................................................................................................5
5. Solving Equations .......................................................................................................6
6. Calculus.......................................................................................................................6
7. 2-D and 3-D Graphs....................................................................................................8
8. Solution of Differential Equations ..............................................................................9
9. Transforms ................................................................................................................10
10. Linear Algebra ..........................................................................................................10
11. Linear Programming .................................................................................................13
12. Statistics ....................................................................................................................13
13. The Maple Programming Language .........................................................................15
14. Reading and Writing Files, and Printing...................................................................16
15. Useful Miscellaneous Commands.............................................................................17
16. Initialization File and Customizing User Interface...................................................18
References.................................................................................................................18
Maple V is a powerful computer-based tool for performing symbolic, numerical and graphi-
cal mathematical computation. It is available on a wide variety of platforms including IBM main-
frames, UNIX workstations, PC’s running MS-Windows and Macintosh’s. Student editions of
Maple for PC’s are available for a reasonable cost at most bookstores. This is a short guide to help
you get started with Maple V Release 3 or 4 for engineering applications. Maple has extensive on-
line help that can be used to find out about its numerous commands and features. In addition, tuto-
rial guides, books and manuals are also available (Char et al. 1992, Char et al. 1991, Abell and
Braselton 1994a, Abell and Braselton 1994b, Abell and Braselton 1994c).
2. Basic Features
2.1 Interface
Help: On-line help can be obtained conveniently using the Help Browser option from the
Help menu located at the top right corner of the Maple window. Detailed help on
function fname can also be obtained using the Maple command ?fname.
Prompt: Maple commands are entered at the > prompt. On color terminals the typed com-
mands appear in red.
Fonts: Fonts displayed on the screen and used when printing can be changed using the For-
mat/Styles menu option.
Cut & Paste: Parts of previously typed commands (red text on color terminals) may be cut by
clicking and dragging with the left mouse button, placing the cursor at the bottom
line by clicking the left button next to the prompt, and pressing the middle mouse
button to paste the text. Extended regions may be copied to the clipboard and pasted
using the Edit menu.
Scrolling: The scroll bar on the right side of windows can be used to scroll back to review pre-
vious work.
Terminators: Each command must be terminated with a semi-colon (;) or a colon (:). The
semi-colon echoes the typed line, while the colon suppresses the echo.
Case: Maple is case sensitive. Xyz is different from xyz.
History: The previous three commands may be recalled by typing ", "" or """. For a longer
history mechanism use the history command.
Saving: Select Save or Save As… from the File menu. For a new worksheet, or when the
Save As… command is selected, enter the file name in the Filename box or double
click on a file appearing in the list of files. Previously saved file can be retrieved
using the Open… command from the File menu.
1
Printing: Select Print… from the File menu, and on the pop-up form, click on the Print Com-
mand radio button, and type “lp -dprinter_name” in the Printer Command box
(where printer_name should be replaced by the name of a printer). Other print op-
tions can also be selected on the form.
Variables: Long expressions, numerical results, etc. can be assigned to variables using
variable := expression;
e.g., exp1 := 2*x + y;
Note that exp1 is a Maple variable, while x and y are algebraic variables used to
construct the expression.
Functions: The built-in mathematical functions are: exp(x), ln(x) or log(x), log10(x) for
logarithm to the base 10, log[b](x) for logarithm to the base b, sqrt(x), abs(x),
min(…), max(…), iquo(…) for truncating division, irem(…) for integer remainder,
round(x) to round to nearest integer, trunc(x) to truncate, frac(x) for fractional
part, a mod b for modular arithmetic, gcd(…) for greatest common divisor, lcm(…)
for least common multiple, signum(x)for the sign function, sin(x), cos(x),
tan(x), sec(x), csc(x), cot(x), sinh(x), cosh(x), tanh(x), sech(x),
csch(x), and coth(x) for the trigonometric and hyperbolic functions, arcsin(x),
arccos(x), etc., for the inverse trigonometric and hyperbolic functions, GAMMA(x)
for the Gamma function, binomial(n,m) for the binomial coefficient, Beta(x,y)
for the Beta function, erf(x) for the error function, Dirac(t) for the Dirac delta
function, Heaviside(t) for the unit step function, and so on.
User-defined functions can be specified using a special syntax or as Maple proce-
dures as shown in Table 1. Procedures are written using the Maple programming
language (see Section 13).
2
Sequences: A simple ordering of Maple objects separated by commas.
e.g., a, b, c is a sequence.
s := seq(x^2, x=0..5) assignes the sequence 0,1,2,3,4,5 to s.
The third to the fifth elements of s may be extracted with s[3..5].
Sets: A set is a sequence surrounded by braces { }. e.g., {a, b, c}.
The operations union, intersect and minus can be used to with sets.
e.g., set1 := {a, b}:
set2 := {a, d, e}:
set1 union set2 would yield {b, a, d, e}.
The operand of a set may be extracted as a sequence with op(range, set).
e.g., op(2..3, set2) would yield the sequence d, e.
The number of operands in a set may be obtained with nops(set).
e.g., nops(set3) would yield 3.
Lists: A list is a sequence surrounded by square brackets [ ]. e.g., [a, b, c].
The elements of a list may be extracted as a sequence with list[i..j].
e.g., L := [17, f, ln(y), [1,9]]:
L[3] would return ln(y). L[4] would return the list [1,9]. L[2..3] would
return the sequence f, ln(y).
The command map(f, L) can be used to apply the function f on every element of
the list, set, array, vector or matrix L.
Arrays: An array is a collections of objects referenced by integer subscripts. The subscripts
can contain negative integers and zero.
e.g., a := array(1..2, 1..2) defines a 2 × 2 array.
a[1,1]:=1: a[1,2]:=2: assigns values to the array elements.
print(a) would print the entire array on the screen.
Arrays can be defined using the indexing functions sparse, symmetric, antisym-
metric or identity by the command array(indexing function, …). Sparse arrays are
assumed to have zero elements unless specified otherwise, symmetric and antisym-
3
metric arrays have those properties enforced on their elements, and identity arrays
have unit diagonal elements with all other elements being zero.
The indices(array) function lists the indices that correspond to non-zero elements,
and the entries(array) function lists the non-zero entries.
Vectors: Vectors are one-dimensional arrays of the form array(1..n).
Matrices: Matrices are two-dimensional arrays of the form array(1..n, 1..m).
Strings: Procedure names, file names, etc. that are strings must be enclosed by back-quotes
when used as arguments to commands.
3. Algebraic Manipulations
collect(expr, var); Collect coefficients of like powers of var. The second form
collect(expr, var, name); allows terms containing name (e.g., sin(x)) to be collected.
coeff(expr, var); Extracts the coefficient of var^n in expr. In the first form n de-
coeff(expr, var^n); faults to 1. Use collect before using coeff.
sort(expr); Sorts the polynomial or list expr into ascending order.
expand(expr); Expand expression by multiplying it out. The optional argu-
expand(expr, expr1, …, exprn); ments expr1, … exprn are used to prevent particular sub-expres-
sions from being expanded. Functions such as sin(2*x) are
also expanded.
combine(expr); Combine terms in sums, products and powers into a single
combine(expr, name); term. Values for name should be one of exp, ln, power, trig
or Psi. For many functions, the transformations applied by
combine are the inverse of the transformations that are ap-
plied by expand.
simplify(expr); Simplify expr. The type of simplification can be controlled by
simplify(expr, rule); specifying rule (commonly power, radical, RootOf, sqrt
or trig).
factor(expr); Factor a polynomial over the rational numbers. The second
factor(expr, field); form allows factoring over other algebraic fields (e.g., fac-
tor(x^2+4,I) yields (x + 2 I)(x - 2 I)).
subs(var = replacement, expr); Substitute all occurrences of var in expr by the specified re-
subs(var1 = replacement1,…, varn = placement expression. The second form is used to substitute
replacementn, expr); for several variables.
assign(var = expr); Globally assign expr to the variable var. The second form is
assign(var1 = expr1, …, used to assign values to many variables. All other previously
varn = exprn) defined objects containing the variables are updated using
the assigned values. To un-assign the value assigned to a
variable x (i.e., to let the variable become an unknown again)
enter x := ’x’.
4
convert(expr, form, optargs); Convert expressions from one form to another. Valid forms
include: parfrac with optargs set to var for a partial fraction
expansion about the main variable var; fraction to express
a floating point number as a whole fraction, polar for polar
form of a complex expression, and so on. The type of con-
version usually depends on the form of expr. Look under the
Library../convert.. topic in the Help Browser for a detailed
list.
lhs(expr); rhs(expr); Returns the left-hand side and right-hand side of the equation
or inequality expr.
numer(expr); denom(expr); Numerator and denominator of expr.
Re(expr); Im(expr); Real and imaginary parts, and the conjugate, of the complex-
conjugate(expr); valued expr.
evalc(expr); Attempts to split complex-valued expr into its real and imag-
inary parts expressing the result as expr_1 + I*expr_2. Un-
known variables are assumed to be real-valued. This
command is often useful for expressing complex exponen-
tials in terms of sine and cosine functions.
map(f, expr); Applies the function f to each element of expr, where expr may
map(f, expr, arg2, arg3, …, argn); be any structure such as a sequence, list, set, matrix, etc.
Some functions do not work with certain types of arguments.
For example, the simplify command works with a single
expression, or a list of expressions, but does not work with a
matrix. The command map(simplify, mat), simplifies each
element of the matrix, mat.
For Maple commands that need arguments, first a user-de-
fined function must be created and then used with the map
command. For example, the subs command does not work
on matrices, and a user-defined function must first be created
and then used with map, as shown below, to perform substi-
tution within matrices:
mysubs := proc(x,y) subs(y,x) end:
map(mysubs, mat, {var1 = replacement1,…, varn = replace-
mentn});
4. Numerical Evaluation
Digits := n; Sets the precision for numerical evaluations. The default is
Digits := 10.
evalf(expr); Evaluates expr using floating-point calculations. In the sec-
evalf(expr, digits); ond form, digits temporarily overrides the precision set by the
variable Digits.
5
5. Solving Equations
solve(eqn); The first form solves an equation in one variable (e.g.,
solve(eqn, var); solve(3*x + 4 = 5*x)). The second form solves for var in
solve(eqn_set, var_set); an equation containing several variables (e.g., solve
(ln(x^2-1)=a, x)). If multiple solutions exist, then a solu-
tion sequence is returned. The third form solves a set of
equations for a set of variables (e.g., solve({a=b+2,
b-a=t}, {a,b})) and returns a solution set, or a sequence
of solution sets if multiple solutions exist. Solutions may
sometimes contain the expression RootsOf(polynomial) to
signify that the solutions are the roots of the indicated poly-
nomial.
allvalues(expr); Computes all possible values of solutions returned with the
expression RootsOf. Since RootsOf may contain several
roots of a polynomial, each root is substituted into the solu-
tions to obtain all possible solutions.
fsolve(eqn); Numerical solution of equations. Equations that cannot be
fsolve(eqn, var); solved exactly using solve may be able to be solved numer-
fsolve(eqn_set, var_set); ically using fsolve. When a solution cannot be found, the
fsolve(eqn_set, var_set, options); input expression is returned, but there could still be a possi-
ble solution (specifying a range may help). Valid options are:
complex (e.g., complex roots of polynomial); a..b to limit
search to open interval (e.g., {x=a..b, y=c..d, …});
maxsols=n to find at most n roots; and fulldigits to eval-
uate roots to the precision specified by the variable Digits.
6. Calculus
limit(expr, var = a); The first form computes the bi-directional limit of expr as var
limit(expr, var = a, option); approaches the number a, except when a is infinity or -
infinity in which case the appropriate directional limit is
computed. The second form is more general and a valid op-
tion is one of left, right, complex or real (the last option
also computes the bi-directional limit). If a limit is not found
the input expression is returned.
series(expr, var, n); Series expansion of expr up to order n. In the first form the ex-
series(expr, var=a, n); pansion is about the origin, while in the second form it is
about the point a. If a Taylor series is specifically desired,
then series may be replaced by taylor.
mtaylor(expr, [var1, …, varn], n); Multi-dimensional Taylor series of expr up to order n. In the
mtaylor(expr, [var1=a1, …, first form the expansion is about the origin, while in the sec-
varn=an], n); ond form it is about the point (a1, …, an).
6
sum(expr, index = low..high); The first form is used for a definite summation (e.g.,
sum(expr, index); sum(i,i=1..1000);) or symbolic sum (e.g., sum(i^2
i=1..n)). The second form is used for an indefinite summa-
tion.
product(expr, index = low..high); Similar to the sum command, except that the product is com-
product(expr, index); puted.
readlib(minimize): Unconstrained minimization and maximization of expr. The
minimize(expr); third and fifth forms are used to minimize and maximize
minimize(expr, var1, …, varn); multi-dimensional functions with respect to the variables
maximize(expr); var1, …, varn. The readlib(minimize) command must pre-
maximize(expr, var1, …, varn); cede the first call to minimize or maximize in the current
session.
readlib(singular): Finds singularities of expr. The readlib(singular) com-
singular(expr); mand must precede the first call to singular in the current
singular(expr, {var1, …, varn}); session. In the last form, expr is assumed to be a function of
var1, …, varn.
diff(expr, var1, …,varn); Partial derivative of expr with respect to var1, …, varn. Specify
variables repeatedly for higher-order ordinary derivatives
(e.g., diff(sin(x),x,x) evaluates d2(sin x)/dx2). The syn-
tax diff(expr,var$n) or diff(expr,var1$n1, var2$n2, …) can
be used for higher-order derivatives, where var$n represents
n repetitions of var.
int(expr, var); Indefinite or definite integral of expr with respect to var. The
int(expr, var = low..high); values low and high specify the range for definite integration.
int(expr, var = low..high, option); If the integral cannot be evaluated in closed-form then it is
displayed unevaluated, and if desired numerical integration
or series expansion may then be performed using evalf or
series. For definite integration the existence of discontinu-
ities are checked by default, and the integral is evaluated as
the sum of independent integrals, each of which has no dis-
continuity. Specifying continuous for option disables this
check. To compute the Cauchy Principal Value of an integral
containing a discontinuous integrand specify option to be
CauchyPrincipalValue. For double and triple integrations
use nested constructions of int (e.g., int(int (x^2*y^2,
x),y)for ∫∫ x2y2dxdy).
Diff(…); These are the inert forms of diff and int, and have argu-
Int (…); ments identical to those. They return unevaluated, simply
producing mathematically formatted display, and are useful
for visually checking complicated expressions, before actu-
ally evaluating them using diff or int.
assume(var1 > 0, var2 < 0, …); Assume that var1 is positive, var2 is negative, etc. Some inte-
grals that cannot be evaluated for general values of its sec-
7
ondary variables, may be able to be evaluated if the range of
the variables is known (e.g., ∫0∞ e−at ln t dt is evaluated only if
it is assumed that a > 0).
readlib(residue): Algebraic residue of expr for the chosen variable, var, around
residue(expr, var = a); the point a. The readlib(residue) command must precede
the first call to residue in the current session.
8
plot3d(expr, var1=a..b, 3-D surface plots. The first two forms are used for single and
var2=c..d, options); multiple surfaces in Cartesian coordinates. The third and
plot3d({expr1,…,exprn}, fourth forms are used for parametric plots in which expres-
var1=a..b, var2=c..d, options); sions within each list are defined in terms of two parameters.
plot3d([x-expr, y-expr, z-expr, Common options are title=‘plot title‘ to write a plot title, la-
param1=a..b,param2=c..d],
bels=[‘xlab‘, ‘ylab‘, ‘zlab‘] to write axes labels,
options);
grid=[m,n] to generate the surface using an m × n grid of
plot3d([x-expr1, y-expr1, z-expr1,
param11=a1..b1, equally spaced values (default is 25 × 25) and coords=
param21=c1..d1], …, [x-exprn, spherical or cylindrical for plots in these other coordi-
y-exprn, z-exprn, param1n=an..bn, nates.
param2n=cn..dn], options); In the X-Windows interface, several features of the plot can
be controlled using a pop-up menu activated by clicking the
right mouse button in the plot window. Dragging the mouse
while the left mouse button is depressed causes the view an-
gle to change. Select Redraw from the pop-up menu to dis-
play the plot using the new plot angle. The plot style can be
changed using the Style menu (default is Hidden Line remov-
al), surface colors can be changed using the Color menu (de-
fault is XYZ which changes the colors continuously in all
three directions), axes styles can be changed with the Axes
menu (default is None), and the projection styles can be
changed with the Projection menu (default is No Perspective
and Unconstrained). Experiment with these options to get
the plot you like.
Type ?sphereplot, ?cylinderplot, ?spacecurve,
?tubeplot or ?pointplot in Maple for help on other ways
to obtain spherical and cylindrical plots, and for help on oth-
er types of 3-D plots.
9
TABLE 2 EXAMPLES OF SPECIFYING DIFFERENTIAL EQUATIONS
The variables var, var1, …, varn are specified as functions of the independent variables (e.g.,
{y(x), z(x)}). The option may be explicit, laplace, series or numeric. If the differential equa-
tion contains the Dirac or Heaviside functions, then laplace must be used. The initial conditions
must be specified at x=0 if the laplace or series option is used.
9. Transforms
laplace(expr, t, s): Laplace transforms and its inverse. The forward transform
invlaplace(expr, s, t); transforms from t to s, and the inverse transform transforms
from s to t.
ztrasn(expr, n, z): Z transform and its inverse. The forward transform trans-
invztrans(expr, z, n); forms from n to z and the inverse transform transforms from
z to n.
readlib(fourier): Fourier transforms and its inverse. The readlib(fourier)
fourier(expr, t, ω); command must precede the first call in the current session to
invfourier(expr, ω, t); fourier or invfourier. The forward transform transforms
from t to ω and the inverse transform transforms from ω to t.
Note that the 1⁄2π factor occurs in the inverse transform.
readlib(FFT): Fast Fourier transform and its inverse. The readlib(FFT)
FFT(m, x, y); command must precede the first call in the current session to
iFFT(m, x, y); FFT or iFFT. Both x and y are real-valued arrays of length 2m
that contain the real and imaginary parts of a complex array.
The transforms are performed in place, and the result is re-
turned in x and y.
10
vec:=vector([expr1, …, exprn]); Define vec to be a vector. In the first two forms, the elements
vec:=vector(n, [expr1, …, of the vector are assigned explicitly. In the third form, the el-
exprn]); ements are computed using the function f as f(1),…, f(n). In the
vec:=vector(n, f); last form, the elements are undefined. Elements of a vector
vec:=vector(n); can be accessed with vec[i].
vec:=array(1..n, [expr1, …, Alternative way of defining vectors without the linalg
exprn]);† package.
vec:=array(1..n);†
grad(expr, vec); Gradient of expr with respect to the vector or list of variables
vec.
curl([expr1, expr2, expr3], [var1, Curl of the three-dimensional function f = [expr1, expr2,
var2, var3]); expr3] with respect to the three variables.
diverge([expr1, …, exprn], [var1, Divergence of a vector function f = [expr1, …, exprn] with re-
…, varn]); spect to its variables.
potential([expr1, …, exprn], Determines whether the vector field f = [expr1, …, exprn] is
[var1, …, varn], ’pot’); derivable from a scalar potential V = [var1, …, varn] such that
∇V = f. If this is possible, then the value true is returned, and
the potential is assigned to the variable pot.
If a potential does not exist then false is returned.
vecpotent([expr1, expr2, expr3], Determines whether the vector function f = [expr1, expr2,
[var1, var2, var3], ’pot’); expr3] is derivable from a vector potential V = [var1, var2,
var3] such that ∇×V = f. If this is possible, then the value true
is returned, and the potential is assigned to the variable pot.
If a potential does not exist then false is returned.
mat:=matrix(L); Define mat to be a matrix. L is a list of lists or vectors of the
mat:=matrix(m, n, L); form [[expr11, …, expr1n], …, [exprm1, …, exprmn]]. In the
mat:=matrix(m, n, f); second form, L may consist of a single list of mn elements. In
mat:=matrix(m, n); the third form, the elements are computed using the two-di-
mensional function f as [[f(1,1), …, f(1,n)], …,[f(m,1), …,
f(m,n)]]. In the last form, the elements are left undefined. El-
ements of a matrix can be accessed with mat[i, j].
mat:=array(1..m, 1..n, L);† Alternative way of defining matrices. L is a list of lists as in
mat:=array(1..m, 1..n);† the matrix command.
mat:=diag(var1, …, varn); The first form defines mat to be a diagonal matrix with the di-
mat:=diag(mat1, …,matn); agonal elements being var1, …, varn. The second form de-
fines mat to be a block diagonal matrix with mat1, …,matn
being the matrix blocks.
11
vec[i]:=expr;† Individually assign values to elements of an array or matrix.
mat[i,j]:=expr;†
extend(mat, m, n); Enlarges mat by adding m additional rows and n additional
extend(mat, m, n, expr); columns. In the second form, all new elements are initialized
to expr.
augment(mat1, …,matn); Defines a new matrix that is obtained by stacking mat1
through matn (which must all have the same number of rows)
side by side.
row(mat, i); col(mat, i); The first form extracts the ith row (or column) of mat as a
row(mat, i..j); col(mat, i..j); vector. The second form extracts rows (or columns) i through
j as a sequence of vectors.
submatrix(mat, i..j, k..l); The first form extracts rows i through j and columns k
submatrix(mat, [i1,…,in], through l from mat as a submatrix. The second form assigns
[j1,…,jm]); the (k,l)th element of the submatrix to be the (ik, jl)th element
of mat.
copyinto(mat1, mat2, i, j); Copies mat1 into the larger mat2 starting at index position (i,j)
of mat2. New matrices can be created from existing ones by
using extend, submatrix and copyinto.
matadd(var1, var2); Matrix or vector addition.
evalm(var1 + var2);†
12
rank(mat); Rank of a square matrix.
norm(mat, normname); Matrix or vector norm. The default norm if normname is not
specified is the infinity norm. Typically normname is 1, 2,
’infinity’ or ’frobenius’, but for vectors it may also be
any positive integer. For the length of a vector normname
should be 2.
cond(mat); Condition number of a square matrix (||A|| ||A−1||).
singularvals(mat); Singular values of a matrix.
rref(mat); Reduced row echelon form of a matrix.
gaussjord(mat);
eigenvals(mat); The first form finds the eigenvalues of mat. The second form
eigenvals(A, B); finds the eigenvalues of the generalized problem Ax = λBx.
eigenvects(mat); Eigenvectors. Eigenvectors of the generalized problem can-
not be obtained directly.
charmat(A); Finds the characteristic matrix of A (i.e., λI − A), and the
charpoly(A); characteristic polynomial |λI − A|.
exponential(A, t); Matrix exponential eAt.
hessian(expr, vec); Hessian matrix of expr with respect to vector or list vec.
12. Statistics
Maple’s statistical library typically operates on “statistical matrices.” A statistical matrix is
simply a matrix whose columns consist of observations of a variable, and whose first row contains
the name of the variables (keys). The matrix
13
x y z
1.2 5.1 3.1
2.2 4.4 1.1
is an example of a statistical matrix in which x, y and z are keys, and each of these have two obser-
vations. In the following summary, smat is used to signify a statistical matrix.
with(stats): Load the statistics library. This must precede any command
requiring this library.
putkey(mat, [key1, …, keyrn]); Converts the standard matrix mat to a statistical matrix by in-
serting a row at the beginning containing the keys.
getkey(smat); Returns a list [key1, …, keyrn] which is the key of the statis-
tical matrix smat.
addrecord(smat, [a1, …, an]); Adds a row of data values to the statistical matrix smat.
evalstat(smat, newkey1=expr1, …, Computes new columns of data in smat corresponding to the
newkeyn=exprn); specified new keys using the expressions specified in terms
of existing keys.
average(x); Average of data. In the first form, x may be a list, array or
average(x1, …, xn); matrix, and for matrices, the average of each column is com-
average(smat, key1, …, keyrn); puted. The second form uses a simple sequence of data val-
ues. In the third form, the average of the columns associated
with the specified keys are computed.
median Median, standard deviation and variance of data. These com-
sdev mands may take one of the three forms shown for average.
variance
correlation(smat, key1, key2); The first form computes the correlation coefficient for the
correlation([x1, …, xn], [y1, data in the columns of smat associated with the keys key1 and
…, yn]); key2. The second form uses data from two lists.
covariance(smat, key1, key2); Similar to correlation, except that the covariance is com-
covariance([x1, …, xn], [y1, …, puted.
yn]);
linregress(smat, ykey = xkey); Returns the list [a, b], in which a is the intercept and b the
linregress([y1, …, yn], [x1, …, slope of the linear regression equation y = a + bx. In the first
xn]); form the data is given in the statistical matrix smat, and ykey
and xkey are the keys for the dependent and independent vari-
ables, respectively. In the second form the data is specified
in the two lists.
multregress(smat, ykey = [xkey1, Returns a list of coefficients [a0, …, an]of the multiple lin-
…, xkeyn], const); ear regression equation y = a0 + a1x1 + … + anxn. ykey, xkey1,
multregress(smat, key1 = [key2, …, xkeyn are keys of the statistical matrix smat. The second
…, keyn]);
form omits the constant a0 in the regression equation.
14
regression(smat, ykey = f(xkey1, Fits a generalized regression equation y = f(x1, …, xn) that is
…, xkeyn)); linear in the unknown coefficients (e.g., y = a0 + a1x12 +
a2x23). The equation is specified using the keys of the statis-
tical matrix smat and coefficients with arbitrary names.
statplot(smat, ykey*xkey); Plots 2-D data and specified equation on top of each other.
statplot(smat, ykey = f(xkey)); The first form is used to specify the X and Y axes. The sec-
ond form is typically used after regression (which assigns
values to the coefficients in the equation f(xkey)) to obtain the
plot.
ChiSquare(F, ν); Returns the value x that has the specified distribution value
Fdist(F, ν1, ν2); F. The remaining parameters are those of the distribution.
StudentsT(F, ν); The results of these commands are equivalent to the tables
found in most statistics books.
Exponential(λ, x); Returns the value of the exponential distributions with pa-
rameter λ evaluated at x (i.e., λe−λx).
Ftest(x, ν1, ν2); Computes 1 – F ν1, ν2(x) , where F is the F distribution.
N(x, m, σ2) Areas under the Normal distribution. The first form com-
Q(x); putes the area under N(m, σ2) to the left of x. The second form
computes the area under N(0,1) to the right of x.
RandBeta(a, b); Generates random numbers from the specified distributions.
RandChiSquare(ν); The arguments for each command are the parameters of the
RandExponential(λ); distribution. In all commands an optional last argument n
RandFdist(ν1, ν2); may be specified signifying the number of digits required in
RandGamma(λ); the generated random number (e.g., RandNormal(0,1,8);).
RandNormal(m, σ);
RandPoisson(λ);
RandStudentsT(ν);
RandUniform(a..b);
15
if condition then Conditional execution with if-then-else blocks. The state-
statement sequence 1 ments if x<=2 then x^2 else x^4 computes x2 if x ≤ 2
else and x4 otherwise.
statement sequence 2
fi;
16
In the X-Windows interface, the current session can be saved
in an internal format with the File/Save or File/Save As menu
options (a .mws extension should normally be used), and in
text format with the File/Export as Text menu option. Saved
sessions may be read with the File/Open menu option.
fortran(expr, option); The first form writes the expression in FORTRAN 77 format
fortran(expr, filename=‘fname‘, to the screen, while the second form writes it to the file fname.
option); If expr is a list, then one line of code is written for each item
in the list. The option may be optimized, in which case sev-
eral lines of code may be written for each expression in order
to minimize the number of arithmetic operations in the gen-
erated code.
readlib(C): These commands are used to write expr in C format. The
C(expr, option); readlib(C): command must precede the first C command
C(expr, filename=‘fname‘, in the current session. As with the fortran command, option
option); may be optimized. If it is necessary to use both the C com-
mand and a variable named C then the command should be
renamed with, say, Ctrans:=readlib(C):.
Files saved in text format can be printed on any line printer. In the X-Windows interface the
current work sheet can be saved in PostScript format using the File/Print menu option. The file can
be sent to a PostScript printer using the UNIX lp command.
17
16. Initialization File and Customizing User Interface
Commonly used libraries/commands can be automatically loaded/executed by placing them
in a personal initialization file. The initialization file is named
• .mapleinit in your home directory for Unix systems
• MAPLE.INI in your current directory for DOS systems
• MapleInit in your System folder for Macintosh systems.
It is advisable to end all statements in the initialization file with the colon so that they are not ech-
oed back at startup. It is convenient to place the following commands in the initialization file if the
linear algebra package is used often:
with (linalg):
mysubs := proc(x,y) subs(y,x) end:
myint := proc(x,y) int(x,y) end:
mydiff := proc(x,y) diff(x,y) end:
The procedures mysubs, myint and mydiff can be used with the map command to perform substi-
tutions, integrations and differentiations of elements of matrices.
References
Abell, M. L., and Braselton, J. P. (1994a). Differential equations with Maple V. AP Professional, Cambridge, MA.
Abell, M. L., and Braselton, J. P. (1994b). Maple V by example. AP Professional, Cambridge, MA.
Abell, M. L., and Braselton, J. P. (1994c). The Maple V Handbook. AP Professional, Cambridge, MA.
Char, B. W., Geddes, K. O., et al. (1991). Maple V library reference manual. Springer-Verlag, New York.
Char, B. W., Geddes, K. O., et al. (1992). First leaves: A tutorial introduction to Maple V. Springer-Verlag, New
York.
18