HomeArticlesMathematics

Riemann Sums: From Rectangles to Simpson's Rule

Left, right, midpoint, trapezoid and Simpson rules compared, and why each one squeezes more accuracy out of the same number of slices.

mysimulator teamUpdated June 2026≈ 7 min read▶ Open the simulation

The area under a curve, sliced into rectangles

The definite integral of f from a to b is defined as the limit of a sum of thin rectangular strips — the Riemann sum — as the strip width goes to zero. Split [a,b] into n equal strips of width Δx = (b-a)/n, pick a sample point in each strip, and add up base times height:

∫ f(x) dx  ≈  Σ f(xi) · Δx      for i = 0 .. n-1

left rule:     xi = a + i·Δx                (sample at left edge)
right rule:    xi = a + (i+1)·Δx            (sample at right edge)
midpoint rule: xi = a + (i+0.5)·Δx          (sample at strip centre)
live demo · rectangles approximating the area under a curve● LIVE

Bernhard Riemann formalised this construction in 1854 to make precise exactly which functions can be integrated at all — a Riemann integral exists whenever the sum converges to the same value no matter how you choose the sample point in each strip, as the strips get arbitrarily thin. That existence question turned out to be subtle (some bounded functions are not Riemann-integrable), which is part of why Lebesgue later built a more general theory, but for any continuous function on a closed interval — nearly every function you will simulate — the Riemann sum converges cleanly and is exactly what a computer approximates when it cannot evaluate an integral symbolically.

Left, right, and why both are biased

On a function that is monotonically increasing and convex, the left rule systematically underestimates the true area (every rectangle sits below the curve on the left) while the right rule systematically overestimates it. The two errors have the same sign as the function's slope, and averaging the left and right sums exactly cancels the first-order error term — which is precisely the trapezoid rule, geometrically equivalent to replacing each rectangle with a trapezoid that connects f(xi) to f(xi+1) with a straight line instead of a flat top.

trapezoid:  ∫ f dx ≈ Δx · [ f(x0)/2 + f(x1) + f(x2) + ... + f(xn-1) + f(xn)/2 ]

Midpoint: the same order, half the constant

The midpoint rule also cancels the first-order error, for a different reason: sampling at the centre of each strip means the curve's slope overshoots on one half of the strip and undershoots by almost exactly the same amount on the other half. Both trapezoid and midpoint have error that shrinks as O(Δx²) — twice as many strips means four times less error — compared to O(Δx) for the naive left or right rule. Interestingly, the midpoint rule's error constant is about half the size of the trapezoid rule's and has the opposite sign, which is the reason combining them cleverly does even better.

Simpson's rule: fitting a parabola instead of a line

Simpson's rule takes that combination explicitly: weight the midpoint rule twice as heavily as the trapezoid rule (2·midpoint + trapezoid, divided by 3), which is algebraically identical to fitting a parabola through each pair of adjacent strips rather than a straight line. The result converges as O(Δx⁴) — quadrupling the strip count shrinks the error by a factor of 256 — and it integrates any cubic polynomial exactly with no error at all, a striking amount of accuracy for such a cheap formula.

Simpson's rule (n even):
∫ f dx ≈ (Δx/3) · [ f(x0) + 4f(x1) + 2f(x2) + 4f(x3) + ... + 4f(xn-1) + f(xn) ]
                     coefficients alternate 4, 2, 4, 2, ..., 4, with endpoints weight 1

Choosing a rule in practice

For a smooth function, Simpson's rule reaches a given accuracy with dramatically fewer function evaluations than the midpoint or trapezoid rule, which matters when each evaluation is expensive (a physics solver, a Monte Carlo estimate, a real measurement). For a function with a kink or discontinuity inside the interval, the higher-order rules lose their advantage — none of these methods know about the kink, and splitting the interval at the discontinuity before integrating each piece is the standard fix. For genuinely rough or high-dimensional integrands, none of the fixed-grid rules here are competitive with Monte Carlo integration, whose error shrinks as O(1/√N) regardless of dimension — slower per point in 1D, but the only practical option once the number of dimensions climbs into double digits.

Frequently asked questions

Why does the trapezoid rule beat the left and right rules for the same number of strips?

The left rule underestimates and the right rule overestimates an increasing convex function by almost the same amount, because both errors come from the same first-order slope term with opposite sign. Averaging the two sums cancels that first-order error, which is exactly what the trapezoid rule does, so its error shrinks quadratically instead of linearly as you add strips.

Why is Simpson's rule so much more accurate for the same number of points?

Simpson's rule effectively fits a parabola through every pair of adjacent strips instead of a straight line, capturing curvature that a linear approximation misses entirely. That extra order of polynomial fit is why its error shrinks as the fourth power of the strip width instead of the second, and why it integrates any cubic function with zero error.

When should I use Monte Carlo integration instead of Riemann sums?

Once the integral has many dimensions or the integrand is rough or discontinuous, fixed-grid rules like the trapezoid or Simpson's rule lose their accuracy advantage or become impractical to evaluate on a grid. Monte Carlo integration's error shrinks as one over the square root of the sample count regardless of dimension, which makes it the standard choice for high-dimensional integrals even though it converges more slowly than Simpson's rule in one dimension.

Try it live

Everything above runs in your browser — open Riemann Integral and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.

▶ Open Riemann Integral simulation

What did you find?

Add reproduction steps (optional)