Skip to content
K Knidox Search…
Math · Calculus

Riemann Sum

Left, right, midpoint and trapezoid sums for any function, with the convergence as n grows.

Use x as the variable. Write 2*x rather than 2x. sin, cos, tan, sqrt, ln, log, exp and abs are available.
Method
Left sum with 10 rectangles
0.285

Strip width 0.1 · Rectangle height from the left edge of each strip

High-resolution reference
0.33333333
Simpson’s rule at 20,000 intervals — a very accurate numerical value, not a symbolic one
Difference from it
4.833e-2
This sum underestimates
The same method as n grows
nSumError
40.218751.15e-1
100.2854.83e-2
500.32349.93e-3
2000.33083752.50e-3
10000.33283355.00e-4

A Riemann sum approximates the area under a curve with rectangles. Split [a, b] into n strips of width (b − a)/n, take a height from each, and add up the areas. As n grows the sum converges on the definite integral — that limit is what the integral is defined to be.

The definition, not just an approximation

It is easy to treat Riemann sums as a rough method you use before learning proper integration. They are the other way round: the definite integral is defined as the limit of these sums as the strips become infinitely thin. Antiderivatives are a way of evaluating that limit quickly, which the Fundamental Theorem of Calculus licenses — but the sum is the thing being evaluated.

That is why the sums still matter after you can integrate. Plenty of functions have no elementary antiderivative, and for those the only route to a number is to sum something. It is also why the method generalises so readily to data: if you have measurements rather than a formula, a trapezoid sum over the samples is still meaningful.

Where the height comes from

The four choices differ only in where each rectangle's height is read. The left rule uses the left edge of each strip, the right rule the right edge, the midpoint rule the centre, and the trapezoid rule averages the two edges — drawing a straight line across the top instead of a flat one. On a function that is increasing throughout, left always underestimates and right always overestimates, which brackets the true value between them.

∫a^b f(x)dx = lim(n→∞) Σ f(xᵢ*)·Δx, Δx = (b − a) ÷ n

xᵢ* is the sample point in each strip — its left edge, right edge or midpoint

  1. 1
    Find the strip width. For f(x) = x² on [0, 1] with n = 4, Δx = (1 − 0) ÷ 4 = 0.25.
  2. 2
    List the sample points. The left rule uses x = 0, 0.25, 0.5, 0.75 — the left edge of each strip.
  3. 3
    Evaluate the function at each. f gives 0, 0.0625, 0.25 and 0.5625.
  4. 4
    Add them and multiply by the width. (0 + 0.0625 + 0.25 + 0.5625) × 0.25 = 0.21875.
  5. 5
    Compare against the true value. The integral is exactly 1/3 ≈ 0.3333, so four left rectangles underestimate substantially — increasing n closes the gap.

The four rules on f(x) = x² over [0, 1]

The true value is 1/3 ≈ 0.333333. Notice how much better the midpoint and trapezoid rules do at the same n.

nLeftRightMidpointTrapezoid
40.218750.468750.3281250.34375
100.2850.3850.33250.335
500.32340.34340.33330.3334
2000.3308380.3358380.3333310.333338

How fast each rule converges

Left and right sums halve their error when n doubles — first order, and the reason they need so many strips to be useful. The midpoint and trapezoid rules are second order, so doubling n cuts their error by a factor of four, which is why they are ahead by two decimal places at the same n in the table above.

The midpoint rule usually beats the trapezoid rule despite both being second order, because its errors on a convex function point the opposite way and are about half the size. A useful consequence: on a function that curves consistently, the true value lies between the midpoint and trapezoid estimates, so the two together bracket the answer.

Two cautions on what this tool reports. The value it compares against is Simpson’s rule at 20,000 intervals — a very accurate numerical result, not a symbolic one, so for an integrand with a vertical tangent at an endpoint such as √x even the reference carries error. And a function undefined anywhere in the interval stops the calculation rather than being silently skipped.

What is a Riemann sum?
An approximation of the area under a curve made by splitting the interval into strips, taking a rectangle height from each, and adding the areas. The definite integral is the limit of these sums as the strips become infinitely thin.
What is the difference between left, right and midpoint?
Only where each rectangle takes its height: the left edge of the strip, the right edge, or the centre. On an increasing function left underestimates and right overestimates, while the midpoint is usually far closer than either.
Which rule is most accurate?
Of these four, the midpoint rule usually wins. It and the trapezoid rule are both second order, but the midpoint error is about half the size and points the other way, so the two together bracket the true value.
Why does left underestimate on an increasing function?
Because the left edge is the lowest point of each strip, so every rectangle sits below the curve. On a decreasing function the roles swap and the left rule overestimates instead.
How many rectangles do I need?
It depends on the rule and the function. Left and right sums halve their error each time n doubles; midpoint and trapezoid quarter it. For a smooth function the midpoint rule is usually within a few decimal places by n = 100.
Is a Riemann sum the same as a definite integral?
The integral is the limit of the sums, so they agree only as n tends to infinity. Any finite n gives an approximation, though for a smooth function it can be extremely close.
Why use Riemann sums when I can integrate?
Because many functions have no elementary antiderivative, and because data often comes as measurements rather than a formula. In both cases summing is the only route to a number.