Illustrating sums that approximate integrals
(leftbox, leftsum, value, rightbox, rightsum)


In Maple's "
student" library, there are several commands that can be used to illustrate the computation of integrals via Riemann sums. To use these commands, you must first enter the command:

>   restart:

>   with(student):


The colon at the end of the line surpresses the output (if you use a semicolon, you will get a list of all of the commands available in the
student library).

We demonstrate the use of the commands by working through the following example: Use Riemann sums to compute:

>   Int(1/t,t=1..2);

Int(1/t,t = 1 .. 2)

Recall that the "Int" command with a capital I is used to get Maple just to type integrals. It does not evaluate them -- the "int" command with a small i does that. But the form of the two int (for integral) commands is the usual verb(what,how); form of many Maple commands. Before the comma, you enter the (name of the) expression to be integrated ("Integrate what?") and after the comma you give the name of the variable and the range of integration ("Integrate it how?").

We will illustrate only the left-hand sums. Maple has three relevant commands: "
leftbox", which draws pictures, "leftsum", which gives summation notation for the area under the left boxes, and "value", which computes the sums (evalf can also be used). So, as we approximate the above integral using 10 rectangles which touch the curve on the left, we can have Maple illustrate the boxes by typing:

>   leftbox(1/t,t=1..2,10);

[Maple Plot]


The syntax of
leftbox matches that of int, except it has a third argument which specifies the number of boxes to be used to approximate the integral.


Notice that in this case, the sum of the areas of the boxes gives an overestimate of the area under the curve because the curve is concave up.

To calculate the sum of the areas of the boxes, use the command
 

>   leftsum(1/t,t=1..2,10);

1/10*Sum(1/(1+1/10*i),i = 0 .. 9)

In this expression, Maple has numbered the ten boxes from 0 to 9, and the area of the ith box is equal to  1/10*(1/(1+i/10)).  Notice that 1/10 is Deltat and the other factor is the value of the function 1/t at the left side of the box. To calculate the sum, we can ask Maple for:

>   value(%);

33464927/46558512

>   evalf(%);

.7187714032

Maple is capable of calculating (but not drawing) the area for an arbitrary unspecified number of boxes:

>   leftsum(1/t,t=1..2,n);

1/n*Sum(1/(1+i/n),i = 0 .. n-1)

>   value(%);

1/n*(n*Psi(2*n)-n*Psi(n))

The "Psi" function is a special function used by number theorists. The point of getting Maple to do this is we can now ask Maple what happens as the number of boxes approaches infinity:

>   limit(%,n=infinity);

ln(2)

And this is in fact the value of the integral, as we can check using Maple's int command (which uses the Fundamental Theorem of Calculus to evaluate integrals):

>   int(1/t,t=1..2);

ln(2)


There are commands "
rightbox" and "rightsum" (and "middlebox" and "middlesum") that correspond to "leftbox" and "leftsum". Also, there are "trapezoid" and "simpson" for using those numerical integration rules.