Some Basic Maple Commands 

 

This file contains some commonly used Maple commands.  If you have not used Maple before, I strongly recommend that you go through this worksheet BEFORE CLASS ON FRIDAY, APRIL 3. 

 

Maple is an advanced software tool for doing complicated mathematics quickly and precisely on a computer.  It is designed to aid scientists,  engineers,  students,  and mathematicians to do difficult or laborious mathematical calculations. 

 

 

Entering Text 

 

To enter text in Maple, press the combination Command-T.  There are 2 command keys, one on each side of the space bar.  Press the [return] key to enter a new paragraph. 

 

 

Entering Mathematics 

 

To enter mathematics press Command-J to get an input prompt below the cursor. Press Command-K to get an input prompt above the cursor. A math entry can contain several inputs. Separate them with semi-colons or colons. To process the inputs, press the [return] key. If an input is terminated with a semi-colon, then its output will appear below, and the last output gets a label. If an input is terminated with a colon, then the output is not displayed. We say that the output is "suppressed".  

 

 

When using Maple you type in commands at the keyboard  and then press [Enter].  Maple provides a result.  Every Maple command must be punctuated with either a semicolon ";" or a colon ":".   For example,  if you wish to multiply two numbers like "247" and "3756" the command would be to type in  247*3756;  at the Maple prompt and then press [Enter].  Try this now. 

 

> 247*3756;
 

927732 (1)
 

 

By pressing [Enter], you also move the cursor to the next command line ( i.e.  210+375;)  in the worksheet.  

 

> 210+375;
 

585 (2)
 

 

What happens if you use a colon? 

 

> 247*3756:
 

 

Notice that no result is printed; however, the computation is done, as we will see later. 

 

Arithmetic 

 

Maple is an interactive program that permits the user to enter commands at the prompt,  press the return key,  and read or use the output in other calculations.  You can use the following arithmetical operations: 

                                       +,  -,  *,  /,  ^  

which are addition,  subtraction,  multiplication,  division,  and raising to a power, respectively. 

 

 

If you ever need additional information about a Maple command,  you can always ask for Help by typing in a question mark followed by the Maple command and then press [Enter].   For example,  type in  ?+  and then press [Enter].  A help window will open that gives information on the various arithmetic operations that are available in Maple. Close the help window to return to your original Maple file. 

 

> ?+
 

 

On many platforms there is an additional Help menu on the menu bar.  On these platforms invoking help is accomplished by selecting the Maple command in question and then pulling down the Help menu.   For example,  use the mouse to select + and then pull down the Help menu and click on the menu item that says Help on "+". 

 

 

We will now give some examples that illustrate how to perform the elementary arithmetical operations. 

 

 

You can add two numbers. 

 

> 253+7775;
 

8028 (3)
 

 

You can add fractions.
 

> 25/27+3/51;
 

`/`(452, 459) (4)
 

 

You can perform operations on a previous result by using the % symbol.  The % symbol refers to the previous output. 

 

> 23*%;
 

`/`(10396, 459) (5)
 

 

One can raise a number to a power. 

 

> 3^7;
 

2187 (6)
 

 

A feature of most computer algebra sytems is that that they use exact arithmetic. For example,  if you  

divide two integers Maple returns an exact answer. 

 

> 3235/7478;
 

`/`(3235, 7478) (7)
 

There is a built-in Maple function evalf - evaluate using floating-point arithmetic.  This produces a decimal approximation. 

 

> evalf(%);
 

.4326023001 (8)
 

 

 

The default number of digits used in floating point output is 10,  but if you wish to have any other number of digits then you can specify them when using evalf.  The following is the 30 digit floating point approximation of the fraction . 

 

> evalf(%,30);
 

.4326023001 (9)
 

 

 

Built in Constants 

 

Maple has many of the the standard mathematical constants built-in.  Maple is also "case sensitive" ,  which means that it treats "a" and "A" as distinct symbols.  In Maple the mathematical constants π (the ratio of the circumference of a circle to its diameter),  and i (the pure imaginary number such that i*i = -1) are denoted by  Pi,  and I respectively. 

 

> Pi;
 

Pi (10)
 

> Typesetting:-mrow(Typesetting:-mi(
 

3.141592654 (11)
 

> Typesetting:-mrow(Typesetting:-mi(
 

`+`(`*`(`/`(1, 2), `*`(`^`(2, `/`(1, 2))))) (12)
 

> Typesetting:-mrow(Typesetting:-mi(
 

.7071067810 (13)
 

 

Functions and Variables 

 

You can assign a value or a function to a variable with the colon-equal symbol :='. 

 

> A := 5;
 

5 (14)
 

> Typesetting:-mrow(Typesetting:-mi(
 

5 (15)
 

> Typesetting:-mrow(Typesetting:-mi(
 

15 (16)
 

 

This means that the variable "A'' has been assigned the value 5 and it will have this value through the remainder of the session unless you assign it another value or "unassign"  it. 

 

> 4*A+12;
 

32 (17)
 

 

Observe that if we suppress the output with a colon, the computation is still performed. 

 

> Typesetting:-mrow(Typesetting:-mi(
 

> Typesetting:-mrow(Typesetting:-mi(
 

14 (18)
 

 

The following statement is the way to  "unassign" the variable. 

 

> A := 'A';
 

A (19)
 

 

Note that in the last statement we have enclosed A within two single quotes '.
 

 

You can also use the restart; command to clear all variables and assignments.  It's typically a good idea to type restart; at the start of each new Maple session. 

 

> Typesetting:-mrow(Typesetting:-mi(
 

 

There are essentially two ways of working with functions.  One way is to define a function as a variable.  Suppose we wish to analyze the function given by  f(x) =x^2 .   Then we can enter the following. 

 

> f := x^2;
 

`*`(`^`(x, 2)) (20)
 

 

The last command defines the function and you can check that out with the following command. 

 

> f;
 

`*`(`^`(x, 2)) (21)
 

 

There is a Maple procedure called  subs which allows you to evaluate this expression.  The format is  

                          subs(variable = something,  expression involving variable). 

 

> subs(x=5,f);
 

25 (22)
 

 

A word of warning here.  Many beginners want to use standard functional notation for a Maple expression,  such as f(5).  This results in nonsense and is not understood by Maple at all. 

 

> f(x);
 

> f(5);
 

 

`*`(`^`(x(x), 2))
`*`(`^`(x(5), 2)) (23)
 

 

If you want to use standard functional notation then you can do so using the minus-greater than symbol "->", made by typing the "minus sign"  followed by the "greater than'"  sign.  For example: 

 

> f := x -> x^2;
 

proc (x) options operator, arrow; `*`(`^`(x, 2)) end proc (24)
 

> f(x);
 

`*`(`^`(x, 2)) (25)
 

 

Now we have
 

> f;
 

f (26)
 

> f(5);
 

25 (27)
 

One of the great benefits of a computer algebra system such as Maple is that it allows you to to manipulate algebraic expressions much in the same way that a calculator permits you manipulate numbers.  Some of the algebra commands used in Maple are listed below: 

 

 

 

 

 

 

 

> simplify((1+x)/x+(1-x)/x);
 

`+`(`/`(`*`(2), `*`(x))) (28)
 

> expand((x^2-4)*(x+1)*(x-2)*(x^2+x+1));
 

`+`(`*`(`^`(x, 6)), `-`(`*`(6, `*`(`^`(x, 4)))), `-`(`*`(3, `*`(`^`(x, 3)))), `*`(6, `*`(`^`(x, 2))), `*`(12, `*`(x)), 8) (29)
 

> factor(%);
 

>
 

`*`(`+`(x, 2), `*`(`+`(x, 1), `*`(`+`(`*`(`^`(x, 2)), x, 1), `*`(`^`(`+`(x, `-`(2)), 2))))) (30)
 

> sol := solve({2*x-5*y=12,12*x+4*y=17},{x,y});
 

{y = -`/`(55, 34), x = `/`(133, 68)} (31)
 

 

Observe that we used braces "{" and "}" in the preceding Maple input.  Maple understands this to be a set.  Observe that the Maple output for the expression `"sol"  is in the form of a  set.  One thing to notice about sets is that they do not distinquish as to order. For example,  Maple might have equally well have produced an equivalent output  of  with a different order.  Maple regards a set as a kind of array and you can pick out its elements.  For example the last Maple  output indicated above is a set consisting of two elements: the first is the equation  y=,  and  the second element is the equation x=.  The way to select the first element is by entering  sol[1];  and pressing  [Return]. 

 

> sol[1];
 

y = -`/`(55, 34) (32)
 

 

The second element is obtained by entering  sol[2]; and pressing [Return]. 

 

> sol[2];
 

x = `/`(133, 68) (33)
 

 

Notice that these answers are given in the form of an equation.  There are two useful Maple commands for equations: lhs -left-hand side,  and rhs-right-hand side. 

 

> rhs(sol[1]);
 

-`/`(55, 34) (34)
 

> lhs(sol[1]);
 

y (35)
 

 

You may use subs to check your answer.
 

> subs(sol,{2*x-5*y=12,12*x+4*y=17});
 

{12 = 12, 17 = 17} (36)
 

Maple V has a procedure plot for graphing a function of one variable.  Thus if a function "f" is defined on an interval [a,b] you can plot it with one of the following commands. 

                                                  plot(f,a..b,options) 

or  

                                                  plot(f(x),x=a..b,options). 

 

We will illustrate this with a few examples.  First define a function. We will use the function   

                                                  f(x)=  sin 3x.
The exponential function  is obtained by using the built-in Maple V mathematical function
exp. 

 

> f :=exp(-x)*sin(3*x);
 

`*`(exp(`+`(`-`(x))), `*`(sin(`+`(`*`(3, `*`(x)))))) (37)
 

 

We now plot this function over the interval [0,3]. 

 

> plot(f,x=0..3);
 

Plot_2d
 

 

Next we can plot the same curve with the  x- and  y- axis labelled. 

 

> plot(f,x=0..3,y=-0.3..1);
 

Plot_2d
 

 

 

 

 

To construct square roots in Maple, type sqrt(x).  You may also choose the Typesetting:-mrow(Typesetting:-msqrt(Typesetting:-mrow(Typesetting:-mi(or Typesetting:-mrow(Typesetting:-mi((for nth roots) from the menu on the left (under the Expression tab).  Remember the assignment operator := to assign a name to a particular expression. 

 

> Typesetting:-mrow(Typesetting:-mi(
 

`*`(`^`(x, `/`(1, 2))) (38)
 

> Typesetting:-mrow(Typesetting:-mi(
 

`*`(`^`(9, `/`(1, 2))) (39)
 

> Typesetting:-mrow(Typesetting:-mi(
 

3.000000000 (40)
 

> Typesetting:-mrow(Typesetting:-mi(
 

`*`(`^`(7, `/`(1, 2))) (41)
 

> Typesetting:-mrow(Typesetting:-mi(
 

2.645751311 (42)
 

> Typesetting:-mrow(Typesetting:-mi(
 

`*`(`^`(`+`(x, 10), `/`(1, 2))) (43)
 

> Typesetting:-mrow(Typesetting:-mi(
 

Plot_2d
 

> Typesetting:-mrow(Typesetting:-mi(
 

Plot_2d
 

 

To construct exponential functions in Maple, type exp(x).   

 

> Typesetting:-mrow(Typesetting:-mi(
 

exp(x) (44)
 

> Typesetting:-mrow(Typesetting:-mi(
 

exp(4) (45)
 

> Typesetting:-mrow(Typesetting:-mi(
 

54.59815003 (46)
 

> Typesetting:-mrow(Typesetting:-mi(
 

54.59815003 (47)
 

> Typesetting:-mrow(Typesetting:-mi(
 

exp(`+`(`*`(`^`(x, 2)), 1)) (48)
 

> Typesetting:-mrow(Typesetting:-mi(
 

Plot_2d
 

 

To enter infinity in Maple, type   infinity.  Alternatively, you may choose the infinity symbol from the "Common Symbols" tab on the menu at the left.   

 

> Typesetting:-mrow(Typesetting:-mi(
 

1 (49)
 

> Typesetting:-mrow(Typesetting:-msubsup(Typesetting:-mo(
 

1 (50)
 

 

To enter pi in Maple, type  Pi.  Alternatively, you may choose the pi symbol from the "Common Symbols" tab on the menu at the left. 

 

> Typesetting:-mrow(Typesetting:-mi(
 

`*`(`+`(exp(Pi), `-`(1)), `*`(exp(`+`(`-`(Pi))))) (51)
 

> Typesetting:-mrow(Typesetting:-mi(
 

.9567860817 (52)
 

> Typesetting:-mrow(Typesetting:-mi(
 

exp(`/`(`*`(sin(`*`(`^`(x, 2)))), `*`(`+`(`*`(2, `*`(x)), 5)))) (53)
 

> Typesetting:-mrow(Typesetting:-mi(
 

`*`(`+`(`/`(`*`(2, `*`(cos(`*`(`^`(x, 2))), `*`(x))), `*`(`+`(`*`(2, `*`(x)), 5))), `-`(`/`(`*`(2, `*`(sin(`*`(`^`(x, 2))))), `*`(`^`(`+`(`*`(2, `*`(x)), 5), 2))))), `*`(exp(`/`(`*`(sin(`*`(`^`(x, 2))... (54)
 

> Typesetting:-mrow(Typesetting:-mi(
 

`+`(`*`(`+`(`-`(`/`(`*`(4, `*`(sin(`*`(`^`(x, 2))), `*`(`^`(x, 2)))), `*`(`+`(`*`(2, `*`(x)), 5)))), `/`(`*`(2, `*`(cos(`*`(`^`(x, 2))))), `*`(`+`(`*`(2, `*`(x)), 5))), `-`(`/`(`*`(8, `*`(cos(`*`(`^`(...
`+`(`*`(`+`(`-`(`/`(`*`(4, `*`(sin(`*`(`^`(x, 2))), `*`(`^`(x, 2)))), `*`(`+`(`*`(2, `*`(x)), 5)))), `/`(`*`(2, `*`(cos(`*`(`^`(x, 2))))), `*`(`+`(`*`(2, `*`(x)), 5))), `-`(`/`(`*`(8, `*`(cos(`*`(`^`(...
(55)