Riemann Sum Approximations
An Exploratory Introduction - Part 1
Notes to the Student:
This lab is designed to increase your intuitive feel for the approach of determining the area beneath a curve and above the x-axis through approximating rectangles. It is not designed to be a rigorous exercise in the specific notation and nuances associated with the generalized Riemann Sum approach but it is hoped that once you work through this activity you will internalize the dynamic nature of the process of approximating the area beneath a curve through the refinement of associated rectangles over a given interval and be better equiped to understand the notational aspects of Riemann Sums as they are presented by your classroom teacher. Enjoy!
Introduction:
The focus of this lab is to address the important question shown below. Read it carefully paying close attention to its various components and what they mean.
"Given a function f which is continuous, non-negative, and bounded over a closed interval [a,b], how do we find the area enclosed beneath the curve and above the horizontal axis over the designated interval ?"
Objectives Defined:
Below is a listing of the specific objectives for this lab:
1.Define the area question through graphical interpretations.
2. Investigate the various rectangle approximation schemes.
3. Apply the Riemann Sum approach to real-world applications.
4. Introduce the different interpretations of obtained approximating sums.
Historical Perspective:
The determination of the area of a bounded region was of prime importance to the ancient people of Greece and other civilizations. These peoples needed answers to practical problems which arose out of their daily living experiences. Many civilizations had developed formulas for the area of the square, rectangle, trapezoid, triangle, etc. It was the Greek mathematician Archimedes who through the method of exhaustion developed insights into the areas bounded by conics and various other curves. His investigations in determining the area of closed regions with polygons were the precursors to the "second-half" of Calculus I, which we call antidifferentiation or integration . While we teach the notion of the tangent to a curve in differential calculus first, in actuality the inquiry into the area of a bounded region preceeded the derivative question. While the tangent to a curve was the focus of differentiation we now turn our attention to determining an answer to the area question posed above. As we will discover, the two are intimately tied together by the The Fundamental Theorem of Calculus.
Visualizing the Problem:
Consider the function:
.
We can graph this function over the interval [2,4] using the Maple code below. Place the cursor in the red restart code command and press ENTER.
>
restart:with(plots):
f(x)=3*x^2:
b:=plot(3*x^2,x=2..4,y=0..100,title="What is the Area\nBeneath f(x) on [2,4]?",filled=true,color=aquamarine,titlefont=[TIMES,BOLD,14],tickmarks=[3,5],view=[0..4,0..60]):
c:=plot(3*x^2,x=2..4,y=0..100,color=black,thickness=3,tickmarks=[3,5],view=[0..4,0..60]):
display(b,c,TEXT([2.2,30],'`f(x) = 3*x^2`',FONT(TIMES,BOLD,12)));
Warning, the name changecoords has been redefined
We wish to answer the question posed on the picture. The next section will start you off.
>
The Approach:
Let's examine the curve f(x) =
over the interval [0,4]. I can
partition
the interval [0,4] into 4 subintervals each of width 1 unit. (Note): I could have chosen any number of subintervals for my partition but I chose 4 to make the example easier to visualize.
We can now create a grid whereby the horizontal lines are determined by the function heights at the partition intersection points.
Now, in order to approximate the area under the blue curve
f(x) =
, we can shade various rectangles, determine their areas, and then add them. But which ones do we shade to add up? We will consider 4 schemes of rectangle shading:
Scheme 1: Using left-hand endpoints .
Scheme 2: Using right-hand endpoints .
Scheme 3: Using the midpoints of each subinterval.
Scheme 4: Using random points in each subinterval where the subintervals are of equal length.
The Left-Hand Riemann Sum:
One way to shade the rectangles is to partition the interval into n-subdivisions using the left-hand endpoint as the first input value upon which to build the rectangles and the last point will be one point shy of the right endpoint, b. This is called the "Left-Hand Riemann Sum".
Left-Hand Riemann Sum
The Maple code below is an animation of this approximating scheme for our function
on the interval [0,4] and yields an area approximation value for 20 rectangles. Place the cursor in the red
restart
code command and press ENTER.Click on the picture and use the
Animation Toolbar
at the page's top to control the animation.
>
restart
:with(student):with(plots):
setoptions(labels=["",""],font=[SYMBOL,14]):
Digits:=6:
f:=x->x^2:
/* inputted function.
a:=0:
/* left-hand endpoint.
b:= 4:
/* right-hand endpoint.
n:=20:
/* You can change the number of approximating rectangles here.
dx:=(b-a)/n:
./* partition width.
display(seq(leftbox(f(x),x=a..b,NumRects),NumRects =5..n),insequence=true,title="Left-Hand Approximating\nRectangles",titlefont=[TIMES,BOLD,14]);
Approximate_Area:=Sum(f(0+k*dx)*dx,k=0..n-1)=value(leftsum(f(x),x=0..4.0,n))*`sq.units`;
Warning, the name changecoords has been redefined
>
Left-Hand Riemann Approximation Questions
Q1. What is the approximate area using 20 rectangles?
Q2. Do you think that this estimate is too high or too low? Explain.
Q3. Change the source code by replacing n:=20: to n:= 50: . Compute the new approximation with 50 rectangles and write down the new area approximation value.
Q4. What is the width of each rectangle when we use 20 rectangles?
Q5. Find the area of the first three individual rectangles when you use n = 20 subdivisions. Show your work.
The Right-Hand Riemann Sum:
Another way to shade the rectangles is to partition the interval into n-subdivisions and use the second x-value point to start building our rectangles while ending at the interval's right endpoint, b. These subdivision points again are used as function inputs to determine the heights of the n-rectangles. This is called the "Right-Hand Riemann Sum".
Right-Hand Riemann Sum
The Maple code below is an animation of this approximating scheme for our function
on the interval [0,4] and yields an area approximation value for 20 rectangles. Place the cursor in the red
restart
code command, press ENTER, and then click on the picture to access the
Animation Toolbar
to control the animation.
>
restart:
with(student):
with(plots):
setoptions(labels=["",""],font=[SYMBOL,20]):
f:=x->x^2:
Digits:=6:
a:=0:
b:= 4:
n:=20:
dx:=(b-a)/n:
display(seq(rightbox(f(x),x=a..b,NumRects),NumRects =5..n),insequence=true,title="Right-Hand Approximating\nRectangles",titlefont=[TIMES,BOLD,14]);
Approximate_Area:=Sum(f(0+k*dx)*dx,k=1..n)=value(rightsum(f(x),x=0..4.0,n))*`sq.units`;
Warning, the name changecoords has been redefined
>
Right-Hand Riemann Approximation Questions
Q1. What is the approximate area using 20 rectangles?
Q2. Do you think that this estimate is too high or too low? Explain.
Q3. Change the source code by replacing n:=20: to n:= 50: . Compute the new approximation with 50 rectangles and write down the new area approximation value.
Q4. What is the width of each rectangle when we use 20 rectangles?
Q5. Find the area of the first three individual rectangles when you use n = 20 subdivisions. Show your work.
>
The Midpoint Riemann Sum:
A third way to shade the rectangles is to partition the interval into n-subdivisions and use the points located in the middle of each subdivision as the function inputs to determine the height of the n-rectangles. This is called the "Midpoint Riemann Sum".
The Maple code below is an animation of this approximating scheme for our function
on the interval [0,4] and yields an area approximation value for 20 rectangles. As before, place the cursor in the red
restart
code command, press ENTER, and then click on the picture to access the
Animation Toolbar
to control the animation.
>
restart:
with(student):
with(plots):
setoptions(labels=["",""],font=[SYMBOL,20]):
Digits:=6:
f:=x->x^2:
a:=0:
b:= 4:
n:=20:
dx:=(b-a)/n:
display(seq(middlebox(f(x),x=a..b,NumRects),NumRects =5..n),insequence=true,title="Midpoint Approximating\nRectangles",titlefont=[TIMES,BOLD,14]);
Approximate_Area:=Sum(f(0+(k+1/2)*dx)*dx,k=0..n-1)=value(middlesum(f(x),x=0..4.0,n))*`sq.units`;
Warning, the name changecoords has been redefined
>
Midpoint Riemann Approximation Questions
Q1. What is the approximate area using 20 rectangles?
Q2. Do you think that this estimate is too high or too low? Explain.
Q3. Change the source code by replacing n:=20: to n:= 50:. Compute the new approximation with the 50 rectangles and write down the new area approximation value.
Q4. What is the width of each rectangle when we use 20 rectangles?
Q5. Find the area of the first three individual rectangles when you use n = 20 subdivisions. Show your work.
>
Random Points:
Let us proceed to examine random points chosen in equally spaced subintervals. We will use these random points as our inputs for the function in order to obtain the rectangles' heights. (In reality, the general Riemann Sum considers random points in subintervals of random width.) The important thing to remember is that as the width of the subintervals become increasingly smaller the number of rectangular strips increases filling the area under the curve more accurately.
The concept of a " rectangular strip" becomes very important in application problems found in later topics of calculus. We will formalize the ides we are exploring here in class. Below is the random point selection method.
The Maple code below displays this approximating scheme for our function
on the interval [0,4] and yields an area approximation value for 20 rectangles. As usual, place the cursor in the red
restart
code command, press ENTER.
>
restart:
with(plots):
with(stats):
with(student):
Digits:=6:
k:=0:
n:=20:
a:=0:
b:=4:
m:=1:
tot:=0:
deltax:=(b-a)/n:
f:=x->x^2:
an1:=plot(f(x),x=0..4,color=BLUE,thickness=3):
for i from a to b-deltax by deltax do
k:=i+rand()/(1.*10^12)*deltax:
h:=(k)^2:
tot:=tot+k^2*deltax: an2[m]:=plot(h,x=i..(i+deltax),y=-2..16,filled=true,color=GRAY):
m:=m+1:
end do:
p:=plots[display]([seq(an2[m],m=1..n)]):
display(an1,p,title="Random Approximating\nRectangles",titlefont=[TIMES,BOLD,14]);
>
Approximate_Area:=evalf(tot)*`sq.units`;
Warning, the name changecoords has been redefined
>
Random Points Riemann Approximation Questions
Q1. What is the approximate area using 20 rectangles?
Q2. Do you think that this estimate is too high or too low? Explain.
Q3. Change the source code by replacing n:=20: to n:= 50: . Compute the new approximation with 50 rectangles and write down the new area approximation value.
>
Application of Riemann Approximating Sums:
Here are two applications using the midpoint and random point rectangle approximating scheme.
Example 1: The Breathing-Cycle
Breathing is cyclic and a full respiratory cycle from the beginning of inhalation to the end of exhalation takes about 5 seconds. The maximum rate of air flow into the lungs is about 0.5 L/second. The graph below is the model for the rate of flow of one full breathing cycle. (Stewart,1999). Place the cursor in the red restart code command and press ENTER,
>
restart:
with(plots):
f:=t->0.5*sin(2*Pi*t/5):
plot(f(t),t=0..5,y=-1..1,title = "Rate of Flow for a Breathing Cycle in Liters per second",titlefont=[TIMES,BOLD,12],color=magenta,thickness=3,labels=["Time ","Rate of Flow"],labeldirections=[HORIZONTAL,VERTICAL],tickmarks=[10,2],labelfont=[TIMES,BOLD,12]);
Warning, the name changecoords has been redefined
>
Q1: What is the period of the breathing cycle?
Q2. When does it appear that the rate of flow is greatest? Explain.
Q3. When does it appear that the rate of flow is least? Explain.
Q4. Approximate the area under the curve using the Midpoint Riemann Sum code below.You may use the animation feature to see the 20 rectangles fill in. Again, place the cursor in the red restart code command and press ENTER.
>
restart:
with(student):
with(plots):
Digits:=6:
f:=t->0.5*sin(2*Pi*t/5):
a:=0:
b:=5.0:
display(seq(middlebox(f(t),t=a..b,NumRects),NumRects =5..20),insequence=true,title = "Rate of Flow for a Breathing Cycle in Liters per second",titlefont=[TIMES,BOLD,12],thickness=2,tickmarks=[10,2]);
Approximate_Area:=(middlesum(f(t),t=0.0..b,20))=value(middlesum(f(t),t=0.0..b,20));
Warning, the name changecoords has been redefined
Breathing Cycle Approximation Questions
>
Q5. What do you notice about the area value?
Q6. How can you adjust the domain in the above code to compute the actual area.
Q7. The answer that you got in Q6 has a physical meaning that is very important. Can you guess what your value represents?
Example 2: A Famous Constant
Consider the function f(x) = 1/x. We will approximate the area under this curve using the Random Point Riemann Sum scheme outlined earlier. We will first consider the interval [1,2] with the number of subdivisions equal to 50.
Again, place the cursor in the red restart code command and press ENTER.
>
restart:with(plots):
with(stats):
with(student):
k:=0:
n:=50:
a:=1:
b:= 2.0:
m:=1:
tot:=0:
deltax:=(b-a)/n:
f:=x->1/x:
an1:=plot(f(x),x=1..b,color=BLUE,thickness=3):
for i from a to b-deltax by deltax do
k:=i+rand()/(1.*10^12)*deltax:
h:=1/k:
tot:=tot+(1/k)*deltax: an2[m]:=plot(h,x=i..(i+deltax),y=-1..5,filled=true,color=GRAY):
m:=m+1:
end do:
p:=plots[display]([seq(an2[m],m=1..n)]):
display(an1,p,view=[0.5..4,0..1.5],TEXT([2,1],"Graph of 1/x",FONT(TIMES,BOLD,12)),thickness=2,tickmarks=[10,2],TEXT([1.5,0.4],'`area`',FONT(TIMES,BOLD,12)),scaling=constrained,axesfont=[TIMES,BOLD,14]);
Approximate_Area:=evalf(tot)*`square units`;
Warning, the name changecoords has been redefined
>
Q1. What is the approximate area for 50 subdivisions?
Q2. Change the source code above by extending the right-endpoint, b, to b = 2.5: and rerun the program. What is the area now?
Q3. Keep adjusting the b value trying to get the area to within 0.0001 of 1.What is the b value that did it for you?
Q4. Your choice for b is very close to a famous constant. Do you know what it is?
Example 3: Extension.
For many functions one
must approximate
the area beneath them through numerical means, such as, Riemann Sums. One of these "difficult" functions is:
.
Approximate the area under f(x) using 20 subdivisions choosing the rectangle scheme of your choice (i.e. left, right, midpoint or random) on [-2, 2].
Closing Remarks:
In this lab we have seen several things:
1. That it is possible to approximate the area under a curve using the summation of rectangles based on various construction schemes.
2. We can use rectangles obtained by left-hand points, right-hand points, midpoints, and random points all from a predetermined partition of a given interval.
3. Our intuition tells us that as we let the number of subintervals increase (i.e. increase the number of approximating rectangles) our approximation to the area under the curve gets better.
4. If the function takes on negative values, we will need to account for this in order to get the true value of the area.
5. That there is sometimes a physical interpretation to this area "number".
Source Code:
Here you will find various routines which produced the images within this worksheet.
>
restart:with(plots):
/* Creates the partition.
plot([x^2,[[1,0],[1,20]],[[2,0],[2,20]],[[3,0],[3,20]],[[4,0],[4,20]]],x=0..4,title="Simple Partition",color=[blue,red,red,red,red,red],thickness=3,titlefont=[TIMES,BOLD,14]);
>
restart:with(plots):
/* Creates a grid.
plot([x^2,1,4,9,16,[[1,0],[1,20]],[[2,0],[2,20]],[[3,0],[3,20]],[[4,0],[4,20]]],x=0..4,title="Simple Grid",titlefont=[TIMES,BOLD,14],color=blue,color=[blue,red,red,red,red,red,red,red,red],thickness=3);
>
restart:with(student):with(plots):
/* Creates Left-Hand Riemann Sum Animation
setoptions(labels=["",""],font=[SYMBOL,14]):
Digits:=6:
f:=x->x^2:
/* function.
a:=0:
/* left-hand endpoint.
b:= 4:
/* right-hand endpoint.
n:=20:
/* number of approximating rectangles.
dx:=(b-a)/n:
/* partition width.
display(seq(leftbox(f(x),x=a..b,NumRects),NumRects =5..n),insequence=true,title="Left-Hand Approximating\nRectangles",titlefont=[TIMES,BOLD,14]);
Approximate_Area:=Sum(f(0+k*dx)*dx,k=0..n-1)=value(leftsum(f(x),x=0..4.0,n))*`sq.units`;
>
restart:
/*Creates Right-Hand Riemann Sum Animation.
with(student):
with(plots):
setoptions(labels=["",""],font=[SYMBOL,20]):
f:=x->x^2:
/* function.
Digits:=6:
a:=0:
/* left-hand endpoint.
b:= 4:
/* right-hand endpoint.
n:=20:
/* number of approximating rectangles.
dx:=(b-a)/n:
/* partition width.
display(seq(rightbox(f(x),x=a..b,NumRects),NumRects =5..20),insequence=true,title="Right-Hand Approximating\nRectangles",titlefont=[TIMES,BOLD,14]);
Approximate_Area:=Sum(f(0+k*dx)*dx,k=1..n)=value(rightsum(f(x),x=0..4.0,n))*`sq.units`;
>
restart:
/*Creates Midpoint Riemann Sum Animation
with(student):
with(plots):
setoptions(labels=["",""],font=[SYMBOL,20]):
Digits:=6:
f:=x->x^2:
/* function.
a:=0:
/* left-hand endpoint.
b:= 4:
/* right-hand endpoint.
n:=20:
/* numberof approximating rectangles.
dx:=(b-a)/n:
/* partition width.
display(seq(middlebox(f(x),x=a..b,NumRects),NumRects =5..20),insequence=true,title="Midpoint Approximating\nRectangles",titlefont=[TIMES,BOLD,14]);
Approximate_Area:=Sum(f(0+(k+1/2)*dx)*dx,k=0..n-1)=value(middlesum(f(x),x=0..4.0,n))*`sq.units`;
>
restart:
/* Computes Random Points Riemann Sum
with(plots):
with(stats):
with(student):
Digits:=6:
k:=0:
n:=10:
a:=0:
/* left-hand endpoint.
b:=4:
/* right-hand endpoint.
m:=1:
tot:=0:
deltax:=(b-a)/n:
/* partition width.
f:=x->x^2:
/ function.
an1:=plot(f(x),x=0..4,color=BLUE,thickness=3):
for i from a to b-deltax by deltax do
k:=i+rand()/(1.*10^12)*deltax:
h:=(k)^2:
tot:=tot+k^2*deltax: an2[m]:=plot(h,x=i..(i+deltax),y=-2..16,filled=true,color=GRAY):
m:=m+1:
end do:
p:=plots[display]([seq(an2[m],m=1..n)]):
display(an1,p,title="Random Approximating\nRectangles",titlefont=[TIMES,BOLD,14]);
Approximate_Area:=evalf(tot)*`sq.units`;
>