Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools


Riemann Sum

How to use
  1. The Function menu at the top lists eight functions in three groups: Polynomial, Transcendental and Numerical only. A new function keeps aa, bb, nn and the rule. Learn more about the function families
  2. The tabs Left, Right, Midpoint and Trapezoid choose where each strip samples ff; the strips, the numbers and the explanation change at once. Learn more about the four methods
  3. The sliders set the lower bound aa and upper bound bb (from −8-8 to 88) and the number of strips nn (from 11 to 8080); ▶ runs a slider by itself, Speed sets how fast, and Reset restores a=0a = 0, b=3b = 3, n=8n = 8. Learn more about the sliders
  4. The amber labels along the bottom of the graph give SnS_n, the true integral and the error Sn−∫abfS_n - \int_a^b f. Learn more about the numbers
  5. The text on the right says whether the sum overshoots, undershoots or is essentially exact. Learn more about overshooting and undershooting
  6. Its two tabs: Explanation works through the current setup, Concepts covers the four rules and convergence order. The buttons at the top zoom, save a picture and open full screen. Learn more about the Concepts tab


Riemann sums
f(x)=x2f\left(x\right)={x}^{2}
a=0a = 0b=3b = 3n=8n = 8Sn=7.3828S_n = 7.3828∫abf=9\int_a^b f = 9error=−1.6172\text{error} = -1.6172
Left Riemann sum · Quadratic
Sn=Δx∑i=0n−1f(a+i Δx)\displaystyle S_n = \Delta x \sum_{i=0}^{n-1} f(a + i\,\Delta x)
General

The interval [a,b][a, b] is split into nn equal strips of width Δx=(b−a)/n\Delta x = (b - a)/n. For each strip, the height comes from sampling ff at the left endpoint of each strip.

For the current setup

Integrating from 00 to 33 with n=8n = 8 strips, so Δx=0.375\Delta x = 0.375.

  • Sn=7.3828S_n = 7.3828
  • True integral =9= 9
  • Error =Sn−I=−1.6172= S_n - I = -1.6172
Why the sum lands where it does

Endpoint rules sit entirely above or below the curve when the function is monotonic on a strip. On the current interval the sum undershoots the true integral by 1.61721.6172.

Convergence order

For smooth functions the left rule converges as O(1/n)O(1/n). Push the nn slider higher and watch the error shrink — doubling nn roughly halves the error.

a=0a = 0
b=3b = 3
n=8n = 8
Speed





Key Terms



Key Terms

Riemann sum — an approximation of the definite integral ∫abf(x) dx\int_a^b f(x)\, dx formed by partitioning [a,b][a, b] into nn equal strips and summing the areas of simple shapes built on each strip.

Partition — the division of [a,b][a, b] into nn subintervals of equal width Δx=(b−a)/n\Delta x = (b - a)/n.

Sample point — the value of xx on each strip where the function's height is evaluated. Determined by the rule: left endpoint, right endpoint, midpoint, or both endpoints (for trapezoid).

Left Riemann sum — sample at the left endpoint of each strip; uses rectangles.

Right Riemann sum — sample at the right endpoint of each strip; uses rectangles.

Midpoint rule — sample at the center of each strip; uses rectangles.

Trapezoid rule — average the function values at the two endpoints of each strip; uses trapezoids.

Convergence order — the rate at which the error shrinks as nn grows. Left and right are O(1/n)O(1/n); midpoint and trapezoid are O(1/n2)O(1/n^2).

Getting Started

The tool opens with f(x)=x2f(x) = x^2, integrating from a=0a = 0 to b=3b = 3 with n=8n = 8 strips by the Left rule. You see:

• The blue curve of ff.

• Eight amber strips, each as tall as the curve at its left edge.

• Dashed gray vertical lines at aa and bb marking the bounds.

Along the bottom of the graph, small labels give aa, bb and nn, and three amber labels give the sum SnS_n, the true integral ∫abf\int_a^b f and the error. The text on the right works through the current setup and says whether the sum overshoots or undershoots.

To explore, choose Left, Right, Midpoint or Trapezoid in the tabs on the right, drag the sliders for aa, bb and nn, or pick another function in the Function menu at the top.

The Four Methods

DemoThe four methods
Step 0 of 4
The four tabs above the sliders offer four ways to build the approximation. Each samples the function at a different point of each strip:

• Left — sample at the left endpoint. On an increasing function every rectangle sits below the curve; on a decreasing function every rectangle sits above. Convergence order O(1/n)O(1/n).

• Right — sample at the right endpoint. Mirror image of left: overshoots on increasing, undershoots on decreasing. Same O(1/n)O(1/n) order.

• Midpoint — sample at the center. The flat top punches above the curve on one half of each strip and below on the other, so over- and under-shoots within each strip mostly cancel. Convergence order O(1/n2)O(1/n^2).

• Trapezoid — connect the left and right endpoint heights with a straight line. Errors also mostly cancel, opposite in sign to midpoint. Same O(1/n2)O(1/n^2) order.

Switching tabs changes the strips, the numbers and the explanation at once; aa, bb and nn stay as they are.

Left Rule: Every Rectangle Falls Short

On the tool's opening setup — f(x)=x2f(x) = x^2 from a=0a = 0 to b=3b = 3 with n=8n = 8 strips, so Δx=0.375\Delta x = 0.375 — the left rule takes each rectangle's height from the left edge of its strip.

S8=7.3828S_8 = 7.3828 against a true integral of 99, an error of −1.6172-1.6172.

Because x2x^2 is increasing across the whole interval, the left edge is the lowest point of every strip. Every rectangle sits under the curve, and the sum has to come in low.
1 2 3 -2 -1 1 2 3 4 5 6 7 8 9 10 11 x y f(x) = x²
Left rule, frozen at n = 8

Every rectangle top meets the curve at its left edge and falls away below it after that. The eight gaps between the tops and the curve are the -1.6172 of error, drawn to scale.

That undershoot is not a quirk of these numbers — it is guaranteed for any increasing function. Reverse the situation and the guarantee reverses with it: on a decreasing function the left rule overshoots by exactly the same reasoning.

The gaps between the rectangle tops and the curve are the error, laid out visually. Each one is roughly a triangle of width Δx\Delta x and height f′(x)Δxf'(x)\Delta x, so halving Δx\Delta x quarters each gap but doubles their number — leaving the total error only halved. That is the O(1/n)O(1/n) behaviour discussed under convergence and error.

Right Rule: Every Rectangle Overshoots

Same interval, same eight strips, height taken from the right edge instead.

S8=10.7578S_8 = 10.7578, an error of +1.7578+1.7578.

On an increasing function the right edge is the highest point of each strip, so every rectangle pokes above the curve and the sum comes in high.
1 2 3 -2 -1 1 2 3 4 5 6 7 8 9 10 11 x y f(x) = x²
Right rule, frozen at n = 8

The mirror image: each top meets the curve at its right edge, so the whole strip sits above the curve. The overshoot of +1.7578 is the visible excess.

The two endpoint rules bracket the answer: 7.3828<9<10.75787.3828 < 9 < 10.7578. That is genuinely useful — on a monotonic function the left and right sums are a rigorous lower and upper bound, so the true value is trapped between them without any further argument.

Their average, (7.3828+10.7578)/2=9.0703(7.3828 + 10.7578)/2 = 9.0703, is precisely the trapezoid rule result. Averaging the two one-sided errors cancels most of what each gets wrong, which is why the trapezoid rule converges an order faster than either of the rules it is built from.

Midpoint Rule: Errors That Cancel Inside Each Strip

Height sampled at the centre of each strip rather than an edge.

S8=8.9648S_8 = 8.9648, an error of just −0.0352-0.0352 — roughly fifty times smaller than either endpoint rule on the same eight strips.

Each rectangle now cuts through the curve rather than sitting under or over it: it is too low on the right half of its strip and too high on the left half, and the two halves very nearly cancel.
1 2 3 -2 -1 1 2 3 4 5 6 7 8 9 10 11 x y f(x) = x²
Midpoint rule, frozen at n = 8

Each rectangle now crosses the curve rather than clearing it, too high on one side of the strip and too low on the other. What is left over after they cancel is -0.0352.

That near-cancellation is what buys the extra order of accuracy. The midpoint rule is O(1/n2)O(1/n^2), so doubling the strip count cuts the error by about four rather than two.

There is a tidier way to see it. A midpoint rectangle has exactly the same area as the trapezoid formed by the tangent line at that midpoint, so the midpoint rule is really a tangent-line approximation in disguise. For a function curving one way throughout — as x2x^2 does — that tangent lies below the curve, which is why the midpoint result lands slightly under the true value.

Trapezoid Rule: Joining the Sample Points

Instead of a flat top, each strip is capped by the straight line joining ff at its two edges.

S8=9.0703S_8 = 9.0703, an error of +0.0703+0.0703 — about twice the midpoint error, and in the opposite direction.

The shaded shapes are visibly slanted here, which is the one method where the outline follows the curve's direction rather than stepping across it.
1 2 3 -2 -1 1 2 3 4 5 6 7 8 9 10 11 x y f(x) = x²
Trapezoid rule, frozen at n = 8

The only method whose outline slants with the curve: each cap is the chord between the two strip edges. On an upward-curving function the chord rides above, giving +0.0703.

The sign is predictable. A chord across a strip of an upward-curving function lies above the curve, so the trapezoid rule overshoots whenever f′′>0f'' > 0 and undershoots whenever f′′<0f'' < 0. The midpoint rule errs the other way for the same reason, which is why the two bracket the answer: 8.9648<9<9.07038.9648 < 9 < 9.0703.

They also err in a fixed ratio — the trapezoid error runs about twice the midpoint error and opposite in sign. Combining them in the proportion that cancels both, 2⋅mid+trap3\frac{2 \cdot \text{mid} + \text{trap}}{3}, gives exactly 99 here. That combination is Simpson's rule, which is accurate to O(1/n4)O(1/n^4) in general and exact for any polynomial of degree three or less — so on x2x^2 it lands on the true value with only eight strips.

The Function Families

DemoOther functions
Step 0 of 3
The Function menu at the top lists eight functions in three groups.

Polynomial (closed-form antiderivative):

• Identity f(x)=xf(x) = x — integrates to x2/2x^2 / 2.

• Quadratic f(x)=x2f(x) = x^2 — integrates to x3/3x^3 / 3.

• Cubic f(x)=x3f(x) = x^3 — integrates to x4/4x^4 / 4.

Transcendental (closed-form):

• Sine f(x)=sin⁡xf(x) = \sin x — antiderivative −cos⁡x-\cos x.

• Cosine f(x)=cos⁡xf(x) = \cos x — antiderivative sin⁡x\sin x.

• Exponential f(x)=exf(x) = e^x — antiderivative exe^x.

Numerical only (no elementary antiderivative):

• Gaussian bump f(x)=e−x2/2f(x) = e^{-x^2/2} — the kernel of the normal distribution.

• Sinc f(x)=sin⁡(x)/xf(x) = \sin(x)/x — appears in signal processing.

A new function keeps aa, bb, nn and the rule, and moves the view to fit the curve. The true integral is always worked out numerically, to far more accuracy than the four decimals shown, so it is the same for every family whether or not a formula exists.

The a, b, and n Sliders

DemoMore strips, smaller error
Step 0 of 4
Three sliders under the tabs control the setup:

• lower bound aa and upper bound bb, from −8-8 to 88 — the endpoints of the interval. The dashed gray lines on the graph follow them. Setting b<ab < a flips the sign of the integral; everything else still works.

• number of strips nn, from 11 to 8080. As nn grows the strips get thinner, fill the area under the curve more tightly, and the error shrinks.

Each slider has a ▶ button that runs it back and forth by itself, and the Speed buttons set how fast. Reset puts aa, bb and nn back to 00, 33 and 88.

The most instructive experiment: fix a rule, then move nn from low to high and watch the error label. With the left or right rule, doubling nn roughly halves the error. With midpoint or trapezoid, doubling nn shrinks the error by about a factor of four.

Reading the Numbers on the Graph

Three amber labels along the bottom of the graph give the results:

• SnS_n — the value of the Riemann sum for the current rule and nn.

• ∫abf\int_a^b f — the true value of the integral, the number the sums are closing in on.

• error — the signed difference Sn−∫abfS_n - \int_a^b f. Positive means the sum is too high (overshoots); negative means too low (undershoots); near zero means the approximation has converged.

Beside them, white or blue labels repeat aa, bb and nn; a label turns blue once its value has moved from the start. The same three numbers, with Δx\Delta x, open the text on the right. Use them together: the sum is what you computed, the integral is what you wanted, and the error is the gap to close.

Overshoots or Undershoots

Under Why the sum lands where it does, the text on the right says in words how the sum compares with the true integral:

• overshoots — the sum is larger than the integral, by the amount it gives. Common for the left rule on a decreasing function, or the right rule on an increasing function.

• undershoots — the sum is smaller. Common for the left rule on an increasing function, or the right rule on a decreasing function.

• is essentially exact — the two differ by less than 0.00010.0001. Either the rule is exact for this function (the trapezoid rule on a linear function, for example) or nn is large enough that the sum has converged.

The endpoint rules (left, right) have predictable signs based on monotonicity. Midpoint and trapezoid usually err in opposite directions, which is why combining them gives Simpson's rule — a more advanced technique.

Zoom, Pictures and the Concepts Tab

DemoThe Concepts tab
Step 0 of 3
The buttons at the top right zoom in and out, return to the starting view, save the graph as a picture and open the tool full screen. Zooming never changes the sum.

The switch Strips and bounds under the sliders hides or shows the strips and the dashed lines, leaving the curve alone.

The text on the right has two tabs.

• Explanation follows the current setup. It gives the rule and its formula, then aa, bb, nn and Δx\Delta x, the values of SnS_n, the true integral and the error, a short paragraph on why the rule over- or undershoots here, and the rule's convergence order. It rewrites itself whenever you change the function, the rule or a slider.

• Concepts does not change with the controls: what a Riemann sum is, the four rules, convergence order, signed areas, and what happens when there is no closed-form integral.

For the three numbers themselves, see the numbers on the graph.

What Is a Riemann Sum

A Riemann sum approximates the area under a curve using simple geometric shapes. The procedure is:

• Split the interval [a,b][a, b] into nn subintervals of equal width Δx=(b−a)/n\Delta x = (b - a)/n.

• On each subinterval, pick a sample point xi∗x_i^* and use the function's value there as a height.

• Sum the areas of the resulting rectangles (or trapezoids):

Sn=∑i=1nf(xi∗)⋅ΔxS_n = \sum_{i=1}^{n} f(x_i^*) \cdot \Delta x


The four classical rules differ only in where on each subinterval the sample point sits. As n→∞n \to \infty, the Riemann sum converges to the exact definite integral:

lim⁡n→∞Sn=∫abf(x) dx\lim_{n \to \infty} S_n = \int_a^b f(x)\, dx


This limit is in fact the definition of the integral. The Fundamental Theorem of Calculus then provides the shortcut: evaluate an antiderivative at the endpoints instead of summing rectangles.

For full theoretical coverage, see the Riemann integral page.

Convergence and Error

The four rules differ not just in how they sample the curve, but in how fast the error shrinks as nn grows.

Endpoint rules (Left and Right): error is O(1/n)O(1/n).

Each rectangle's flat top mismatches the curve's slope. Doubling nn halves the strip width and roughly halves the error. To reduce the error by a factor of 100100, you need nn to grow by a factor of 100100.

Midpoint and Trapezoid: error is O(1/n2)O(1/n^2).

Both rules sample more representatively. Midpoint takes the height at the center of each strip; trapezoid uses the linear interpolant between endpoint heights. In either case the over- and undershoots within a single strip largely cancel, so the leading-order error is in 1/n21/n^2 instead of 1/n1/n. Doubling nn shrinks the error by a factor of four. To reduce the error by 100100, nn only needs to grow by 1010.

The practical lesson: choose the rule before you crank up nn.

Signed Area

When the integrand dips below the x-axis, the function values become negative and the corresponding rectangles count as negative area. The tool draws them on the appropriate side of the axis and the Riemann sum subtracts them naturally.

This matches the standard convention for definite integrals: ∫abf(x) dx\int_a^b f(x)\, dx is the signed area between the curve and the x-axis, counting area above the axis positively and area below negatively. A function that's symmetric about the x-axis (like sin⁡x\sin x over [−π,π][-\pi, \pi]) has integral zero — positive and negative areas cancel.

Two other sign conventions are also handled correctly:

• If you set b<ab < a, the strip width Δx=(b−a)/n\Delta x = (b - a)/n goes negative, every term in the sum flips sign, and the result becomes −∫baf(x) dx-\int_b^a f(x)\, dx. This is the standard ∫ab=−∫ba\int_a^b = -\int_b^a identity.

• If a=ba = b, every strip has zero width and the sum collapses to zero.