Understanding science, for all. Home About
Novadette › ∑ Mathematics › Calculus › Integral Calculator › Approximations
∑ Calculus

Approximating Integrals: Riemann Sums

Cut the area under a curve into n thin strips and add them up: that is a Riemann sum, and as n grows it approaches the integral. Compare left, right and midpoint rectangles with the trapezoidal rule and Simpson’s rule, see every term of the sum, and watch the error shrink as you make n bigger.

Calculus Riemann sum Numerical Methods
Inputs
Input examples
Method
Type pi for π and e for Euler’s number. Simpson’s rule needs an even n. The rectangles are drawn for n up to 400; the sum works for n up to 100 000.

What Is a Riemann Sum?

Split [a, b] into n strips of width Δx = (b − a)/n. In each strip, pick a point xi* and draw a rectangle of height f(xi*). The total area of the rectangles is a Riemann sum. Taking the left end, the right end or the middle of each strip gives the left, right and midpoint sums.

The definite integral is defined as the limit of these sums as n → ∞. Rectangles below the x-axis count as negative, just like in the integral. The trapezoidal rule joins the points with straight lines, and Simpson’s rule with parabolas, which is far more accurate for smooth functions.

Left, righterror × ½ when n doubles
Midpoint, trap.error × ¼
Simpsonerror × 1⁄16
Increasing fleft too low, right too high

The Strips Under the Curve

f(x)
Function graph
Enter a function, the bounds and n, then press Calculate.
f(x)
counts as positive
counts as negative
Result
Enter a function and bounds above

All Methods Side by Side

MethodApproximationErrorError %

Make n Bigger: the Error

nLeftRightMidpointTrapezoidSimpson

The Terms of the Sum

ixf(x)WeightTerm

The Five Methods

Left and Right Riemann Sums

The height of each rectangle is taken at its left or right edge. For an increasing function the left sum is too low and the right sum too high.

Example: x² on [0, 2], n = 4:
Midpoint Rule

The height is taken in the middle of each strip. The bits that are too high and too low partly cancel, so it is much more accurate than the left or right sum.

Example: 
Trapezoidal Rule

Straight lines between the points: the average of the left and right sums.

Example: 
Simpson’s Rule

A parabola through every three points; n must be even. It equals (2Mn/2 + Tn/2)/3 and is exact for polynomials up to degree 3.

Example: , exact.
Error Bounds

K1, K2 and K4 are the largest values of |f′|, |f″| and |f(4)| on [a, b]. The calculator finds them by sampling the exact derivatives.

Sources & Verification

References
  1. J. Stewart, Calculus: Early Transcendentals, 8th ed., Cengage, 2016 — Sections 5.1–5.2 (Areas and distances; the definite integral as a limit of Riemann sums) and 7.7 (Approximate integration, with the error bounds).
  2. R. L. Burden & J. D. Faires, Numerical Analysis, 9th ed., Brooks/Cole, 2011 — Section 4.4 (Composite numerical integration).
More in Calculus
Single integral (exact, with steps) → Double Integral → Derivative Calculator → ← All Mathematics tools

Frequently Asked Questions

What is a Riemann sum?

An approximation of the area under a curve by rectangles. Split [a, b] into n strips of width Δx = (b − a)/n, take the height f(x) at one point in each strip, and add up the areas f(x)·Δx. As n grows, the sum gets closer to the integral; the definite integral is defined as the limit of these sums. Rectangles below the x-axis count as negative.

How do I calculate a left Riemann sum?

Example: f(x) = x² on [0, 2] with n = 4 rectangles.

1. Δx = (2 − 0)/4 = 0.5, so the strips start at x = 0, 0.5, 1 and 1.5 (the left ends).

2. The heights are f(0) = 0, f(0.5) = 0.25, f(1) = 1 and f(1.5) = 2.25.

3. L₄ = 0.5 × (0 + 0.25 + 1 + 2.25) = 1.75. The exact integral is 8/3 ≈ 2.667, so the left sum is too low here, because x² is increasing. The calculator shows every term in the table The Terms of the Sum.

What is the difference between left, right and midpoint sums?

Only where the height of each rectangle is taken: at the left end, the right end or the middle of the strip. For an increasing function the left sum is too low and the right sum too high; for a decreasing function it is the other way round. The midpoint sum is usually much closer: for x² on [0, 2] with n = 4 the sums are 1.75 (left), 3.75 (right) and 2.625 (midpoint), against the exact 2.667.

How does the trapezoidal rule work?

It joins the points on the curve with straight lines, so every strip becomes a trapezoid: T = (Δx/2)·[f(x₀) + 2f(x₁) + … + 2f(xₙ₋₁) + f(xₙ)]. That is exactly the average of the left and right sums: for x² on [0, 2] with n = 4, (1.75 + 3.75)/2 = 2.75.

How does Simpson’s rule work?

It fits a parabola through every three neighbouring points, which needs an even n: S = (Δx/3)·[f(x₀) + 4f(x₁) + 2f(x₂) + 4f(x₃) + … + 4f(xₙ₋₁) + f(xₙ)]. It is exact for polynomials up to degree 3 (x³ − x on [−1, 2] gives exactly 2.25 with n = 6) and very accurate for smooth functions: 1/x on [1, 2] with n = 8 gives 0.6931545, only 0.0000074 away from ln 2.

Which method is the most accurate?

For smooth functions, Simpson’s rule by far. When you double n, the error of the left and right sums roughly halves, that of the midpoint and trapezoidal rules becomes four times smaller, and that of Simpson’s rule sixteen times smaller. The table Make n Bigger shows this for your function. But it depends on the function: for √x on [0, 4], which is infinitely steep at 0, the midpoint rule with n = 50 (error 0.0013) beats Simpson’s rule (error 0.0018).

What is the error bound of the midpoint, trapezoidal and Simpson’s rule?

|E_M| ≤ K(b − a)³/(24n²) and |E_T| ≤ K(b − a)³/(12n²), with K the largest value of |f″| on [a, b]; for Simpson’s rule |E_S| ≤ K(b − a)⁵/(180n⁴) with K the largest |f⁽⁴⁾|. The bound is a guaranteed maximum, not the actual error: for sin x on [0, π] with the midpoint rule and n = 6 the bound is 0.0359, while the real error is 0.0230. The calculator gives both.

What is the difference with the integral calculator?

The Single integral tab gives the exact value of the integral, with the antiderivative and a step-by-step solution. This tab shows how the integral is built up from strips, and how good each approximation is for a given n. Approximations are also what you use when a function has no antiderivative that can be written down, such as e^(−x²).