Riemann Sums: A Symbolic and Graphical Approach  


Objective: This demo uses a computer algebra system to investigate various approximations to the definite integral. Right hand endpoint, left hand endpoint and midpoint Riemann sums as well as trapezoidal and Simpson's rules are expressed in closed form as functions of . Behavior as approaches 0 is observed.  This demo helps students to 

  • understand the definition of Riemann sum and why Riemann sums approximate the definite integral;
  • demonstrate that the limit of a Riemann sum is the same for (almost) any choice of points from each subinterval;
  • investigate combinations of Riemann sums that lead to better approximations to the definite integral;
  • appreciate the meaning of rate of convergence of an approximation.

Level:  This demo can be presented in any course in which definite integration using Riemann sums is discussed. While this will often be a topic of discussion in a Calculus class, it is also appropriate for a numerical analysis class.

Prerequisites: Students should be familiar with Riemann sums.  The concepts of upper and lower sums should have been introduced.  In addition, it would be useful if students have been introduced to graphical notions of limits and limiting behavior.  Simpson's rule and the trapezoidal rule are also illustrated, that portion of the demo should be shown after students have been introduced to these approximate methods.

Platform:  Any  computer system with Mathematica or Maple.  The downloadable worksheets were developed in Mathematica 4 and Maple 6.

Instructor's Notes:  

As first examples, it is helpful to investigate common functions, such as polynomials.  

NOTE:  When the definite integral is introduced, it is often an area calculation.  This the case when the function is nonnegative over the interval.  The example in this demo leads to an appreciation that the definite integral is not always an area of a region and thus is not always positive.

Evaluate .

A usual and important approach is to partition the interval [0,2] into n equal subintervals and construct n rectangles over the subinterval with (signed) heights determined, for example, by right hand endpoints, left hand endpoints, or midpoints of the subintervals.  An approximation for the definite integral is determined by the sum of the signed areas of the n rectangles.  For this example, we construct the Riemann sum for this integral by dividing the interval [0,2] into n subintervals of equal width so that = 2/n.  

Using right hand endpoints, the Riemann sum that approximates the definite integral (computed here by Mathematica) is 

NOTE:  In this example, the interval is [0,2], so the points at which we evaluate the function are multiples of .   For a general interval [a,b] and using right hand endpoints, we evaluate the function at , where k = 1, 2, ..., n.  This remark extends to the other approximation methods as well.

The rectangles determined using right hand endpoints, and the computed values for the Riemann sums for n = 1 to n = 30 are displayed in the animation in Figure 1.  The left hand graph shows the rectangles while the right hand side shows a graph of the values of the Riemann sums as they are computed.  As n becomes larger, the rectangles appear to fill the region between the curve and the x-axis.  It also appears that the approximations seem to be leveling off to some (as yet unknown) value.  Note that for n = 1, the rectangle is completely below the x-axis, so the approximation is negative.  For n > 1, there are rectangles above and below the x-axis, providing some cancellation.  However, it is reasonable to think there is a strong possibility that if the approximations are approaching a limiting value, that value will be negative.


Figure 1.  Riemann sums computed using right hand endpoints.

Using left hand endpoints, the Riemann sum is


Figure 2 shows the approximating rectangles for the left hand endpoint Riemann sum and the corresponding approximations to the definite integral.


Figure 2.  Riemann sums computed using left hand endpoints.

We will now compute the Riemann sum using the midpoints of the subintervals.  The midpoint, mk, of each subinterval with width can be computed by averaging the endpoints.  Thus, for this approximation scheme, we evaluate the function at   .

(On a general interval [a,b],  the midpoints are .)

For this example, the midpoint approximation is


Figure 3 shows the approximating rectangles for the midpoint Riemann sum and the corresponding approximations to the definite integral.


Figure 3.  Riemann sums computed using midpoints.

In each of the previous cases, it appears that the computed values of the Riemann sums will eventually approach a limiting value as n becomes large.  But does each method produce the same limiting value?  Figure 4 provides convincing evidence that for this example, the answer appears to be "YES."


Figure 4.  Right Hand, Left Hand, Midpoint Approximations

An important geometric observation to point out to students is that as n becomes larger, the width of each rectangle, , becomes smaller.  This is a nice alternative approach to the usual textbook presentation because considering the limit as ->0 is an easier concept for many students to understand than the more abstract idea of a limit as n -> Infinity.  This is also an easier approach from a computational standpoint, particularly when the Riemann sums for a polynomial can be computed exactly using a symbolic algebra package.  

The symbolic expressions we have obtained so far for the Riemann sums involve both n and .  To express the sums in terms of only,  substitute n = 2/.  The simplified expressions (using Mathematica) for the right hand endpoint, left hand endpoint, and midpoint Riemann sums are, respectively, 

RHE( ) = ,

LHE() = , and 

MidPt( ) = .

From these symbolic expressions, it is easy to see that as approaches 0, all three expressions approach the exact limiting value -218/15, approximately -14.533. 

Figure 5 shows plots of the graphs of the right hand, left hand, and midpoint approximations generated as approaches 0.


Figure 5.  Right hand, left hand, and midpoint approximations generated as approaches 0.  (For these calculations, we used n = 50 and displayed every other frame.)

From Figure 5, it seems that the midpoint Riemann sums approach the limiting value faster than the other two approximations.  NOTE:  This observation allows us to introduce the idea of "rate of convergence," discussed below.

This example can convince students that Riemann sums using left and right hand endpoints and midpoints of the subintervals converge to the same value as , but what about other partitions of the interval and other choices for the points in the subintervals at which to evaluate the function?  A computer algebra system cannot be used to compute a Riemann sum in closed form for an arbitrary partition of the interval, however, if we use a consistent method for choosing the points in the subintervals having equal widths, we can obtain a closed form expression for the Riemann sum.  

One way to accomplish this is to require that = 2/n and choose the points xk* inside each subinterval by the following

and s varies between 0 and 1.  If s = 0, this corresponds to choosing right hand endpoints and if s = 1, we obtain the left hand endpoints.  If, for example, s = 1/2, the chosen points are the midpoints of the subintervals.

Using this scheme, we see that 

which simplifies to 

when we set n = 2/.

It is clear from this expression that the limit as is -218/15.

Other Approximation Schemes: Trapezoidal and Simpson's Rules

Another approximation we can use involves averaging the approximations for the right and left hand endpoints.  This approximation scheme is called the trapezoidal rule.  If the right and left hand endpoint approximations are expressed as functions of , the trapezoidal rule is


Another combination of the approximations yields one form of Simpson's rule:

= .

Note:  This is not the usual formulation for Simpson's rule. See the reference to find an explanation of how this form corresponds to the classical formulation for Simpson's rule.

It is clear from these expressions that each will approach the limit -218/15 as .  But how do these approximation schemes compare to the previous schemes?  To answer that question, we introduce the idea of "rate of convergence."

Rate of Convergence

The rate of convergence of a numerical algorithm for approximating a limiting value gives a general idea of how fast the algorithm approaches the limit.  From a computational point of view, the faster the algorithm converges, the better.  One way to quantify the rate of convergence is by looking at the absolute value of the errors generated by the approximations.

Looking at the symbolic expressions for the various approximations,

RHE( ) =

LHE() =

MidPt( ) =


= ,

we see that if is very close to zero, the absolute value of the errors in the approximations are dominated by the term that is proportional to the lowest nonzero power of .  We will refer to this term as the dominant term in the error.  The dominant terms in the error for each of the right hand and left hand Riemann sums are proportional to (we say that the convergence rate is linear).  For each of the midpoint and trapezoidal approximations, the dominant terms in the error are proportional to (we say that the convergence rate is quadratic).  The dominant term in the error for Simpson's rule is proportional to .  Generally, the higher the (nonzero) power of in the dominant term in the error, the faster the convergence to the limit.  At this relatively early stage in Calculus, these ideas do not mean much to students, however, a graphical approach to these ideas can be very helpful.  

A dramatic visual tool for the rate of convergence is to plot the values of the various approximation methods as a function of and examine n, , error, and the ratio of errors at consecutive steps, as we halve .  If the dominant term in the error is proportional to , the ratios should approach 1/2.  If the dominant term in the error is proportional to , the ratios should approach 1/4.  Similarly, if the dominant term in the error is proportional to , the ratios should approach 1/16.  This also provides a useful tool for discussion of the meaning of "big oh" notation in a numerical analysis course.  

The animations below illustrate the linear convergence of the right hand and left hand approximations and the quadratic convergence of the midpoint and trapezoidal approximations.  The rapid convergence of Simpson's rule due to the fact that dominant term in the error is proportional to .  Note that vertical scales are adjusted so that behavior near = 0 can be more easily observed.  Convergence for the midpoint and trapezoidal rule approximations is fast, but convergence for Simpson's rule is much faster.  A table of the data generated by each approximation scheme is interesting to include in a discussion after the presentation of the animations.


Right Hand Endpoint Approximation


Left Hand Endpoint Approximation


Midpoint Approximation


Trapezoidal Rule Approximation


Simpson's Rule Approximation


Other interesting examples are cubic polynomials, trigonometric functions, and the ideas extend quite naturally to double integrals.

Additional Resources:

Mathematica 4:  Click here to preview and download a Mathematica notebook that generates the calculations and animations illustrated in the demo.

Maple 6:  Click here to preview and download a Maple 6 worksheet that accompanies this demo.

Credits:  This demo was adapted from 

Lawrence H. Riddle, Symbolic and Graphical Investigations of Riemann Sums with a Computer Algebra System, PRIMUS, VI, No. 4 (December 1996), 366-380.

We appreciate the demo suggestion and accompanying Maple worksheet from

Dr. Larry Riddle
Department of Mathematics
Agnes Scott College
Decatur, GA  30030

Additional Mathematica and Maple worksheets were developed by Lila Roberts.

Additional information regarding possible use of this demo:

In his class, Dr. Riddle provides a Maple worksheet that allows students to investigate left, right, and midpoint Riemann sums as well as sums obtained from the trapezoidal and Simpson's rules.   Each sum simplifies to a closed-form formula in terms of the number of points in the partition.  The student can then investigate such issues as what happens to the sum in the limit as n goes to infinity or how the errors for the different sums change as n changes.  The worksheet also allows students to plot the approximations as functions of n to illustrate the convergence rates to the limit.  The goal of the worksheet is to help students to realize that (at least for polynomials)

  1. All five of the sums converge to the value of the integral as n -> Infinity.

  2. The left and right sums approximate the integral with an error that is proportional to 1/n and each error is approximately the same, but of opposite sign.

  3. The midpoint and trapezoidal approximations have an error that is proportional to 1/n2 and that the midpoint error is about half the size of the trapezoidal error but opposite in sign.

  • The error for Simpson's rule is proportional to 1/n4.

  • Dr. Riddle uses this worksheet in class with a specific example where we observe the behaviors described above.  Then each student investigates her own 4th degree polynomial (where coefficients are obtained from the digits of her social security number) to see if the same behavior occurs for her sums.  If one is lucky, one of the students will end up with a cubic polynomial and observe that Simpson's rule gives the exact value of the integral for all values of n.

    Preview Dr. Riddle's worksheet here. Download the Maple worksheet by clicking here.

     Last updated 5/23/2006  (DRH)
    Previous counter information was lost.

    Visitors since 2/8/2005