Tutorial135

In this lab we will study how to use MAPLE for Calculus applications. These applications include Differentiation, Integration, Riemann Sums and Plotting. If you need more basic help with MAPLE an additional tutorial is available.

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:

>

 

Differentiation

MAPLE has a powerful capability to differentiate. The function diff performs differentiation.

 

Example1 (differentiating an easy function)

First we need to define a function. Take for example an easy one: f(x)=x^2. To enter this in MAPLE type

> f:=x->x^2;

 

 

 

Now f is defined as a function of x. Type

> f(x);

to see that MAPLE remembers our function.

Moving on to Calculus lets try to differentiate the function f(x)=x^2.

> f';

Error, unexpected single forward quote

 

This doesnt work.

We need HELP. To get help, type ?, or use the scroll bar at the upper right. The help material suggests that typing ?topic will access information on the topic. Notice there are also some indices of help categories, and library functions. You can exit help by clicking on the lower X in the upper right corner of the screen.

Lets try ?differentiation. That worked well. Actually, you should try ?dif to see what happens when you dont stumble on the precise function name you need.

Having learned from the help material that the function we want is diff, type

> diff(f(x), x);

Everything looks good. Maple can handle differentiation successfully. Of course we often want to insert the result of a differentiation or other operation into some later computation.

 

Example2

Define the function f = arctan(x);

> f:=x->arctan(x);

The result after differentiating this function is:

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

In Maple one has to distinguish between a function and an expression. In our example, f is a function while g is an expression.

One difference between functions and expressions lies in the kind of variable used at the time of their definition: it isnt necessary to use free variables in order to define a function, while the definition of an expression requires a free variable or the use of apostrophes.

If f is a function, one only has to request the evaluation of f(a) to obtain the value of f when its argument is equal to a.

 

> f(5);

Try with g

> g(5);

If g is an expression that depends on a free variable x, its value for x=a can be obtained by assigning a to x and requesting the evaluation of g (be aware that x is no longer free).

 

If g is an expression in the free variable x, then the evaluation of unapply(g, x) returns the function that maps x onto g(x). Try it:

> g:=unapply(g, x);

 

Now g is a MAPLE function. Try again with g

> g(5);

 

Example3 (A messier problem)

Define f = sin(x)/arctan(x).

> f:=x->sin(x)/arctan(x);

 

Differentiate f(x).

> diff(f(x), x);

Use unapply to make g a MAPLE function after you differentiate.

 

> g:=unapply(diff(f(x), x), x);

**Note

The differentiation and conversion to a MAPLE function can be done on the same line.

 

Problem

Differentiate the following functions:

1) f(x) = (x^2)*sqrt(sin(x)).

2) f(x) = (sin(x))^2/arctan(x)

 

 

Plots

MAPLE is a powerful tool that can be used in graphing functions. To illustrate this capability we look at how MAPLE can plot a function, its derivative, and a tangent line. The function plot does the graphing part.

 

Define a function f (x)=2+arctan(x-1). Then graph it to see how it looks.

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

 

> plot(f(x), x=-5..5, y=0..4);

Name the derivative of this function m. Then graph m.

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

 

Make m a function. Do the differentiation and conversion to a MAPLE function on the same line.

> m:=unapply(diff(f(x), x), x);

MAPLE sees the derivative m as a function of x, so m can be referred to as m(x).

 

> plot(m(x), x=-10..10);

 

If m is the slope at x=a, then the equation of the tangent line at a point a is: y-f(a)=m(x-a) or y=f(a)+m(x-a). In this case the function is f=2+arctan(x-1) and the slope is m=1/(1+(x-1)^2).

Let a = 1. Find f(a) and m(a).

> a:=1;

> f(a);

2

> m(a);

With the slope m and the function f(a) find the equation of the tangent line at the point a.

> y:=unapply(f(a)+m(a)*(x-a), x);

Graph the equation of the tangent line, y(x).

 

 

 

 

 

 

 

 

 

> plot(y(x), x=-5..5, y=0..4);

 

It would be nice to see the function f(x)=2+arctan(x-1) and the equation of the tangent line y(x) on the same graph.

> plot([f(x), y(x)], x=-5..5, y=0..4);

 

The red wavy line is f(x) and the green straight line is the equation of the tangent line, y(x).

For black and white printing it is better to have black graphs.

> plot([f(x), y(x)], x=-5..5, y=0..4, color=black);

 

Where does our slope m have a max? Where m=0.

To solve the problem first differentiate m, which also means differentiating f(x) twice.

> m1:=unapply(diff(m(x), x), x);

Now find where m1=0.

> solve(m1(x));

The function solve determines all the solutions of an equation in one unknown. If m1(x) is an equation in the free variable x, the evaluation of solve(m(x), x) returns all solutions in x of the equation m(x)=0. One may simply write solve(m(x)) if m(x) contains no variable other than x.

 

Problem

Define a function f (x)=2+tan(x-1).

1)      Differentiate the function f(x) and name the derivative m.

2)      Graph f and m on the same axes.

 

 

Integration

MAPLE can handle differentiation well. Lets move forward and see how can MAPLE be used for integrating functions. The function int gives the means to compute integrals.

 

Computation of Definite and Indefinite Integrals

Example1

Define the function f=2x.

> f:=x->2*x;

If f is a function in one variable, one uses int(f(x), x) to integrate this function

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

MAPLE doesnt use integration constants when it computes indefinite integrals.

Warning! The identifier I represents sqrt(-1) for MAPLE and may therefore not be used to store an integral.

> I:=int(x^2, x);

Error, illegal use of an object as a name

 

 

Example2 (definite integral)

The function f=2x is already defined. So, there is no need to define it again.

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

 

Example3 (polynomial)

In this example the function to be integrated is a polynomial. Define f=5x^3+3x^2+7.

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

Integrating the function f the answer should look like:

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

Now, the definite integral for the function is:

> int(f(x), x=0..3);

 

Oops, the result is a fraction. For a more helpful answer use evalf(%) to get a decimal representation for a number.

> evalf(%);

The same thing can be done if typing in some decimals. In place of just 3 type in 3.0.

 

> int(f(x), x=0..3.0);

 

Example4 (a more challenging problem)

Define g = 1/(1+x^2).

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

Integrate the function g.

> z:=unapply(int(g(x), x), x);

 

Example5 (inserting a constant)

Suppose the problem gets more complicated by inserting a constant c. Define f = 1/(1+c*x^2) and then integrate it.

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

> z:=unapply(int(f(x), x), x);

This is good since in real life (at least in the real life of calculus applications) it is often important to understand how solutions depend on various constants. For example, what happens to the satisfaction of workers if we reduce their salary by c percent?

Give a value to c. Let c = 1;

> c:=1;

> f(x);

> int(f(x), x=-1000..1000);

 

For a more helpful answer dont forget to use evalf(%).

> evalf(%);

 

You can also type in some decimals. In place of just 1000 type 1000.0, so the answer is a decimal number.

> int(f(x), x=-1000..1000.0);

**Note

Its enough if only one number in expression has a decimal representation. This tells MAPLE that you want an answer as a decimal number.

Observe the following:

> int(f, x=-10.0^6..10.0^6);

What number does this look like? Can you draw any inferences from this? How would you express your conjecture in terms of area?

 

Riemann Sums:

To help with teaching about Riemann Sums and numerical integration let's go to the student version.

Type with(student).

> with(student);

Define the function f = f:=x->exp(-(x^2)).

> f:=x->exp(-(x^2));

Integrate this function.

> b:=unapply(int(f(x), x), x);

What is erf ? Use MAPLE help material to find what erf means.

For a numerical value type the decimal place:

> b:=int(f(x), x=0..3.0);

Geometrical computation of left endpoint of Riemann Sums type:

> leftbox(f(x), x=0..3, 10);

 

 

**Note

The limits of integration are 0 and 3, while 10 is the number of subintervals. In this case they have equal length.

To actually compute Riemann Sum try:

> leftsum(f(x), x=0..3, 10);

If this is not quite what we want then try:

> value(leftsum(f(x), x=0..3.0, 10));

Increase the number of intervals to 100, 10^3, 10^4, 10^5 and see what happens.

 

> value(leftsum(f(x), x=0..3.0, 100));

> value(leftsum(f(x), x=0..3.0, 10^3));

 

> value(leftsum(f(x), x=0..3.0, 10^4));

> value(leftsum(f(x), x=0..3.0, 10^5));

**Note

The approximations of the integral are getting better, but the computations are slowing down. Even with 10^4 subintervals there is a difference in the fourth decimal place between the Riemann sum and Maple's standard answer. While Riemann sums are nice for theory, accurate calculations almost always use more sophisticated methods.

 

FINAL EXERCISE:

The final issue is one of printing results, particularly plots, on paper. First, select new from file scrollbar. Otherwise you'll print all the junk I've had you type. MAPLE thinks of your work as being part of a worksheet. The more adventurous may want to use help to find out how to edit worksheets.

Generate a nice Riemann sum figure, say

f:=->exp(-(x^2));

rightbox(f(x), x=0..3, 10);

Now click on the printer icon, which is near the top of the screen, fourth icon from the left. Then print, and collect your paper from the printer.

 

Bye.