A Riemann sum is an approximation of the definite integral of a function—the area between a curve and the x axis, with areas below the axis treated as negative. (The functions must meet some technical requirements; refer to the Wikipedia pages for those details.)
To compute the approximation, the interval is divided into n subintervals (typically, though not necessarily, of equal width). On each subinterval, a rectangle is constructed, the height of which is equal to the value of the function at some point in that subinterval. The collective area of those rectangles is roughly equal to the area under the curve; the approximation grows better for large n (assuming the function meets the technical requirements mentioned before).
In the formulas shown above the graph, the endpoints of the subintervals are denoted
x0 = a, x1 = a + Δx, …, xn = b, where [a, b] is the overall interval, and Δx is given by the formula below.
That is, the n subintervals are
[x0, x1], [x1, x2], etc.
The midpoints of those intervals (used by the midpoint and Simpson's methods) are denoted
x0.5, x1.5, etc.
For the "random point" method, we choose a random point in each interval, denoted
x1*, x2*, etc.
Because Simpson's method requires an even number of subintervals, the subscript for the Simpson's estimate is always equal to 2n.
The adaptive Simpson's method does not use the specified number of subintervals; instead, it divides the interval in half, then divides those subintervals in half, and then divides those subintervals in half, etc., stopping when it finds that the estimated area does not change substantially with further subdivisions. A full description is beyond the scope of this page, but more information can be found in a numerical analysis textbook, or at Wikipedia (and elsewhere on the Web).
(11/26/2013) First release: This page has been tested on Chrome, Firefox, and Explorer. For some reason, it seems to run slowly in Firefox; I'll try to figure out why, but don't hold your breath.
(11/30/2013) Added "random point" sum, and slight improvements to the interface. Firefox slowdown fixed (I think).
(12/1/2013) Added "saving" link, allowing extended web addresses like riemannsums.html?cos(x)&0&2pi&20&1 or riemannsums.html?e^x from 0 to 5.
(12/19/2013) Added adaptive Simpson's method, showing the function evaluation points to get a nearly exact value of the integral.
(5/10/2020) Removed MooTools dependency.
TODO (someday): Add more methods (Newton-Cotes quadrature, etc.)
The contents of this page are © 2020 Darryl Nester. It is available to anyone who wishes to use it (like most things on the Internet). Please send me an email if you have found it to be useful, or if you have suggestions.