>

day1.mws
AN INTRODUCTION TO MAPLE: Basic computations and plotting

Math 242 section 1 -- Spring 1998

Matt Miller (miller@math.sc.edu)

Objectives:
- Enter mathematical expressions in Maple
- Plot a given function in Maple
- Extract information from a graph

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 ON-LINE 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. Information about these commands can be found in the on-line help: ?plots, ?restart

> restart:

> ?plots;

> with(plots):

BASIC FACTS

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

The fundamental symbols:

- assignments are made with := (plain = has a different meaning) -- think of this as giving the value of the right hand side to the name that appears on the left hand side
- every command is terminated by a semi-colon ( ; ) or colon ( : ) -- with the latter the computation is done, but the result is not displayed
- the double quote ( " ) refers to the result of the immediately preceding computation
- Maple is case sensitive -- that is, the names x and X are different, pi and Pi are not the same thing
- { } -- set notation (mostly used in the context of plotting a bunch of functions simultaneously)
- .. as in a .. b -- this is how Maple indicates the interval [a, b], that is, the real numbers from a to b
- ? or help -- a request to Maple for information

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 ;

> power:= (-3)^3 ;

> abs( % );

> Pi ;

> v:= sin( Pi / 4 ) :

> w:= v^2 ;

> v;

> tan( -Pi / 2 ) ;

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


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 ) ;

> g := 4 * x^2 ;

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

> p:= f * g ;

> q:= f * h ;

> s:= f + h ;

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!!

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

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

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 MM] ` ) ;

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 );

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

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.

PLOTTING MULTIPLE FUNCTIONS IN ONE WINDOW

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

Can you identify the three different plots? What about the next one? Can you explain the little bumps that appear inside the large dips in the graph of s?

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

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);

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

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

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 .

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

This is better, but what are those (almost) vertical lines? Maple doesn't plot asymptotoes without being asked, so these are actually spurious connect-the-dots lines. It is really better to tell Maple that the function is discontinuous.

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

> plot ( ( 1 - 0.4*t^3) / ( 1 - t^2 ) , t = -3 .. 5 , -10 .. 10 , discont = true, title = `vertical asymptotes by [MM]` ) ;

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.

>