Basic Maple Tutorial

The purpose of this document is to introduce some basic Maple commands, syntax, and programming concepts for Maple V Release 9.5.

1 Some Basic Maple Commands

After you log on to your terminal and access Maple, you will get a window containing a ”prompt” > where you can immediately begin entering Maple commands. If you wanted to multiply the numbers 247 and 3756, you would enter

   > 247*3756;

927732

NOTE: Every Maple V command must end with either a semicolon or a colon. If a command is ended with a colon then the calculation will be made but no output will be printed. When a semicolon is used the calculation will be made and the result will be printed.

If a colon were used on the previous command, the result would look like the following:

   > 247*3756:

If the semicolon or colon is omitted from a command, the command will not execute. Maple will respond as follows:

   > 247*3756

   Warning, premature end of input

However, because Maple allows full screen editing, you can go back to the line where the problem occurred and correct it.

2 Arithmetic

The basic arithmetic operations of addition, multiplication, division, and exponentiation are recognized in Maple V by the following symbols:

+ and - add and subtract
* and / multiply and divide
ˆ or **  raise to a power

You can easily add two numbers

   > 253+7775;

8028

or add two fractions.

   > 25/27 + 3/51;

\frac{452}{459}

Operations can be performed on previous results by using the percent symbol %. The next calculation multiplies the previous result by 23.

   > 23 * %;

\frac{10396}{459}

Double percent marks refers to the next to last result.

   > 23 * %%;

\frac{10396}{459}

You can raise a number to a power as follows.

   > 3^7;

2187

   > 3**7;

2187

Like other computer algebra systems, Maple uses exact arithmetic. For example, if you divide two integers Maple V will return the exact answer.

   > 3235/7478;

\frac{3235}{7478}

The Maple function evalf will give the following decimal representation.

   > evalf(%);

0.4326023001

3 Defining Variables and Functions

You can assign a value or a function to a variable by using the colon-equal notation ”:=”

   > y := 5;

y := 5

This means that the variable ”y” has been assigned the value 5 and will have this value throughout the session until it is assigned another value or its value is unassigned. To display the current contents of a variable, we enter the variable’s name followed by a semicolon.

   > y;

5

We can perform basic calculations with the unassigned variable such as

   > 4*y + 5;

25

Assigning a variable to itself enclosed in single quotes unassigns the variable.

   > y := 'y';

y := y

   > y;

y

There are two ways to define and work with functions. One way is to define the function as an expression. For the function f(x) = x^{2}, this would be done by entering

   > f := x^2;

f := x^{2}

This definition can be checked by entering:

   > f;

x^{2}

The Maple V procedure subs allows expressions such as this to be evaluated.

> subs(x=5,f);

25

The problem with defining functions as expressions is that standard functional notation, such as f(5), is not understood by Maple V and results in nonsense.

> f(x);

x(x)^{2}

> f(5);

x(5)^{2}

If you wish to use standard functional notation, you must enter the function using the minus-greater than notation ”->”, made by typing the ”minus sign” followed by the ”greater than” sign. For example:

> f := x -> x^2;

f := x → x^{2}

> f(x);

x^{2}

> f(5);

25

4 Case Sensitivity

Maple is case sensitive - it distinguishes between upper and lower case characters. If you want to factor the polynomial x^{2} + 2 x + 3, you would enter

> factor(x^2 - 2*x - 3);

(x + 1) (x − 3)

However, the following command results in nonsense.

> FACTOR(x^2 - 2*x - 3);

FACTOR(x^{2} − 2 x − 3)

Even one letter not being the correct case returns nonsense.

> Factor(x^2 - 2*x - 3);

Factor(x^{2} − 2 x − 3)

5 Algebra

Here are some of the important Maple V algebra commands:

Maple Command  What it does
expand  Expands expressions
simplify  Simplifies expressions
factor  Factors expressions
solve  solves equations

Some examples of these commands follow:

> expand( (x^2 + 1) * (x + 1) * (x + 3) );

x^{4} + 4 x^{3} + 4 x^{2} + 4 x + 3

> factor(%);

(x^{2} + 1) (x + 1) (x + 3)

> sol := solve( x^3 - 9*x^2 + 20*x = 0, x);

sol := 0, 5, 4 The last equation has 3 roots, and we can pick a particular one by entering

   > sol[1];

0

or

   > sol[3];

4

6 Graphing

Maple has the ability the graph functions and equations. The plot command is the basic command used for plotting graphs. To demonstrate, suppose we enter the function

   > f := x^2;

f := x^{2}

The following command will graph this function (note the quotes around the sentence in the title option).

   > plot(f, x = -3..3, y = -5..10, title = "Graph of y = x^2");

Figure 1: Maple graph of y = x^{2}

In the previous statement, the first parameter is the function that will be graphed. The second and third parameters are the ranges on the x and y axis over which we want our graph to be plotted.

Maple has the ability to graph multiple graphs. Suppose we enter the function

   > g := x^3;

g := x^{3}

The following commands set up and store the plots for these graphs in the variables p1 and p2. An important fact to remember is to end these commands with a colon :. If you end the command with a semicolon, all the data points generated to plot the graph will be displayed.

   > p1 := plot(f, x = -3..3, y = -9..9, color = blue):
   > p2 := plot(g, x = -3..3, y = -9..9, color = green):

Using the display command, we can graph both functions. The display is in a package of routines called plots, which we read into the session by entering

   > with(plots);
   Warning, the name changecoords has been redefined

[animate, animate3d, animatecurve, arrow, changecoords, complexplot, complexplot3d, conformal, conformal3d, contourplot, contourplot3d, coordplot, coordplot3d, cylinderplot, densityplot, display, display3d, fieldplot, fieldplot3d, gradplot, gradplot3d, graphplot3d, implicitplot, implicitplot3d, inequal, interactive, listcontplot, listcontplot3d, listdensityplot, listplot, listplot3d, loglogplot, logplot, matrixplot, odeplot, pareto, plotcompare, pointplot, pointplot3d, polarplot, polygonplot, polygonplot3d, polyhedra supported, polyhedraplot, replot, rootlocus, semilogplot, setoptions, setoptions3d, spacecurve, sparsematrixplot, sphereplot, surfdata, textplot, textplot3d, tubeplot]

This command now plots both graphs on the same axes.

> display([p1, p2], title = "Graphs of y = x^2 and y = x^3");

Figure 2: Maple graphs of y = x^{2} and y = x^{3}

7 Help File

You can obtain the help file regarding most Maple functions and statements by entering ? name where name is the function or statement you desire help on. To see help on factor, you can enter:

> ?  factor

Help can also be obtain using the help option on the toolbar.