Riemann Sum Approximation of Area
Copyright 2000
Department of Mathematics
University of Georgia
Athens, Georgia
Carol W. Penney
Robert Rumely
John Gosselin
The following diagram shows a shaded region bounded by the graph of y=f(x), the x-axis, and the vertical lines x=a and x=b. Our goal is to determine the area of this shaded region.
Our method is this: Approximate the area of the region by calculating the area of a polygonal region consisting of rectangles as shown in the following diagram.
| > |
Because this polygonal region consists of rectangles, its area is easy to compute by adding the areas of these rectangles.
The polygonal region consisting of five rectangles will be easy to compute, but it is only a rough approximation of the area under the curve, so after we compute this approximation, we will improve it. How will we do this? Click anywhere in the diagram above. A new row of icons will appear at the top of the page. On the left of this row is a box containing a pair of coordinates. To the right of that box is a set of icons used to display animations. Click the icon that looks like [-> ] ], the third icon from the left. That will step you to the second frame of this seven-frame animation. View all seven frames.
Eventually we will calculate the area A(n) of the polygonal region consisting of n rectangles, then take the limit of A(n) as n approaches infinity. Let's begin.
Calculation of the polygonal approximation with 5 rectangles:
The function whose graph is shown above is f(x)=.008*x^3-.3040*x^2+3.1360*x-.1200, and the interval is [a,b]=[2,25]. We define the function and the interval.
| > | restart: |
| > | f:=x->.008*x^3-.3040*x^2+3.1360*x-.1200; |
| > | a:=2;b:=25; |
Look at the graph of f(x).
| > | plot(f(x),x=a..b,y=0..f(b),scaling=constrained); |
Notice that Maple chooses to draw the vertical axis at x=2 instead of the y-axis in order to make the graph fill up as large as possible region of the picture.
| > |
Consider the five rectangles shown in the first frame of our animation. These rectangles are of equal width. To determine this width, divide the interval [a,b]=[2,25] of width 23 into five equal subintervals, each of width (b-a)/5=(25-2)/5=23/5. Call this width deltax, and define it next:
| > | deltax:=(b-a)/5; |
| > |
Now that we know the widths of the rectangles, we need to compute their heights. Each rectangle in our diagram has its top right vertex on the graph of y=f(x). These heights are, therefore, values of the function f(x) at the right-hand endpoints of the subintervals. We'll call the endpoints of the subintervals a = x(0), x(1), x(2), x(3), x(4), and x(5) = b, and their values are:
x(0) = a = 2,
x(1) = a + deltax = 2+23/5,
x(2) = a + 2*deltax = 2+2*(23/5),
x(3) = a + 3*deltax = 2+3*(23/5),
x(4) = a + 4*deltax = 2+4*(23/5), and
x(5) = a + 5*deltax = 2+5*(23/5)
Here is a picture of the five rectangles, displaying the six partition points x(0), x(1), . . . , x(5):
| > |
We define these endpoints x(0), x(1), . . . , x(5) by defining a function x(i), for i=0, 1, 2, . . . , 5:
| > | x:=i->a+i*deltax; |
Check to see that these x(i)'s are correct, by asking for the sequence of values, from i=0 to i=5:
| > | seq(x(i),i=0..5); |
So the right-hand endpoints of the five subintervals are x(1), x(2), x(3), x(4), and x(5). The heights of the five rectangles are, therefore, f(x(1)), f(x(2)), f(x(3)), f(x(4)), and f(x(5)). The ith rectangle has height f(x(i)) and width deltax, so its area is f(x(i))*deltax. Compute the total area inside of these five rectangles by summing the areas of each of the rectangles as i goes from 1 to 5:
| > | sum(f(x(i))*deltax,i=1..5); |
| > |
This sum is an example of a right endpoint Riemann sum . It approximates the area of the shaded region lying under the curve and above the x-axis between x=2 and x=25 using 5 rectangles, each of height determined by the value of the function at the right endpoint of its base.
| > |
Calculation of a polygonal approximation using left endpoints:
The height of each rectangle in the previous calculation was determined by the value of the function at the right endpoint of its base. What approximation would we have obtained had we instead used the left endpoint of each subinterval? The following diagram shows a left endpoint approximation:
| > |
To compute this left endpoint approximation, use the same function on the same interval; these do not have to be redefined.
Since the subdivision (the partition) of [a,b] is the same, the value of deltax is unchanged. What does change? The height of the first rectangle is determined by the value of f at the left endpoint of the first rectangle, which is x(0); this height is f(x(0)). What is the height of the second? third? . . . fifth? A slight change in the formula that we used earlier for our right endpoint approximation produces the left endpoint approximation.
| > | sum(f(x(i))*deltax,i=0..4); |
If your approximation is
, your calculation is correct!
| > |
Inscribed and circumscribed rectangles:
Consider the function f(x)=
on the interval [a,b]=[1,3].
| > | restart: |
| > | f:=x->1+x+x^3; |
| > | plot(f(x),x=1..3); |
You can see that this function is decreasing on the entire interval. The left and right endpoint Riemann sums are especially informative for such a function, which is said to be monotonically increasing on the interval. To see why, use the following commands to generate pictures of these approximations. The rectangles are called circumscribed rectangles.
| > |
| > | a:=1; |
| > | b:= 3 ; |
| > | n:=10; |
| > | deltax:= (b-a)/n; |
| > | x:=i->a+i*deltax; |
| > | xstar:=i->x(i); |
We want now to construct and plot the Riemann rectangles used to approximate this region. We will define rectangles using the rectangle command, which exists in the package plottools , so we must first load this package with the following command.
| > | with(plottools): |
Note: You may have noticed that the previous command ended with a colon instead of the usual semicolon; the colon suppresses display of the output, so use the colon if you are not interested in seeing the output. Go back now, replace the colon with a semicolon, and enter the command to see the list of commands available in the plottools package.
Now we define the ith rectangle, called riemannrectangle(i), by listing a pair of opposite vertices. Since the bottom left vertex is at [x(i-1),0], we list this vertex, together with its opposite vertex, which has x-coordinate x(i) and y-coordinate f(xstar(i)).
| > | riemannrectangle:=i->rectangle([x(i-1),0],[x(i),f(xstar(i))],color=red); |
Form the sequence of all of these rectangles,
| > | rectangles:=[seq(riemannrectangle(i),i=1..n)]: |
and, since you want to simultaneously display the graph of the function and the Riemann rectangles, open up the package plots , which contains the display command,
| > | with(plots): |
and display the graph of f along with the rectangles and a title to the display:
| > | display(plot(f(x),x=a..b,title=`Right Endpoint Riemann Sum`,color=navy,thickness=2),rectangles); |
| > |
Finally, the following command defines and evaluates the Riemann sum:
| > | riemannsum:=sum(f(xstar(i))*deltax,i=1..n); |
To find a decimal approximation of this Riemann sum, use the evalf command:
| > | evalf(riemannsum); |
| > |
Look at your diagram. Is your approximation too big or too small? What do you expect from a right endpoint approximation for this example?
First enter the appropriate formula for xstar(i) on the right of the arrow to select the left endpoint of the ith subinterval to be xstar(i):
| > | xstar:=i->x(i-1) ; |
Then define the ith rectangle.
| > | riemannrectangle:=i->rectangle([x(i-1),0],[x(i),f(xstar(i))],color=green); |
The plottools and plots packages are already open, so we do not have to open them again. Define the rectangles and display and calculate the Riemann sum.
| > | rectangles:=[seq(riemannrectangle(i),i=1..n)]: |
| > | display(plot(f(x),x=a..b,title=`Left Endpoint Riemann Sum`,color=navy,thickness=2),rectangles); |
| > |
| > | riemannsum:=sum(f(xstar(i))*deltax,i=1..n); |
| > | evalf(riemannsum); |
| > |
What do these two calculations enable you conclude about the area under the curve?
The Limit of the Riemann Sum
Calculation of this Limit
Now we will compute a Riemann sum for each of various values of n, and take the limit as n approaches infinity.
| > | restart: |
Define the function and the interval:
| > | f:=x->1+x+x^3; |
| > | a:=1;b:=3; |
Because we want to vary n, we will define the width of each subinterval to be a function of n:
| > | deltax:=n->(b-a)/n; |
Also define the sequence of partition points, x(0), x(1), . . . , x(n) by defining x(i,n) to be a function of both i and n:
| > | x:=(i,n)->a+i*(b-a)/n; |
We'll use a right endpoint approximation here, so we'll define xstarright(i,n) to be the right endpoint of the ith subinterval, then evaluate the right Riemann sum for various values of n:
| > | xstarright:=(i,n)->x(i,n); |
| > | rightriemannsum:=n->sum(f(xstarright(i,n))*deltax(n),i=1..n); |
Now that we have defined the right Riemann sum as a function of n, the number of subintervals, we can easily compute the right Riemann sum for various values of n, to get an idea of the limit of the right Riemann sum as n approaches infinity. We first construct a sequence of right Riemann sums for n=2, 4, 8, 16, 32, . . . 2^10.
| > | seq(evalf(rightriemannsum(2^k)),k=1..10); |
This sequence is somewhat easier to see if we display it in a vertical list. We'll ask for 16 digits in each approximation.
| > | print(`n`,`right Riemann approx`); for k from 1 to 10 do print(2^k,evalf(rightriemannsum(2^k),16)); od; |
| > |
The first column is a list of increasing values of n. The second column is a list of corresponding values of the right-hand Riemann sum approximation to the integral.
| > | xstarleft:=(i,n)->a+(i-1)*(b-a)/n ; |
| > | leftriemannsum:=n->sum(f(xstarleft(i,n))*deltax(n),i=1..n); |
and compare the right and left approximations. This rather complicated construction consists of the following: First, the labels for the tables, with spaces inserted for readability of the table. The second command is a "do" loop, asking Maple to print the right and left Riemann sums, for n=2, n=4, n=8, n=16, . . . n=2^(10). The end of the "do" loop is "od".
| > | print(`n`,` `,`right Riemann approx`,` `,`left Riemann approx`); for k from 1 to 10 do print(2^k,` `,evalf(rightriemannsum(2^k),16),` `,evalf(leftriemannsum(2^k),16)); od; |
| > |
Since the right endpoint approximation is an overestimate and the left endpoint approximation is an underestimate of the area shaded area bounded by f(x)=
from x=1 to x=3, this area appears to lie between the last values in these lists. Let's let Maple calculate the limit of the Riemann sum by calculating the value of the integral of f(x) from x=a to x=b:
| > | evalf(int(f(x),x=a..b)); |
| > |
Now let Maple attempt to find directly the limit of your right Riemann sum as n approaches infinity. First let Maple evaluate the right Riemann sum as a function of n:
| > | rightriemannsum(n); |
Maple can simplify this sum into a more compact form:
| > | simplify(rightriemannsum(n)); |
Finally let Maple compute the limit of this expression:
| > | limit(rightriemannsum(n),n=infinity); |
Now let Maple do the same for your left Riemann sums
| > | leftriemannsum(n); |
| > | simplify(leftriemannsum(n)); |
| > | limit(leftriemannsum(n),n=infinity); |
Explain what these calculations show. How accurate are the Riemann sums with 1024 rectangles?
Project: The Riemann Sum
Open a new file, type a heading at the top, then write an introductory paragraph to present your investigation.
. You want to write the numerator as 1.0 m rather than as m because 1.0 is a floating point number. Its presence is contagious throughout your calculations, freeing Maple to compute with decimal approximations rather than having to compute exact values. Exact value calculations can be extremely slow, particularly when making large numbers of calculations, such as when adding up 100,000 rectangular areas.
| > | Digits:=20; |
| > |
With the cursor in the second column second row, enter leftriemannsum(~A2). leftriemannsum is your function for the left Riemann sum with n subintervals. The expression ~A2 instructs Maple to evaluate the function leftriemannsum at the number in the cell A2 (first column second row). If you have defined everything correctly, you should get a number in the cell B2. Now highlight cell B2 by clicking the mouse with the cursor in B2. Then click the copy button on the tool bar. Choose the next cell B3 in the second column and then click on the paste button. This will evaluate the left Riemann sum at the value n = 100. Continue to paste in the remaining cells in the first column. Continue to fill in the spreadsheet one column at a time. The third column will contain the right Riemann sums, the fourth column will contain the error between the left Riemann sum and the integral, and the fifth column will contain the error between the right Riemann sum and the integral.
The Most Common Maple Commands
Academic Honesty Statement:
Place the following statement (by copying and pasting) at the end of your report and sign it in ink. Your instructor will not grade your report unless this signed statement appears at the end of your report.
I understand that I may work with others if I give them credit in this statement. I also understand that I am required to write my report--that to copy all or part of someone else's report or to allow someone else to copy all or part of my report constitutes plagiarism, which is a serious violation of academic honesty.
I worked with (replace this parenthetical remark with first and last names of those with whom you worked) on this project. I wrote my own report. I did not copy any of this report from anyone else and I did not allow anyone else to copy any of this report.
Signed: