## Running Maple

To start MAPLE 11 CLASSIC WORKSHEET, click the Start button on the bottom left hand corner of your screen, then select MAPLE11 from the popup menu, then select MAPLE11 CLASSIC WORKSHEET with the yellow icon.

When you want to save your work, select the disk button on the toolbar.  You will be prompted for a file name.

To exit Maple, simply select the "exit" option under the "file" submenu in the top left corner of the Maple window.

## Introduction

You are about to undertake a tutorial that will guide you through portions of the symbolic manipulation package called Maple. Maple is a powerful program that can be used interactively to do a wide variety of things ranging from tedious algebra to plotting three-dimensional graphics. This tutorial is intended to provide you with an overview of some of Maple's capabilities, as well as warn you about a few of the common pitfalls. In the material that follows you will repeatedly encounter text in the form shown below:

> 1 + 1;

2

When text appears like this, the entry in bold following the > sign indicates items that should be entered by you at the Maple cursor. The text that follows is the output produced by Maple in response to your input. In the operation above, for instance, Maple responded to 1 + 1 by performing the addition correctly. Good !

Every Maple command must end with a semicolon as shown in the example above (or a colon if you don't want output displayed). For example, for the sum 1 + 1, enter the following:

> 1 + 1;

to which Maple responds with:

2

The use of a semicolon is crucial in Classic Maple, but not in the regular Maple. Until you enter a semicolon, Classic Maple assumes that you are still in the process of entering a single command. For example, the command above is equivalent to,

> 1
>
+ 1;

2

Alternately,

> 1
>
+
>
1
>
;

2

In either case, you can recognize that the semicolon behaves as a cue for Maple, indicating that the expression is ready for evaluation. This is a useful feature when dealing with long expressions that require multiple lines of input. You can also combine two commands one one input line, as long as you use the semicolon.

> 1+1;2+2;

2
4

## Arithmetic

We have encountered addition within Maple above. Analogously, subtraction follows simply as:

> 5 - 2;

with output,

3

Multiplication requires an asterisk *,

> 5*5;

25

As you might expect, division is signified by a backslash /,

> 25/5;

5

To raise something to a power, proceed as follows:

> 8^2;

64

Note that if you forget a semicolon, you'll see a warning message,

> 10^20
warning, premature end of input

If you ignore the warning...

> 10^20
>
10^20
Error, unexpected number

Here Maple interprets your input as 10^20 10^20, which is meaningless.  But note that the error message is not particularly helpful.  This is MAPLE's biggest drawback.

> 10^20;

100000000000000000000

Another interesting feature of Maple is the factorial function. You will remember that 5! = 5*4*3*2*1. Try it out.

> 3!;

6

Let's try something that puts Maple through its paces,

> 1000!;

4023872600770937735437024339230039857193748642107146325437999104299385123986290\
2059204420848696940480047998861019719605863166687299480855890132382966994459099\ 7424504087073759918823627727188732519779505950995276120874975462497043601418278\ 0946464962910563938874378864873371191810458257836478499770124766328898359557354\ 3251318532395846307555740911426241747434934755342864657661166779739666882029120\ 7379143853719588249808126867838374559731746136085379534524221586593201928090878\ 2973084313928444032812315586110369768013573042161687476096758713483120254785893\ 2076716913244842623613141250878020800026168315102734182797770478463586817016436\ 5024153691398281264810213092761244896359928705114964975419909342221566832572080\ 8213331861168115536158365469840467089756029009505376164758477284218896796462449\ 4516076535340819890138544248798495995331910172335555660213945039973628075013783\ 7615307127761926849034352625200015888535147331611702103968175921510907788019393\ 1781141945452572238655414610628921879602238389714760885062768629671466746975629\ 1123408243920816015378088989396451826324367161676217916890977991190375403127462\ 2289988005195444414282012187361745992642956581746628302955570299024324153181617\ 2104658320367869061172601587835207515162842255402651704833042261439742869330616\ 9089796848259012545832716822645806652676995865268227280707578139185817888965220\ 8164348344825993266043367660176999612831860788386150279465955131156552036093988\ 1806121385586003014356945272242063446317974605946825731037900840244324384656572\ 4501440282188525247093519062092902313649327349756551395872055965422874977401141\ 3346962715422845862377387538230483865688976461927383814900140767310446640259899\ 4902222217659043399018860185665264850617997023561938970178600408118897299183110\ 2117122984590164192106888438712185564612496079872290851929681937238864261483965\ 7382291123125024186649353143970137428531926649875337218940694281434118520158014\ 1233448280150513996942901534830776445690990731524332782882698646027898643211390\ 8350621709500259738986355427719674282224875758676575234422020757363056949882508\ 7968928162753848863396909959826280956121450994871701244516461260379029309120889\ 0869420285106401821543994571568059418727489980942547421735824010636774045957417\ 8516082923013535808184009699637252423056085590370062427124341690900415369010593\ 3983835777939410970027753472000000000000000000000000000000000000000000000000000\ 0000000000000000000000000000000000000000000000000000000000000000000000000000000\ 0000000000000000000000000000000000000000000000000000000000000000000000000000000\

0000000000000000000000000000000000000000

Ugly ! What happens if you divide the above number by 999! ? The answer is extremely simple...you can do it in your head.

Maple knows about certain special numbers such as E and Pi. For example, if we wish to compute 2*Pi we enter,

> Pi * 2;

2 p

Case matters. For example, pi is the just the Greek symbol p, whereas Pi  is the number 3.14159... that we're used to.  Incidentally, for lots of interesting information on Pi, peek into Pi through the ages Note that Maple does not evaluate the expression explicitly. Rather than introduce an approximate numerical value for Pi, it carries the constant along instead. To force Maple to evaluate the expression numerically enter,

> evalf(Pi * 2);

6.283185308

evalf explicitly evaluates expressions as decimal numbers. Let's drive a little harder. How many decimal places do you know Pi to ? Let's request Maple for Pi to a 1000 decimal places. How do you suppose this number is calculated ? How do we know it is right ? explicitly evaluates expressions as decimal numbers. Let's drive a little harder. How many decimal places do you know Pi to ? Let's request Maple for Pi to a 1000 decimal places. How do you suppose this number is calculated ? How do we know it is right ?

> evalf(Pi, 1000);

3.14159265358979323846264338327950288419716939937510582097494459230781640628620 8998628034825342117067982148086513282306647093844609550582231725359408128481117 4502841027019385211055596446229489549303819644288109756659334461284756482337867 8316527120190914564856692346034861045432664821339360726024914127372458700660631 5588174881520920962829254091715364367892590360011330530548820466521384146951941 5116094330572703657595919530921861173819326117931051185480744623799627495673518 8575272489122793818301194912983367336244065664308602139494639522473719070217986 0943702770539217176293176752384674818467669405132000568127145263560827785771342 7577896091736371787214684409012249534301465495853710507922796892589235420199561 1212902196086403441815981362977477130996051870721134999999837297804995105973173 2816096318595024459455346908302642522308253344685035261931188171010003137838752 8865875332083814206171776691473035982534904287554687311595628638823537875937519
57781857780532171226806613001927876611195909216420199

Make sure you understand the above instruction by determining E to a 100 decimal places. To compute E, you need to use the exp() function, as exp(1);

evalf works in other situations as well. In the following, we will use it to obtain approximate values for the fraction:

> 2 + 1/3;

7/3

To evaluate the fraction numerically, we will use evalf but this time with the symbol % which Maple recognizes as shorthand representing the expression on the previous line.

> evalf(%);

2.333333333

Maple permits the definition of variables. To define a variable called emu and assign to it a value of 12 we proceed as follows.

> emu := 12;

emu := 12

Here := signifies assigned to. We can now query Maple for the value of emu,

> emu;

12

or, we can multiply emu by 10,

> emu * 10;

120

Maple has an excellent Help capability.  To access it, you need to click on the Help button on the top right hand side of the Maple window.  You can then search the Help database by topic, by text, or complete MAPLE's own tutorial.

## Algebra and Plotting

Almost everything we have done so far we could have done just as fast without ever using Maple. To really begin to take advantage of Maple we move on to some more advanced topics. Lets look at some symbolic calculations using Maple, where we tinker with variables without defining their numerical
values,

> (x + 2*y)^2;

```
2
(x + 2 y)
```

Alternately, using shorthand % to refer to the last result, we can expand the expression,

> expand(%);

```
2          2
x + 4xy + 4y
```

Another example:
> (x*y - y^2) / (x - y);

```            2
x y - y
--------
x - y                                     ```

Maple does not simplify expressions automatically. In the previous example, for instance, as the numerator equals y*(x - y), the expression reduces to just y. For Maple to perform such a simplification, it must be explicitly requested,

> simplify(%);

y

where the " again refers to the previous result. Having warmed up with some simple algebra, we are in shape to attempt solving algebraic equations. First, consider our old friend the quadratic equation. To make the steps somewhat
clearer, we use the assigned to := operation to define a variable that will be our abbreviation for a quadratic equation,

> eland := x^2 + 8*x + 12;

```       2
eland := x + 8 x + 12                                     ```

To solve the equation, eland = 0, enter the following:

> solve(eland = 0, x);

-2,-6

where x within the solve command specifies the variable to be solved for. Are these in fact solutions to the quadratic equation ? We can use Maple to carry out the check very easily. For example, substituting x = -6 into eland,

> subs(x = -6, eland);

0

Therefore, -6 is a solution to eland = 0. Try other choices for x to see if they are solutions.

Maple can also solve sets of algebraic equations. In the following we'll use this capability to determine the intersection between two lines. As before, to keep things tidy, we will define variables as abbreviation,

> eq1 := y = a*x + c;

eq1 := y = ax + c

> eq2 := y = b*x + d;

eq2 := y = bx + d

These commands should strike you as a little odd. So far we have used  the assignment operation := to introduce variables as abbreviations for expressions. Here, on the other hand, variables eq1 and eq2 are abbreviations for entire equations. To determine intersections between the two, we need to solve the equations simultaneously. Maple does this really well:

> solve({eq1, eq2}, {x, y});

```
c - d            ad - cb
{x = - ------- ,    y = ---------}
a - b             a - b
```

Easy ! Observe that we have exploited Maple's ability to work with sets to use solve on multiple equations involving multiple unknowns. Within Maple a set of objects is defined by enclosing the objects in a pair of curly brackets { }. With this in mind, the solve command can be seen to instruct Maple to solve the set of equations {eq1, eq2} for the set of unknowns {x, y}.

Solutions to simultaneous equations are always returned as a list {unknown 1, unknown 2 ...}.  We often want to extract the solution to just one unknown, so we can do further algebraic manipulations. For this purpose, the following trick is helpful

>soln := solve({eq1,eq2},{x,y}):

>soln[1];

c - d
x = -  -------
a - b

>soln[2];

y = ---------
a - b

This lets you see the solutions one at a time.  MAPLE seems to give the solutions in a random order - when you run this tutorial you might find solution[1] is the equation for y, and solution[2] is the equation for  x.  I guess they do this to make life more interesting.

We can substitute these solutions into new equations

> eq3 := z = x^2 + y^2:

>subs(soln[1],eq3);

2
(b-d)            2
z = ------     + y
2

( a - b)

You can substitute more than one variable into an equation using the syntax subs({soln[1],soln[2]},eq3);

You can also use subs() to plug numbers into an equation.  For example

> subs({a=1,b=2,c=3,d=4},soln[1]);

x=1

Maple's equation solving is fantastic and we will make a great deal of use of it in EN3.  It can be a frustrating function to use, however, because if you make a mistake while typing in one of the equations, Maple will sometimes just sit there and won't tell you what's going on.  For example, try the following

>eq1 := a*x + b*y + c*z = p:
>
eq2 := a*x + b*y + c*z = q:
>
eq3 := g*x + h*y + i*z = r:
>
solve({eq1,eq2,eq3},{x,y,z});

We get nothing...  That's because the system of equations actually has no solution.  In eq1 and eq2 the left hand sides are identical, but the right hand sides are different.  So Maple is stuck.  When you solve a complicated set of equations with lots of variables, a small typo can cause this to happen.

However, if we try

>eq1 := a*x + b*y + c*z = p:
>
eq2 := d*x + e*y + f*z = q:
>
eq3 := g*x + h*y + i*z = r:
>
solve({eq1,eq2,eq3},{x,y,z});

then Maple has no trouble at all...

Sometimes the equation of interest may not have a closed-form solution. In such cases, Maple can be used to find numerical solutions. For instance, what if we were interested in finding values of x at which cosh(x) = 2*x. To solve this equation numerically:

> fsolve(cosh(x)=2*x, x);

.5893877635

There are more than one solution to this equation, and fsolve will report the first one it encounters. Depending on the version of MAPLE you are using, you may get a different answer. To check whether this is indeed the solution, find the hyperbolic cosine of this number:

> cosh(%);

1.78775527

Dividing this result by 2 should return the original number,

> %/2;

.5893877635

Clearly, the equation is satisfied.

Alternately, we can check the validity of the solution graphically. Consider the curve y = cosh(x) and the line y = 2*x. The two intersect at solutions to the equation cosh(x) = 2*x. To check that the intersection indeed coincides with the solution determined previously, we will use Maple to plot the two over the interval -3 to 3. First, the function cosh(x):

> plot(cosh(x), x = -3..3);

Here the two dots .. separating the limits of the plot are not accidental. These are required by Maple syntax.

If you click on the plot, you will find that you change its size and axes using the plot bottons that appear on the toolbar. Right clicking on it brings up a menu which lets you change various properties of the plot, such as line thickness.

Next, we proceed to plot the functions simultaneously to examine their intersection,

> plot({cosh(x), 2*x}, x = -3..3);

(There are two dots between the -3 and 3 again)

Observe that the solution determined numerically does match an intersection. In order to touch up the plot, you might want to add a title and axes labels. To do that, enter instead:

> plot({cosh(x), 2*x}, x = -3..3, title = `solution to cosh(x)=2 x`, labels = [`x`, `y`]);

Note that you have to use the weird little backwards quotes positioned way up on the top left hand corner of the keyboard.

Adding labels to plots in maple is a big pain.  This is the second major limitation of MAPLE - you simply can't easily produce publication quality graphs.  I usually just have MAPLE produce a bare plot, with no labels, and then export the plot in some format that I can paste into a proper illustrator program.

Maple has extensive plotting capabilities. For a glimpse of these the Maple picture gallery at the NCSU   Maple Archive is highly recommended. To keep your expectations from running overboard, on the other hand, an example of the sort of graphics Maple is likely to have trouble with. Here we will consider a single example: a three dimensional plot of the function z = sin(x)*sin(y),

> plot3d(sin(x) * sin(y), x = -4*Pi ..4*Pi, y = -4*Pi..4*Pi);

Observe that the grid used is far too coarse to display the function accurately. Moreover, unlike the two dimensional plots we worked through earlier, the command does not add axes to the plot. We can fix both problems by supplementing plot3d with additional instructions, grid[m, n] to add m and n grid lines along the x and y axes respectively, and axes = FRAME to switch on axes,

> plot3d(sin(x) * sin(y), x = -4*Pi..4*Pi, y = -4*Pi..4*Pi,grid = [60, 60], axes = FRAME);

Note that you can you can rotate the plot by clicking on the window and dragging with your mouse.  Try it!

Maple can also do pretty contour plots.  But to access them we need to load a Maple package, which contains some special routines. We load the package by typing

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

[animate, animate3d, animatecurve, changecoords, complexplot, complexplot3d, conformal, contourplotm, contouplot3d, coordplot, coordplot3d, cylinderplot, densityplot, a bunch of other plots that I'm too lazy to type here...]

We can now do all kinds of new plots.  Try

>contourplot(sin(x)*sin(y),x=-2*Pi..2*Pi,y=-2*Pi..2*Pi);

The contourplot function has many options that change the appearance of the plot.  It's worth searching the help database for contourplot to find out what they are.  For example

>contourplot(sin(x)*sin(y),x=-2*Pi..2*Pi,y=-2*Pi..2*Pi,filled=true);

produces filled contours, which look much nicer if you have a color printer.  You can change the colors for example to make the maxima red, and minima blue, you can use

>contourplot(sin(x)*sin(y),x=-2*Pi..2*Pi,y=-2*Pi..2*Pi,filled=true,coloring=[red,blue]);

You can also have MAPLE make movies (what I really want to do is direct...).  For example try

>animate3d(sin(x-t)*sin(y+t),x=-2*Pi..2*Pi,y=-2*Pi..2*Pi,t=0..2*Pi,frames=30);

This isn't going to win us an Oscar.  But that's because we didn't start the animation.  Click the blue right arrow button (the one just to the right of the square box) to start the movie

You should then see this...

You can save the file as an animated GIF (to insert into a web page, or a powerpoint presentation) by right clicking the window.  Create some nerdy MAPLE graphics for your webpage today!!

## Calculus

Maple is highly skilled with calculus as well. For instance, differentiation requires the simple command,

> diff(x^2, x);

2 x

where x within the diff command specifies differentiation with respect to x. No surprises here. Things get a little more interesting when we use Maple to differentiate the function x*y with respect to x,

> diff(x*y,x);

y

Clearly, Maple can carry out partial derivatives as well. Taking this a step further, let's differentiate x*y first with respect to x and then with respect to y,

> diff(x*y, x, y);

1

this can be recognized as the partial derivative of x*y, first with respect to x then with respect to y. Maple can carry out integrals as well. To explore this ability, we'll attempt to integrate 2*x,

> int(2*x,x);

2
x

which helps us verify both, the integration here, as well as the differentiation performed earlier. We might need to integrate this function between specified limits. Taking the limits to be 0 and 5, for instance,

> int(2*x, x = 0..5);

25

Finally, for something a little uglier, we'll integrate the exponential function,

> int(exp(-x), x = 0..infinity);

1

Although Maple has an array of predefined functions such as sin(x) and exp(x), occasionally you will find it useful to define your own functions. To define the function sin(t)*exp(-omega*t), for example, proceed as follows:

> f(t) := sin(t) * exp(-omega * t);

f(t) := sin(t) exp(-w t)

With this definition, you have added to Maple's list of functions the new function f(t). In all future operations, it will behave just as any of the predefined functions. For example, to differentiate the function with respect to t you would enter,

> diff(f(t), t);

cos(t) exp(-w t) - sin(t) w exp(-w t)

Similarly, integration would require simply,

> int(f(t),t);

```
exp(- w t) cos(t)   w exp(- w t) sin(t)
- --------------------- - ---------------------------
2                          2
w  + 1                 w  + 1
```

You can also find the minimum and/or maximum of a function:
> minimize(x^2-3*x+y^2+3*y+3);

-3/2

Include the word 'location in the argument list, and it will tell you where the minimum or maximum occurs.

>minimize(x^2-3*x+y^2+3*y+3, location);

-3/2, {[{y = -3/2, x = 3/2}, -3/2]}

You can prescribe a range with which the maximum or minimum can be found.

> maximize(exp(-x),x=0..100);

1

Let's try a more complicated function and attempt to find  the minimum value of sin^2(theta)+cos(theta) in the range 0<theta<2*Pi.

> minimize((sin(theta)^8+cos(theta)),theta=0..2*Pi);

minimize(sin(theta)^8+cos(theta),theta = 0 .. 2*Pi)

The fact that Maple just returned our original statement means that it cannot handle the complicated function. But  complicated maximization and minimization can be done with commnads from the Optimization package. This package is an extra set of functions that Maple provides. To access the package, type

> with(Optimization);

[ImportMPS, Interactive, LPSolve, LSSolve, Maximize, Minimize, NLPSolve, QPSolve]

The functions Maximize and Minimize (note thea upper case M) find maxima and minima numerically, and can deal with more complicated functions. We can use Minimize, for example, to find the  minimum value of sin^2(theta)+cos(theta) in the range 0<theta<2*Pi.

> Minimize((sin(theta)^8+cos(theta)),theta=0..2*Pi);

[-1., [theta = 3.14159265358979312]]

Maple returns the minimum value of the function and the location at which it occurs--even though we did not add the word location, as was required with the minimize (lower case m) command.

The Upper case-M commands can handle more than one variable. Here we find the minimum of the function (x-1)^2+(x-y)^2 in the ranges -1<x<-1, and -1<y<-1.

> Minimize((x-1)^2 + (x-y)^2,x=-1..1,y=-1..1 );

[0., [x = 1., y = 1.]]

And if we want to look for the minimum of this same function but are only interested in values of x and y for which x*(1+y^2) is greater than or equal to 8, we can do this by adding the constraint x*(1+y^2)>=8 to the command as follows:

> Minimize((x-1)^2 + (x-y)^2 , {x*(1+y^2)>=8});

[0.517128660129716033,[x = 1.62561974988122571, y = 1.98020202339228080]]

## Clearing variables using the restart command

Type

> emu;

12

Remember that we defined emu to have the value 12?  No?   Maple, like the proverbial elephant, never forgets (unless you quit MAPLE).  When you're solving a problem using MAPLE you often assign values or formulas to many variables.  Then, when you want to move on to another problem, you need to clear these assignments.  To clear all assignments, just type

> restart;

Then, just to check

> emu;

emu

It is a good idea to start every worksheet with a restart;  command to clear any defined variables from a previous session run in the same window.

## Printing

A remaining issue is the question of printing Maple graphics or worksheets. To print an entire worksheet, just click on the worksheet you'd like to print, and then hit the print button on the Maple toolbar.   You can send the output to different printers - the first printer in the list is the one on the left hand side of the computer room; the second is the printer on the right.  You can also create a pdf file using Acrobat PDFwriter.

Finally, you may want to include a maple graph in a report you are writing - say a Microsoft word document.  To do this, you can copy the graph (click on it and use the clipboard icon from the toolbar or right click and select copy from the po-up menu. The, you can  paste the graph directly into your Word or other document.

If you have a lot of graphs to rpint, you might want to set up Maple so that each graph appears in its window, rather than in the the worksheet. To do this,  click the File pull down menu, and select Preferences...

Click on the plotting tabe and  then select Window int the Plot Display catagory. Now, plot your graph in the usual way: you will find the graph appears in a separate window in the MAPLE interface. To print a graph in its own window, click on this window, and then follow the instructions for printing worksheets (File, Print..., etc) that were outlined in the preceding paragraph.

In this tutorial we have considered a range of Maple commands to help you get started with the package. These are, however, only a tiny subset of its capabilities. To proceed from here, depending on your needs, you could either work through some of the more advanced Maple tutorials available on the web (or Maple's own tutorial), or invest in a book on Maple. Once you are comfortable with Maple's basic capabilities, its probably best to aim to be aware of its more advanced aspects rather than attempting to master them all at once, returning to specific aspects only when the need arises.

Good luck!