Next: USER-DEFINED FUNCTIONS Up: A Short Maple Primer Previous: BASIC FACTS

HELP FACILITIES

center

> ?fname; displays a help message about fname, and a general help message can be obtained by typing a sole question mark: > ?

The call > anames(); returns a list of all names that have been assigned a value.

Assign the global variable printlevel to an integer and Maple will trace the execution of all its code.

The trace function can be used to trace the execution of a specific procedure.

READING and SAVING FILES

To save all data on the file foo type > save(foo);

If you just want to save some assignments type > save(name1,name2,foo);

The command used for reading from a file is called read: > read(foo);

SEQUENCES, LISTS and SETS

Sequences are expressions separated by commas. Sequences can be generated using the seq command.


> 1, (2,3,4), 5;
                            1, 2, 3, 4, 5

> seq( i!, i=1..5 );
                           1, 2, 6, 24, 120

A list is of the form [op1, ..., opn] and a set {op1,...,opn}. The i:th element of the list L is addressed L[i]. (also works for sets). Examples:


> L:=[17,f,ln(y),[1,9]]:  L[2];
                                   f

> S:={9,L[1],L[4][2],9};
                             S := {9, 17}

There is no special append function; instead, to append x to the list L you write


> L:=[op(L),x];
                     L := [17, f, ln(y), [1, 9], x]

Some operations you can perform on sets are: union, intersect, minus:


> {1,2,3} union {a,2,b} minus {c,3};

                                  {1, 2, a, b}

> map(fcn,L); means ``apply the function fcn on every element in the list L''. This also works for sets, vectors, matrices etc. If fcn takes several arguments you type

> map(fcn,L,arg2,arg3);

ASSIGNMENT and EVALUATION

Assignments are made with := whereas the equality sign = is used for equations.

To check the current value of a variable type its name: > a;

The exceptions are vectors, matrices, arrays, tables and procedures for which the print or op command has to be used: > print(A); or > op(A);

To check if the variable a has been assigned a value you can type > assigned(a);

To unassign the variable a write > a:='a';

The main evaluation rule in Maple is that every expression is evaluated as far as possible, i.e. all variables in the expression are substituted by their value if they have been assigned one. Thus the order in which assignments are made is of importance, as is illustrated by the following example.


> a:=b;
                                 a := b
> b:=3:
> c:=b;
                                 c := 3
> b:=4:
> [a,b,c];
                               [4, 4, 3]

> b:='b': [a,b,c];
                               [b, b, 3]

This principle does not work for vectors and matrices. E.g. no evaluation of the entries of the matrix A is made at the call > op(A); The best way to circumvent this is to use subs (see Elementary Manipulation below).

For complex evaluation of expr, use > evalc(expr);

To evaluate the expression expr numerically with n digits, type > evalf(expr,n); If n is left out the floating point precision is determined by the variable Digits.

The function evalhf uses the hardware floating-point of the system, to enhance speed.

ELEMENTARY MANIPULATION

> op(n,expr); extracts operand number n in expr. Example:


> a:=x+2*y*z^2;
                                              2
                                a := x + 2 y z
> op(2,a);
                                          2
                                     2 y z
> op(2,");
                                       y

> nops(expr); number of operands of expr, e.g. the length, if expr is a list.

> subs(a=b,expr); Substitute a by b in expr. If the second argument is a vector, matrix etc. you have to use op: > subs(a=b,op(M));

rhs, lhs right and left hand sides of equations

Re, Im Real and imaginary part

> coeff(pol,var); gives the coefficient of var in the polynomial pol.


bondaren@thsun1.jinr.ru