Math 241 - Maple Workshop Fall Semester, 2001 Session 1 - Introduction to Maple © 2001, All Rights Reserved, SDSU & Joseph M. Mahaffy San Diego State University -- This page last updated 10-Sep-01

Introduction to Maple

Session #1 - Algebra. Calculus using Maple, including functions, differentiation, integration, and graphing. Management of Maple worksheets. Maple help.

This workshop begins by using Maple to review some of the techniques that you learned in Algebra and Calculus. This session is designed to introduce you to key aspects of the program to get you started. As with most computer languages, the key to learning them is by practice, which is why the Math 241 Workshop was designed to be a hands on experience. A hyperlink to a Maple worksheet containing most of the material below is provided.

Introduction to Maple

I will take advantage of Maple's ability to create HTML pages to design this website for the course notes. For those of you interested in using Maple to enhance your website, then you can save your Maple worksheets as HTML. This brings us to our first point. When you begin a session in Maple, it opens a new worksheet . Your options are to start with this new worksheet or bring up a previously saved worksheet. The standard Maple file on any platform (and they can be moved between the different platforms, such as Windows or UNIX) has a name and extension such as filename.mws . (Obviously, a file saved as HTML will not satisfy this criterion.)

The worksheet is embedded in window that has a series of headings. These are the standard headings that you see for many programs, such as File , Edit , View , Insert , etc. During this course, we will work with many of these operations to gain proficiency in Maple. (I suspect that often you will point out useful features to me as the course proceeds.) The actual operations are performed on an active worksheet. You may have multiple worksheets open, but each one is self-contained.

Functions

Probably the best place to begin our study of Maple is just like we begin Calculus. We start with the function . There are two standard ways to introduce a function in Maple: 1. Function form and 2. Explicit expression. In most cases, I will use the first form as it has more adaptability.

Suppose we want to write the polynomial

f ( x ) =

This is done in Maple in the following manner:

> f := x -> x^3 - x^2 - 7*x + 15;

There are several points to be made about this expression. Maple uses the symbols := (colon and equals) to mean "defined to be." The symbols -> (minus and greater than) produce an arrow used to define the variable (or variables) in the function which is (are) used in the function. The f at the beginning is the name of the function, and the semicolon at the end tells Maple to execute the command and write its interpretation. A colon allows Maple to execute an operation, but it will not reflect an answer following the colon. I have inserted spaces in a number of locations above for clarity, but these are not essential. You cannot have spaces in certain places, like between the : and = or the - and >, when composite Maple characters are being created. We see that the Maple output shows the expression in good mathematical font. (This can be changed under the Options menu.)

The second manner of entering a function is the Explicit expression. This only uses the := or "defined to be" symbol. For example, we write

> g := x^3 - x^2 - 7*x + 15;

Let us show function evaluation for each of these expressions.

> f(2); g(2);

Notice that function evaluation is easy for f, but doesn't work for g. If you want to evaluate the explicit expression, then you need the substitution command in Maple:

> subs(x=2,g);

Maple is called a symbolic algebra language. Let us show a few commands that demonstrate Maple's ability to perform algebra. We begin with the commands factor and solve , which do what you might expect (though you may remember that solving cubic equations is not a simple process).

> factor(f(x));

> solve(g=0,x);

If you had forgotten the quadratic formula, then Maple can manage the symbolic solution.

> h := x -> a*x^2 + b*x + c; solve(h(x)=0,x);

Suppose we want to use the first of these solutions for solving a couple of specific equations. The second expression is a vector with the two solutions for the quadratic equation. Maple uses the symbol % to remember the last operation executed. (I can not warn you enough that this is the very last executed expression, not necessarily the expression appearing on the line above, as you can move around the Maple worksheet and insert new work whenever you find it convenient.) The [1] means the first component of the vector. We will define the first first of the solutions as solnp (an arbitrary name).

> solnp := %[1];

Now we can substitute into this expression the values of a, b, and c to get a specific answer. Note that {} are used to allow multiple substitutions into the same expression.

> subs({a=2,b=4,c=5},solnp);

If we prefer a decimal representation, then we can use the evalf (floating point evaluation) command. Maple defaults to an integer mode whenever possible and handles integers and decimals quite differently.

> evalf(%);

Before moving to the next section. We introduce a couple more useful commands and demonstrate the use of Maple's Help . We can expand algebraic and trigonometric functions readily.

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

> expand(tan(a+b));

One Maple function that can be used to try to obtain easier expressions is its simplify command.

> simplify(x^2/(x+2)-4/(x+2));

> sin(3*theta)/sin(theta);

> simplify(%);

Help

One of the easiest methods to learn about Maple is the use of its Help, which is on the menu bar. You can search for specific topics or you can use the introduction menu bar to trace through topics to find the one that interests you. When you find a subject that interests you, then it is easiest if you simply copy the topic of interest from the examples at the bottom of that Help page and execute the command.

For example, suppose that we wanted to produce a pretty 3-D graphic. We can go to the Introduction Help menu and trace the set starting with Graphics , then 3-D , then plot3d . We can read about the details of plot3D, but here I simply copy one of the examples at the bottom of the help page.

> plot3d([1,x,y],x=0..2*Pi,y=0..2*Pi,coords=toroidal(10),scaling=constrained);

>

Graphing and Calculus

We now consider a damped oscillator given by the expression.

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

We want to graph this on the interval from 0 to 2 .

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

We show the function evaluation again.

> f(1); evalf(f(1));

Suppose that we want to find the x values of the first two zero crossings. You can estimate the value by pointing and clicking at the graph, then seeing the value appear in the window on the menu bar. However, and accurate value is obtained using the solve or more often the fsolve commands.

> solve(f(x)=0,x); fsolve(f(x)=0,x);

> fsolve(f(x)=0,x=1..2);

Differentiation

Now suppose we would like to find the value of the first maximum ( x > 0) and the third minimum ( x > 0). Again, we can estimate these values from pointing and clicking on the graph. However, Calculus provides better tools, which are readily accessible in Maple. We use the derivative to find find extrema, then we can evaluate the function at those extrema.

> df := diff(f(x),x);

> xmax := fsolve(df = 0,x = 1..2);

> f(xmax);

> xmin3 := fsolve(df = 0, x = 4.5..5.5); f(xmin3);

Integration

What is the integral of f ( x )?

> int(f(x),x);

Suppose we want to find the area under the first hump on the graph. We find the limits of integration using fsolve, then use Maple to solve the definite integral.

> x0 := fsolve(f(x) = 0, x = 1.2..1.7); x1 := fsolve(f(x) = 0, x = 2.2..2.7);

> Int(f(x),x = x0..x1);

> int(f(x),x = x0..x1);

For those of you familiar with LaTeX, Maple has a command for typesetting the LaTeX of mathematical expressions, which is where commands such as Int can be useful.