Skip to content
ScienceQuest

Riemann Sum and Integral Explorer

SimulatorSchool Updated

Support ScienceQuest on Buy Me a Coffee (opens in a new tab)

Watch rectangles converge on an integral, and see why the midpoint and Simpson rules beat endpoint sums at the same strip count.

Simulator

Approximation
Left endpoint rule with 1 strips.
0
Exact value
Hand integrated, so the error beside it is a real error.
2.66667
Error
Signed. Positive means this rule overestimates.
-2.667
Strips
1
Strip width
Called h. Every rule’s error is a power of it.
2
Measured order
Doubling the strips divides the error by 2 to this power. Theory says 1.
0.862
Parameters

The limit as this grows without bound is the integral. Watch the error, not the picture.

Climbs from one strip to the slider’s value, so the convergence is something you watch.

Each rectangle takes its height from its left edge, so it undershoots a rising curve.

Rising throughout, so the left sum is below the answer and the right sum above it.

  • Left endpoint
  • Right endpoint
  • Midpoint
  • Trapezoid
  • Simpson
Absolute error against strip count for every rule, on a linear scale, with the selected rule drawn solid. Every error falls towards zero as the strips increase, and the faster a rule converges, the sooner its line flattens onto the axis.
Cite this tool

Citing this tool

Last updated . Add the date you accessed it as well, which a citation of a page that can change asks for. If a specific result matters, cite the permalink from the tool’s share row instead of this page: it reproduces the exact parameters.

Teaching with this? You can put it on a class page or LMS for free, with no ads inside the frame. Get the embed code.

The equation

∫abf(x) dx=lim⁡n→∞∑i=1nf(xi) Δx\int_a^b f(x)\,dx = \lim_{n \to \infty} \sum_{i=1}^{n} f(x_i)\,\Delta x

Riemann, Habilitationsschrift (1854)

What is a Riemann sum in definite integration?

A Riemann sum approximates the signed area under a curve y = f(x) by partitioning the interval [a, b] into n subintervals of width Δx: Area ≈ ∑ f(xi*) · Δx. As the partition count approaches infinity (Δx → 0), the Riemann sum converges to the exact definite integral: ∫ab f(x) dx.

Watching the sum converge

In most courses the limit definition appears once and then gives way to a table of antiderivatives. Here the sum is the object on screen and the exact value is what it approaches. Turn the strips up and watch the Error readout as well as the picture: the rectangles stop looking different long before the error stops shrinking.

When left and right sums bracket the answer

On a rising curve every left rectangle sits under the graph and every right one pokes above it, so the true value is trapped between the two sums. That guarantee is useful, and easy to over-generalise.

Select sin x on [0, π] and it fails. The two sums come out identical, and both are too small. Bracketing is a property of monotonic functions. Once the curve rises and then falls, the left sum undershoots on the way up and overshoots on the way down, the right sum does the reverse, and the guarantee is gone.

Order of accuracy

The rules also differ in how fast they improve as the strips get narrower:

What halving the strip width does to the error
RuleOrderError becomes
Left or right endpoint1half
Midpoint2a quarter
Trapezoid2a quarter
Simpson4a sixteenth

The Measured order readout computes this live by doubling the strip count and comparing errors, so you can check the table instead of taking it on trust. The error plot is drawn on a linear scale: every line falls towards zero as the strips increase, and the higher a rule’s order, the sooner its line flattens onto the axis.

Midpoint and trapezoid: same order, opposite errors

The midpoint rule takes the height from the centre of each strip, so the slice of curve above the rectangle on one side roughly cancels the slice below it on the other. The trapezoid rule joins the two endpoints with a straight line instead, which works out to exactly the average of the left and right sums, as you can check by switching rules.

Both are second order, and for a curve bending upwards they err in opposite directions: the trapezoid overestimates, and the midpoint underestimates by about half as much. Combining them two to one cancels that leading error, and the result is Simpson’s rule.

Why Simpson’s rule is exact for a cubic

Simpson fits a parabola through each pair of strips. Its error term depends on the fourth derivative of the function, and a cubic’s fourth derivative is zero everywhere, so the error is zero.

Choose x³ - 3x and set the strips to two. Simpson reports -0.75, the exact answer, from a single parabola. At the default 8 strips the midpoint rule is still about 0.05 out, and the other three rules about 0.1.

When Simpson’s rule loses its advantage

Every order in that table comes from a Taylor remainder, which assumes the relevant derivative stays bounded across the interval. Choose √x on [0, 1] and that assumption fails at the origin, where the derivatives are unbounded.

The Measured order readout shows the consequence: Simpson’s order drops from 4 to about 1.5, the same as the trapezoid rule’s. At the default 8 strips it is only about 2.4 times more accurate than the trapezoid rule at the same cost, and the midpoint rule beats it.

Your own integrand

Pick Type your own and you get a box and a pair of limits. The presets have integrals worked out by hand, so the error beside them is a true error. A function you type has no closed form waiting for it, and the readout says so. It is measured against Simpson’s rule at 20,000 strips instead, far finer than any sum on screen, and for a smooth function that reference is usually accurate to rounding. That is close enough to measure against without being the same claim, so the label reads Reference value rather than Exact value.

Before summing, the tool checks the integrand at 201 evenly spaced points, both limits and the midpoint among them, and refuses it if any of those points has no value. Every rule here adds up heights, so a single infinite height makes the whole sum infinite, and 1/x across zero is an improper integral: a different piece of mathematics from the one this page is about. The check catches 1/x on [-1, 1], where zero is the midpoint. A pole that falls between the checked points, as zero does on [-1, 2], gets through, and the sums are then meaningless. Most strip counts give a finite number. Any multiple of three strips puts a strip edge on zero, and every rule except the midpoint then reads the function there and comes out infinite.

Common mistakes

  • Assuming left and right sums always bracket the answer. True for a monotonic function, false in general.
  • Treating area below the axis as positive. A definite integral is signed. Those strips subtract, which is why they are drawn below the axis in a different colour rather than flipped.
  • Judging convergence by the picture. Past about forty strips the rectangles are visually indistinguishable from the curve while the error keeps shrinking: each doubling halves an endpoint sum’s error and quarters the midpoint and trapezoid errors.
  • Believing more strips is always the answer. Changing the rule is often worth far more. For e^x on [0, 1] at the default 8 strips, switching from the left sum to Simpson’s rule cuts the error from about 0.1 to about 2 × 10⁻⁶.
  • Expecting Simpson’s rule to accept an odd number of strips. It pairs them, so an odd count is rounded up to the next even one.

Model and assumptions

The method, what it assumes and how accurate it is
Method
Exact expression, no time stepping
Repeatability
Deterministic. The same link gives the same numbers on any machine.

What it assumes

  • The sums are evaluated directly, and the value they converge on comes from a closed-form integral worked out by hand for each preset.
  • A typed function has no closed form available, so its reference value is Simpson’s rule at 20,000 strips, and the readout says so rather than calling it exact.
  • Convergence order is measured by doubling the strip count, not asserted from theory.

Numerical accuracy

No time stepping, so nothing accumulates. For the preset functions each sum is compared against an integral worked out by hand, so the error shown is a true error, exact to rounding. A typed function has no closed form to compare against, so its reference value is itself a sum, Simpson’s rule at 20,000 strips, and the errors shown for it are measured against that rather than against the integral.

Common questions

Why do left and right sums bracket the answer, and when do they stop?

They bracket it only while the function is going one way. On a rising curve every left rectangle sits under the curve and every right one pokes above, so the true value is caught between them. Choose sin x on 0 to pi and that breaks completely: the two sums come out identical and both are too small, because the function rises and then falls. Bracketing is a property of monotonicity, not of the method.

Why is the midpoint rule so much better than the endpoint rules?

Taking the height from the centre of a strip means the bit of curve above the rectangle on one side roughly cancels the bit below it on the other. That cancellation changes the order: halving the strip width halves an endpoint sum’s error but quarters the midpoint error, so the gap between them widens as you refine rather than staying constant.

What is the trapezoid rule doing differently?

Joining the two endpoints with a straight line instead of a flat one, which works out to be exactly the average of the left and right sums. That is worth checking on screen. It is second order like the midpoint rule, but it errs the other way: for a curve that bends upwards the trapezoid overestimates while the midpoint underestimates, by about half as much.

Why is Simpson’s rule so accurate?

It fits a parabola through each pair of strips rather than a line, which makes it fourth order: halving the strip width divides the error by sixteen. It is also exactly right for any cubic, because its error term depends on the fourth derivative and a cubic’s fourth derivative is zero. Pick the cubic here and Simpson reports the exact answer at two strips.

Is a higher order rule always the better choice?

No, and the square root shows why. Every one of these orders comes from assuming a particular derivative stays bounded on the interval, and the square root’s derivatives blow up at the origin. Simpson’s fourth order collapses to about 1.5 there, so it is barely better than the trapezoid rule. A high order rule is better only where the smoothness it assumes actually holds.

What does the area below the axis do?

It subtracts. A definite integral is a signed area, so a strip whose height is negative reduces the total, which is why the cubic on -1 to 2 comes out at -0.75 despite the curve spending part of its time above the axis. Those strips are drawn in the second colour below the axis rather than being flipped, since flipping them would hide the fact.