>

day1.mws

AN INTRODUCTION TO MAPLE: Basic computations and plotting

Math 242 (sections 1 and 3) -- Spring 1998

Matt Miller (miller@math.sc.edu)

Douglas Meade (meade@math.sc.edu)

>

Objectives

>

What is Maple?

Much of your mathematical background has probably been focused on developing the ability to solve equations and explore functions. The sophisticated manipulation of symbols and expressions that you use to solve equations and investigate functions can also be performed by software packages called computer algebra systems (CAS). A CAS can be use to generate the exact symbolic solutions you obtained by hand, the numerical approximations you found using a calculator, and the graphs you have drawn. Maple is one of several CAS's; other major examples are Mathematica, Macsyma, Derive, and MathCad.

>

How will Maple be used in this course?

Our first, and largest, use of Maple will be the graphical display of functions, including the solution of one or more differential equations. In fact, this graphical information is often more useful than a formula for the exact solution. Sometimes we will use Maple just for demonstrations during regular class; other times students will turn to the computers as needed to carry out caculations, both during class and outside of class. You will also be expected to use Maple on the homework and even parts of the exams.

Note: You might find Maple of use in other courses!

>

Documentation and Online Help

The on-line help for Maple is very good. The help pages describe the syntax of each command, a brief description of the algorithm that has been implemented, and a few examples illustrating the use of the command. To obtain help on the command func , type: ?func . To close a help window use the small button in the top left corner; to simply turn it into a small icon for later reference use the dot in the top right corner (this works for any window actually, and the box next to it opens a window up to full size). The Help Browser, an interactive interface to the entire Maple help system, can be brought up by clicking on Help , found at the top right of the Maple window. To get started trying activating Balloon Help under the Help Browser (this will be useful when you start to experiment with the Menu Bar).

>

Getting Started

You have already learned how to open up a worksheet. After Maple is opened, position the cursor arrow on the menu item File and click the left button once. You can select New to obtain a fresh, empty worksheet. Or you can select Open to choose an existing worksheet (the name will always end with .mws), either by double clicking on the name or by selecting the name and then Load. Once in a worksheet the current location is marked by a vertical bar. You can move around by moving the mouse and then clicking the left button once, by using the arrow keys, or by using the scroll bar up and down arrows on the right side of this window followed by finer adjustment with the mouse. A command (marked by the > symbol with words in bright red) is executed by positioning the cursor anywhere on the desired line and pressing the return key. Briefly: use the mouse to position yourself, and the return key to actually do something.

It is probably a good idea to begin EVERY worksheet that you create with the following two commands.

> restart;

> with(plots):

Warning, the name changecoords has been redefined

Note for Math 242 (Differential Equations)

When working with differential equations, it is advisable to add the following command to the startup commands.

> with( DEtools ):

>

>

Information about these commands can be found in the on-line help: ?plots , ?restart .

>

Basic Facts

Maple is a computer language; it cannot read your mind. You need to learn how to communicate with Maple.

The fundamental symbols:

The standard mathematical functions are denoted by their standard names:
+ (plus) , - (minus) , * (times) , / (divided by) , ^ (raised to the power) , sin , cos , tan , abs , sqrt , ...

>

In the following lines, use paper and pencil to first predict what you think Maple will do. Then execute the command and see what actually happens!

> number:= 4 * 6 + 12 / 6 - 1 ;

number := 25

> power:= (-3)^3 ;

power := -27

> abs( % );

27

> Pi ;

Pi

> v:= sin( Pi / 4 ) :

> w:= v^2 ;

w := 1/2

> v;

1/2*sqrt(2)

> tan( -Pi / 2 ) ;

Error, (in tan) numeric exception: division by zero

> 3 / ( 5 - sqrt( number ) ) ;

Error, division by zero

>

Now enter some commands of your own! To produce the input prompt > use the [> button in the Menu Bar. Be generous with the space bar to make your commands easy to read, and to edit (modify after the fact). Go back to the tangent calculation above (remember how to reposition the cursor!) and change it to compute the tangent of Pi/3 .

>

Next we define some functions for later use.

> f := sin( 2 * x ) ;

f := sin(2*x)

> g := 4 * x^2 ;

g := 4*x^2

> h:= 0.25 * cos ( 8 * x ) ;

h := .25*cos(8*x)

> p:= f * g ;

p := 4*sin(2*x)*x^2

> q:= f * h ;

q := .25*sin(2*x)*cos(8*x)

> s:= f + h ;

s := sin(2*x)+.25*cos(8*x)

>

Plotting

Graphs of functions are produced by the plot command. In its simplest form, plot needs to know the function to be plotted and the range of values for the independent variable. Note that a..b is Maple's way of describing the interval [a,b]. Observe that I have placed signed titles on some of these graphs. When you actually print plots to turn in with your homework, they MUST have a title and signature [by your initials or last name]. Again, try to predict the output before tapping the return key!

> plot( 3 * t - 2 , t = -3 .. 10 ) ; # WAIT FOR THE GRAPH TO APPEAR!!

[Maple Plot]

> plot( f , x = -Pi .. 2 * Pi ) ;

[Maple Plot]

> plot( p , x = -6 .. 8 , title = ` f * g [by DM] ` );

[Maple Plot]

>

These plots are nice, but what information do they convey? Let's concentrate on the plot of p, that is f*g. Position the cursor on a point on the graph and click the left button. The numbers that appear on the upper-left corner are the coordinates of the current location of the cursor. Use this technique to identify the global maximum and minimum values of f*g on the interval [-6, 8], and the x-values at which these are found. Where do other (local) minima and maxima occur? Can you guess the exact values?

> plot(2 * u^3 + 4 * u - 5 , u = -10 .. 7 , title = ` cubic function [by DM] ` ) ;

[Maple Plot]

>

Where does the cubic function cross the u-axis? Maybe it would be helpful to cut down the plotting interval from [-10, 7] to [-1, 3], or even narrower, say to [0, 1.5]. Try it. Can you find the u-intercept to 2-decimal point accuracy by this process? It is a powerful method, which we call ZOOMING IN.

> plot( s , x = 0 .. 3 * Pi );

[Maple Plot]

> plot( q , x = -1.2 .. 1.2 ) ;

[Maple Plot]

>

Can you explain why the graphs of s and q look the way they do?

>

Housecleaning

As you scroll up and down you may find that old plots take time to be redrawn and aren't really needed anyhow. If you click on a plot you will box it (and for printing purposes this box can be resized by dragging on the sides or corners). To remove it hold down the shift key and press delete.

>

Graphing Several Functions in One Plot

> plot( { p , g , -g } , x= -6 .. 8 );

[Maple Plot]

>

Can you identify the three different plots?

What about the next one?

> plot( { f , h , s }, x=0 .. 3*Pi );

[Maple Plot]

Can you explain the little bumps that appear inside the large dips in the graph of s?

>

Plotting A Discontinuous Function

The tangent function is well-known to all of us. In particular, we know that the graph of y = tan(x) has vertical asymptotes at all odd multiples of Pi/2 . Let's see how Maple handles this.

> f := tan(x);

f := tan(x)

Note: This definition completely replaces the previous definition of f.

> plot( f , x = -Pi .. Pi );

[Maple Plot]

>

Is this what you expected to see?

Why does the graph look like this?

What can be done to improve the appearance of the plot?

>

The key is to restrict the vertical range of the plot and tell Maple that the function is discontinuous.

> plot( f, x = -Pi .. Pi , -10 .. 10 );

[Maple Plot]

> plot( f, x = -Pi .. Pi , -10 .. 10 , discont=true );

[Maple Plot]

>

> plot ( ( 1 - 0.4*t^3) / ( 1 - t^2 ) , t = -3 .. 5 , -10 .. 10 ,

> discont = true, title = `vertical asymptotes [by DM]` ) ;

[Maple Plot]

>

This technique is very useful for any function that has vertical asymptotes.

>

Congratulations

You have just completed your first Maple worksheet. If you wish to save it select File in the menu bar, and then either Save (which will destroy the original version of day1.mws) or Save As... (which will leave day1.mws untouched, and will request a new name for this modified version). Worksheet names should always end with .mws; also unless you really need the output it is usually a good idea to remove it before saving -- to do this, select Edit, then Remove Output.

>

>