Riemann Sum Explorer

Cut [a, b] into n strips, give each strip one height read from the curve, and add up the strips. As n grows, every way of choosing the heights closes on one number: the definite integral.

The integral as a limit of sums
Where each sum reads its heights
Which way they miss
Loading interactive simulation...

Lesson

The theory — Riemann Sum Explorer

A Riemann sum of f over [a, b] cuts the interval into n strips, takes one height f(xi*) in each, and adds the strips' areas f(xi*)Δx. The definite integral is the number these sums close on as n → ∞.

What each symbol means

Δx
the width of each strip, (b − a)/n
xᵢ*
the sample point in strip i, where its height is read

Where the formula comes from

  1. Cut the interval. n strips of equal width Δx = (b − a)/n, with edges x0 = a, x1, …, xn = b.
  2. One height per strip. Read f at a sample point xi* anywhere in strip i; this page offers its left edge, its right edge and its middle. The strip's area is f(xi*)Δx, and the Riemann sum adds the n of them. The trapezoid rule uses both edges, and comes out as the average of the left and right sums.
  3. Below the axis counts negative. Where f < 0 the term f(xi*)Δx is negative, so the sum measures the area above the axis minus the area below it. The strips drawn in orange are the ones being subtracted.
  4. Let n grow. For x² on [0, 1] the right sum is (n + 1)(2n + 1)/(6n²), which closes on 1/3. For a continuous f every choice of sample points closes on the same number, and that number is the integral.
  5. Which way a sum misses. If f rises on [a, b], the left sum is too small and the right sum too big. If f is concave up, the midpoint sum is too small and the trapezoid sum too big. A falling or concave-down f swaps each pair.

why pharmacology switches rules halfway through 🖖

Drug exposure is a Riemann sum. A regulator wants the area under a patient's concentration-time curve; what exists is a dozen blood draws, so the standard method is the trapezoid rule between consecutive samples. That inherits the bias this page shows. An elimination curve is convex, the chord lies above it, and the linear trapezoid credits the patient with more exposure than they received. Hence the standard practice: linear up the absorption phase, logarithmic on the way down.

The function no Riemann sum can pin down 🖖

Every sum on this page closes on one number whichever sample points you choose. That is a theorem about functions like these, which are continuous, and it can fail without continuity. In 1829 Dirichlet described a function that is 1 at every rational x and 0 at every irrational one. Every strip, however narrow, contains points of both kinds, so tag each strip at a rational and the sum over [0, 1] is 1; tag each at an irrational and it is 0, at every n. The sums share no limit, and the function has no Riemann integral. Lebesgue's integral of 1902 groups the points by the value f takes there instead of by where they sit on the axis, and gives this function the integral 0.

RIEMANN SUM THEORY — THE DEFINITION BEHIND THE INTEGRAL

Where Do You Sample Inside Each Strip?

A Riemann sum cuts [a, b] into n strips and gives each strip a single height, read off at one sample point inside it. Which point you tag — left edge, right edge, or middle — changes the answer while n is small. As n grows every choice closes on the same number, and that shared limit is what the definite integral means.

Left endpoint — tag at the start of each strip Σ f(xi) Δx
Right endpoint — tag at the end of each strip Σ f(xi+1) Δx
Midpoint — tag at the centre of each strip Σ f(xi + Δx/2) Δx
Trapezoid — both endpoints, averaged Σ ½[f(xi) + f(xi+1)] Δx

01

Left endpoint — tag at the start of each strip

Sample point: Height read at xᵢ, the left edge of strip i. The value at b is never used.

Sum: Σ f(xi) Δx

At small n: x² on [0, 2] with n = 4 gives 1.75 against a true area of 2.667 — a long way short.

Open this case: Four left strips
Left endpoint — tag at the start of each strip. Every rectangle takes its height from its own left edge, so a wedge of curve is left out. Height read at xᵢ, the left edge of strip i. The value at b is never used.
Every rectangle takes its height from its own left edge, so a wedge of curve is left out.

02

Right endpoint — tag at the end of each strip

Sample point: Height read at xᵢ₊₁, the right edge of strip i. The value at a is never used.

Sum: Σ f(xi+1) Δx

At small n: Same curve and n: 3.75 against 2.667 — now overshooting by roughly what the left sum lost.

Open this case: Six right strips
Right endpoint — tag at the end of each strip. The same strips tagged at the right edge — now each rectangle overshoots. Height read at xᵢ₊₁, the right edge of strip i. The value at a is never used.
The same strips tagged at the right edge — now each rectangle overshoots.

03

Midpoint — tag at the centre of each strip

Sample point: Height read at the centre of the strip, so neither edge is privileged.

Sum: Σ f(xi + Δx/2) Δx

At small n: Same curve and n: 2.625 against 2.667 — closer than left and right by an order of magnitude.

Open this case: Forty midpoint strips
Midpoint — tag at the centre of each strip. Sampling at the centre lets each strip’s two errors cancel against each other. Height read at the centre of the strip, so neither edge is privileged.
Sampling at the centre lets each strip’s two errors cancel against each other.

04

Trapezoid — both endpoints, averaged

Sample point: Both edges of the strip are used and the top is slanted between them.

Sum: Σ ½[f(xi) + f(xi+1)] Δx

At small n: Same curve and n: 2.75 against 2.667 — better than either endpoint sum, still behind midpoint.

Open this case: sin x, trapezoids
Trapezoid — both endpoints, averaged. A slanted top joining both edges — the average of the left and right rectangles. Both edges of the strip are used and the top is slanted between them.
A slanted top joining both edges — the average of the left and right rectangles.

Problems solved in full

  1. Estimating ∫₀² x² d x with eight midpoint rectangles 5 steps

    Estimate ∫₀² x² dx with eight midpoint rectangles. Then do better than estimating: combine two wrong answers to get the exact one.

    I − M T − I = 2(I − M) x* h
    1. Eight strips across a width of 2 gives Δx = 0.25, and the midpoint rule takes each rectangle's height at the centre of its strip — 0.125, 0.375, and so on. Sampling at the centre is not an aesthetic preference; step 4 is what it buys.

    2. Sum the eight squared midpoints and multiply by the common width. Nothing so far is approximate except the decision to use rectangles at all.

    3. The exact integral is 8/3, so the estimate is low by 0.0104167. Low, and by an amount worth explaining rather than shrugging at.

    4. The midpoint error is −(b − a)h²f″(ξ)/24. For x² the second derivative is 2 everywhere, so it does not matter where ξ is, and the formula stops being a bound and becomes an equality. It returns −1/96, which is the tool's signed error to the last digit it prints.

    5. The trapezoid rule errs the other way and by exactly twice as much: a midpoint rectangle cuts off as much as it adds, while a trapezoid chord lies wholly above a convex curve. Weight them two to one and the errors cancel.

    Answer

    Midpoint gives 2.65625 against a true 2.666667, and because x² rises on [0, 2] the left and right sums, 2.1875 and 3.1875, bracket the integral. Keep the last line, though: (2M + T)/3 = 8/3 exactly, from eight strips and no extra evaluations. That weighted average is Simpson's rule, published by Thomas Simpson in 1743 and used for a single strip by Kepler in 1615 to gauge wine barrels. Two crude rules fail in a fixed ratio, so their errors can be cancelled by construction. Switch the function to x³ and the midpoint and trapezoid sums are 3.96875 and 4.0625; combined they give 4, dead on, because Simpson's rule is exact for every cubic. Switch to x⁴ and it finally misses, by 0.000065 against 6.4.

  2. Left and right sums for a falling curve 4 steps

    Estimate ∫₁² (1/x) dx with four strips, by the left sum and by the right sum. Which is too big, and how can you tell without knowing the answer?

    Open this problem in the tool

    Show solution
    1. Four strips across [1, 2] are each 0.25 wide. The left sum reads heights at 1, 1.25, 1.5 and 1.75; the right sum at 1.25, 1.5, 1.75 and 2.

    2. Add the left heights and multiply by the width:

    3. The right sum drops f(1) = 1 and gains f(2) = 0.5, so it is smaller by 0.25 × 0.5:

    4. 1/x falls across the interval, so each strip's left edge is its highest point and its right edge its lowest. The left sum is too big and the right sum too small:

    Answer

    L₄ = 0.759524 is too big and R₄ = 0.634524 too small; the integral, ln 2 = 0.693147, lies between them. For a function that only falls, or only rises, on the interval, the left and right sums always bracket the integral, and they differ by Δx·|f(b) − f(a)|, here 0.125.

  3. The trapezoid rule, and which way it misses 4 steps

    Use the trapezoid rule with four strips to estimate ∫₀⁴ √x dx. Is the estimate too big or too small?

    Open this problem in the tool

    Show solution
    1. Δx = 1, and the trapezoid rule uses the heights at all five edges, the inner three twice:

    2. Put the numbers in:

    3. The same number is the average of the left and right sums:

    4. √x is concave down, since f″(x) = −¼x−3/2 < 0. Every chord lies below the curve, so every trapezoid leaves out a sliver:

    Answer

    T₄ = 5.146264, too small by 0.187069, because √x is concave down. On a concave-up curve the chords lie above it and the trapezoid rule overestimates. The midpoint rule errs the other way in both cases, so the two sums together trap the integral.

  4. An integral as the limit of right sums 4 steps

    Write the right sum for ∫₀³ x² dx with n strips, and find the integral as its limit.

    Open this problem in the tool

    Show solution
    1. Δx = 3/n and the right edges are xi = 3i/n, so strip i contributes (3i/n)²·(3/n):

    2. The sum of the first n squares is n(n + 1)(2n + 1)/6:

    3. Check one value before trusting the formula. At n = 6 it gives 11.375, which is what six right strips add up to:

    4. Now let n grow. Divide top and bottom by n²:

    Answer

    ∫₀³ x² dx = 9. Six strips overshoot by 2.375, and the formula says the overshoot is 27/(2n) + 9/(2n²) in general, so it shrinks like 1/n, the rate of an endpoint sum.

  5. Reading a limit of sums as an integral 3 steps

    Evaluate the limit, as n → ∞, of Σ (2/n)·√(1 + 2i/n), summed from i = 1 to n.

    Open this problem in the tool

    Show solution
    1. Match the pattern Σ f(xi)Δx. The factor 2/n is Δx, so b − a = 2, and xi = 1 + 2i/n starts at a = 1 when i = 0 and reaches b = 3 when i = n:

    2. So the sum is the right sum of √x on [1, 3], and its limit is the integral:

    3. Integrate:

    Answer

    The limit is ⅔(3√3 − 1) = 2.797435. The same sum can also be read with xi = 2i/n, as √(1 + x) on [0, 2]; that integral is 2.797435 too, which is a quick check that the reading was right.

  6. Area below the axis counts negative 3 steps

    Find ∫₋₁² x dx, compare it with the area between the line y = x and the x-axis, and check it against the left sum with six strips.

    Open this problem in the tool

    Show solution
    1. The line is below the axis on [−1, 0] and above it on [0, 2]. The two triangles have areas ½ and 2:

    2. In the integral the triangle below the axis counts negative; in the area it does not:

    3. Six left strips of width 0.5 read heights −1, −0.5, 0, 0.5, 1 and 1.5. The first two are negative and subtract:

    Answer

    ∫₋₁² x dx = 3/2, while the area between the line and the axis is 5/2. A Riemann sum adds f(xi*)Δx with its sign, so it closes on the first; for the area, integrate |x|. The left sum of 0.75 is low because the line rises, and the midpoint sum is exactly 1.5 at every n, since under a straight line a midpoint rectangle has the same area as its trapezoid.

  7. A sum from a table of measurements 3 steps

    A car's speed is read at t = 0, 2, 5, 7 and 10 s and is 0, 8, 14, 17 and 20 m/s. Estimate the distance travelled in those 10 seconds with a left sum, a right sum and the trapezoid rule.

    Show solution
    1. The strips are not equal: their widths are 2, 3, 2 and 3 s. Each strip's area is its own width times a height, so no common Δx comes out of the sum. The left sum uses the speed at the start of each interval:

    2. The right sum uses the speed at the end of each interval:

    3. The trapezoid rule averages the two ends of each strip, which on unequal strips is still the average of the left and right sums:

    Answer

    L = 103 m, R = 152 m, T = 127.5 m. The speed never falls in the table, so if it rose steadily between readings the distance lies between 103 m and 152 m. The table cannot promise that: a car can brake between two readings, and no sum over these five numbers would know.

Learning path

Why everything looks straight up close

References (4)