Tutorial 136

This lab is intended to give you familiarity with those additional capabilities of

MAPLE that are related to the content of the Calculus II course. More basic material is discussed in earlier tutorials.

 

Introduction 

MAPLE is a powerful computer algebra system that can perform many mathematical calculations. It can also be used as a programming language. This lab is intended to introduce both of these capabilities. The MAPLE program is available to enrolled mathematics students in the computer lab in EAS 136.

  

Logging into the System 

On the log-in screen, you will see a prompt for your username and password. Type in your username first. This will be the first letter of your first name followed by the first seven letters (or less) of your last name. For example, if your name is John Williams, then your username will be JWilliam.

 

If you have not previously logged in, you will need the initial password. This is, usually the first eight digits of your student ID number. After you log in you will be asked to change this password, make sure you remember it!

 

**Note  

If for some reason either your username or your password does not work, first check that the DOMAIN is set to UFP. If it still doesn't work, ask someone for help.

 

Starting out with MAPLE

Double click the MAPLE icon on the desktop. This will open a MAPLE worksheet, and you should see a prompt in the upper left corner that looks like this:

>

 

Area Between Curves

Our first task is to plot the functions

g(x) = x^2 + 2

f(x) = 2*x + 5

on the same axes and find the area of the region enclosed between these curves from x = 0 to x = 3.

> g:= x -> x^2 + 2;

> f:= x -> 2*x + 5;

> a:= plot(g(x), x = -1.5..3.5, thickness=2, color=red):

> b:= plot(f(x), x = -1.5..3.5, thickness=2, color=brown):

> display({a,b});

Now solve the polynomial g(x) f(x) = x^2 + 2 2*x 5 = 0 to find where our curves intersect. Using the MAPLE command solve, we find the values: x1 = 3 and x2 = -1.

 

> solve(g(x)-f(x), x);

Finally compute the requested area by integrating (f(x) g(x)) from x = -1 to x = 3.

> Area:=int(f(x)-g(x), x = -1..3);

Problem

Find the area of the region bounded above by y = exp(x), bounded below by y = x, and bounded on the sides by x = 0 and x = 1.

 

Volumes of Revolution

A simple extension of the ideas and definition of the definite integral permits evaluation of the surface area and the volume of solids of revolution. A solid of revolution is the solid formed when a plane curve is rotated in space around an axis in its plane. The Maple function plot3d does the plotting and it can be found in the plots package. To be able to use this function we have to bring in this package.

 

> with(plots):with(plottools):

Warning, the name changecoords has been redefined

 

Warning, the name arrow has been redefined

 

**Note

Maple gives a warning when this package is called. Ignore it.

 

Rotate the curve, y(x) = x^2 + x - 1 around the y axis from the point where y=2 to y=4, and then find the volume of the resulting solid.

 

 

> f:=x->x^2+x-1; plot(f,2..4);

 

To rotate this curve use the maple functions seq and rotate. The seq function is used to construct a sequence of values; in this case it builds a sequence of circles around y-axis. The rotate function takes the plot and produces a new one rotated by the specified angle(s).

> a := seq(rotate(cylinder([0,0,f(k/10)],k/10,1),Pi/2,0,0),k=20..40):

 

Now draw what you created previously using the display function.

 

> display(a,axes=normal,labels=[x,y,z]);

 

To find the volume of this solid of revolution about the yaxis, we must express our curve y = x^2 + x - 1 as a function of y. The function solve can be used.

 

> X:=solve(f(x)=y,x);

The equation has two solutions; specify the first with X[1]. Using slices find the volume of the plotted cylinder.

 

> Vol:=Pi*int(X[1]^2,y=2..4);

 

The Menu of plot3d

Do you know how you can improve your graph? Here are some helpful hints.

Put the mouse cursor on the graph and right click. A menu pops up. It contains the following:

 

Cut

Copy

Paste

Style  >

Legend >

Color >

Lightning >

Axes >

Scaling Constrained

Projection

Transparency

Export

Animation

Now, lets see what the most important of those functions do for 3-Dimensional Graphics.

 

Style - Choose among the following styles:

Point plot of the computed points only.

Patch - colored surface and grid obtained by joining the computed points.

Patch w/o grid colored surface without grid.

Hidden line grid obtained by joining the computed points, hidden lines not plotted.

To choose the Symbol being used when the surface is plotted with points, select from Cross, Diamond, Point, Circle.

To choose the Line Style being used to represent the curves, select from continuous Solid, dashes Dash

To choose the Line width, select from thin, medium, thick, default.

 

Color - Choose the color in Patch style:

XYZ colors varying in function X, Y, Z.

XY colors varying in function of X, Y.

Z colors varying in function of Z.

To chose a lighting of the surface, select from No Lightning, light scheme1

 

Axes - Choose the kind and the position of the axes: Boxed, Framed, Normal, None

To change the graphs position put the mouse on the picture, left click and move the mouse until the desired position is obtained.

 

Projection - Chose the type of perspective used: No Perspective, Near Perspective, Medium Perspective, Far Perspective.

 

Calculating Integrals

MAPLE can handle integration, often by finding an antiderivative. This program is a very powerful tool you can use to solve difficult integrals, integrals that solving by hand can be very messy.

Topics:

I. Antiderivatives

II. Definite integrals

III. Improper integrals

 

I. Antiderivatives

Example1

Find the integral of a function f=x*sqrt(x^2+2*x). First define the function.

> f:=x->x*sqrt(x^2+2*x);

 

Now integrate the function using maple command int.

 

> g:=int(f(x), x);

Notice that MAPLE omits the constant of integration. It produces a particular antiderivative, not the most general one. Therefore, when making use of machine integration, dont forget to add the constant.

 

Example2

Now integrate the function h(x) = sin(x)^2/(1+sqrt(x)).

> int(sin(x)^2/(1+sqrt(x)), x);

 

Notice the fact that MAPLE returns the integral of this function in a symbolic form. The machine doesnt have an elementary antiderivative.

 

 

II. Definite integrals

A. Antiderivatives in definite integrals.

Example1

MAPLE has a preference for exact computation. In this example define f(x) = 1/(1 + x^2), compute the integral and evaluate it

1.     From x = 0 to x = 1

2.     From x = 0 to x = infinity

Notice that the integral of this function is actually arctan(x).

 

> f:=x->1/(1+x^2);

> g:=int(f(x), x=0..1);

> g:=int(f(x), x=0..infinity);

Do you think this is a numerical answer? Well maybe for you it is, but for MAPLE this is actually a symbolic one. If you want a numerical answer then use evalf(%) to get it.

> evalf(%);

 

Example2

> int(sin(x)^2/(1+sqrt(x)), x=0..1);

 

 

Again, MAPLE doesnt know what the antiderivative of this integral is, so it returns a symbolic answer.

 

Problem

Now, try to do the same with the following function. f = 2/(3+2*x^3-x^2).

1. First define the function.

2. Integrate the function and evaluate the integral from 0 to 1.

3. Get a decimal representation for your answer.

 

 

II. Numerical methods

Weve seen one example of an integral that has a symbolic answer. Here it is another one.

Some functions like f(x) = exp(-x^2) do not have elementary antiderivatives.

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

In this case MAPLE gives a name erf to the antiderivative. erf is the error function. MAPLE uses numerical techniques to calculate this type of integrals. By using evalf(%) a numerical answer can be obtained.

 

> evalf(%);

 

As weve seen, there are two cases:

1.     MAPLE has an elementary antiderivative.

2.     MAPLE doesnt have any elementary antiderivative.

For the first case a decimal number can be obtain using evalf.

For the second case MAPLE returns a symbolic answer whether in a form like

or using the error function erf,

Again a decimal result can be obtained using evalf.

 

Problem

Evaluate in decimal int(sin(x)^2/(1+sqrt(x)), x=0..1);

 

 

III Improper Integrals

The function int sometimes returns a result in an unevaluated form. As the following example shows, the fact that MAPLE returns such a result doesnt say anything about the convergence of the integral.

Divergent Integrals

Example1

When the integral diverges towards + , MAPLE returns + .

> int(1/x,x=0..1);

 

Example2

> int(sin(x)^2/(1+x^(1/2)),x=0..infinity);

In this case the integral diverges because the area under the graph is infinite. MAPLE recognizes this fact, as we can see by forcing an evaluation using evalf(%).

 

> evalf(%);

 

Example3

MAPLE returns the value undefined when it realizes that the integral diverges without tending towards +.

> int(x*sin(x), x=0..infinity);

Convergent Integrals

Now take a look at some convergent integrals.

Example1

> int(1/x^2, x=2..infinity);

Example2

MAPLE knows sophisticated results that are difficult or impossible to obtain using Calculus.

> int(sin(x)/x, x=0..infinity);

Problem

Suppose f(x) = cos(x)/sqrt(x).

  1. Evaluate the integral from x = 0..infinity.
  2. Does the integral of this function converge or diverge?

 

 

Taylor polynomials

MAPLE can be great timesaver when you need Taylor polynomial approximations to a function. To review the nature of the approximation by Taylor polynomials let's look at plots for some of the standard Taylor polynomials for sin(x). Define

> f:=sin(x);

 

 

> p:=x;

> q:=x - x^3/6;

> r:=x - x^3/6 + x^5/(5!) -x^7/(7!);

 

Now look at plots with the original function and the various approximations.

plot([f,p,q,r],x=0..2*Pi, y = -2..2, color=[blue, red, green, black]);

Legend:

 

Blue: f:=sin(x);

Red: p:=x;

Green: q:=x - x^3/6;

Black: r:=x - x^3/6 + x^5/(5!) -x^7/(7!);

 

 

 

 

 

MAPLE can compute Taylor polynomials by using the command taylor.

Suppose we want the 7th order Taylor polynomial of the sin function at x = 0.

> p7 := taylor(sin(x),x=0,8);

 

p7 is not actually a polynomial because of the term at the end which describes the order of the error. Convert the above to a polynomial.

> p7 := convert(p7,polynom);

 

Make the polynomial p7 a function of x using unapply and evaluate for p/2 using evalf.

> p7:=unapply(p7,x);

 

> evalf(p7(Pi/2));

 

 

 

 

Now, find the Taylor polynomial at x = Pi/2.

> taylor(f,x=Pi/2,8);

you get a Taylor polynomial with the order of the error for sin(x) about x = p/2.

 

Problem

1. Try taylor(cos(x),0,8). How is this result like the previous one?

2. Now compute and plot the corresponding Taylor polynomials for the function

g(x) = exp (-x^2).

 

 

 

Polar Graphs

MAPLE can also use polar coordinates as well as x-y coordinates for the plane. Here are several cute polar plots.

 

1. Trigonometric Functions

> with(plots):

> polarplot({ 10 + 10*cos(theta), 10 + 10*sin(theta), 10 -10*cos(theta), 10 - 10*sin(theta)}, theta = 0..3*Pi, scaling = constrained);

 

Looking at all four at once, can you decide which graph belongs to which? Think about what values of theta make the sine and cosine maximal.

 

 

 

2. The Rose

Next, look at polar functions of the form f = a sin(n*theta ) and g = a cos(n*theta ). The plots of these functions look like multi-petaled roses.

 

When n is an odd number, the resulting rose has exactly n petals

> polarplot( {10, 10*sin(7* theta)}, theta = 0..2*Pi, scaling = constrained);

 

 

When n is even, the rose has 2*n petals.

> polarplot( {10, 10*sin(4*theta)} , theta = 0..2*Pi, scaling = constrained);

 

 

Problem

1. Create a rose with 24 petals.

2. What about a single-petaled rose?