Riemann Sums with Maple

To gain a better understanding of a Riemann Sum, we can ask Maple to compute a numerical approximation to a definite integral using rectangles with the commands leftsum and rightsum and create graphs with the procedures leftbox and rightbox. The height of each rectangle is determined by the value of the function at the left or right side of each interval respectively. These commands, found in the student package, are initiated by typing

(Press ENTER after the colon.)

Numerical Approximations

The calling sequence for leftsum is

leftsum( f(x), x = a..b, n );

where f(x) is an algebraic expression in x, x is the variable of integration, a is the left end of the interval, b is the right end of the interval, and n is the number of rectangles to use (optional, the default value is four rectangles). (Note that there are TWO DOTS between the a and b rather than the customary three.)

We may want to find the definite integral of f(x) = x^2 from x = 0 to x =1. The actual value of this definite integral is 1/3. However, we can see how Maple comes closer and closer to 1/3 as we increase the number of rectangles from 10 to 10,000. First, lets try 10 rectangles. We begin our command with evalf as follows. (Press ENTER after the semicolon.)

The left and right sums are close to 1/3. Now lets try 100 rectangles.

We can see that Maple is sandwiching the value 1/3. So lets try 10,000 rectangles!

We probably wouldn't have the time to wait for a graphing calculator to make this last computation, but Maple completes it in seconds. And as we expected, these two approximations are even closer to 1/3 than the previous example. We can get as close to 1/3 as we like by increasing the number of rectangles.

Graphs

To create a gragh with 10 rectangles showing the area under the curve of f(x) = x^2 from x = 0 to x = 1, we use the Maple procedures leftbox and rightbox.

leftbox has evaluated the function on the left side of each rectangle.

rightbox has evaluated the function on the right side of each rectangle.

As we can see from the graphs, the lefthand sum is an underestimate of the area under the curve and the right hand sum is an overestimate, since the function is increasing. (Refer to Graphing Ordinary Functions for more information on graphing in Maple.)


Link to Maple Home Page


Back to Ellerbruch Web Site Home

Link to Math Department Home

Link to Northern Michigan University


Jo Norby-Davis: jnorbyda@nmu.edu.