Riemann sum calculator

Enter a function, an interval and the number of subintervals to get all the usual Riemann sums side by side: left, right, midpoint, trapezoidal and Simpson's rule. The exact integral and the error of the chosen method show how good the approximation is.

Use x, numbers, + - * / ^, parentheses, pi, e and sin, cos, tan, exp, ln, log, sqrt, abs with brackets, for example sin(x).
The limits may be expressions such as pi/2.
A whole number from 1 to 100,000. Simpson's rule needs an even n.
Sum for the chosen method2.625
Width Δx = (b − a)/n
0.5
Left sum
1.75
Right sum
3.75
Midpoint sum
2.625
Trapezoidal rule
2.75
Simpson's rule
2.666666667
Integral (numerical, high precision)
2.666666667
Error of the chosen method
-0.04166666667
Sample points of the chosen method
x₀ = 0.25 f = 0.0625 x₁ = 0.75 f = 0.5625 x₂ = 1.25 f = 1.5625 x₃ = 1.75 f = 3.0625

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Type f(x), for example x^2.
  2. Enter the interval [a, b] and the number of subintervals n.
  3. Pick the method you need; all the others are listed too, with the exact integral for comparison. For n up to 40 the sample points and values are listed.

How it works

With Δx = (b − a)/n and xᵢ = a + iΔx:

  • Left: Δx · [f(x₀) + f(x₁) + … + f(xₙ₋₁)]
  • Right: Δx · [f(x₁) + … + f(xₙ)]
  • Midpoint: Δx · Σ f((xᵢ + xᵢ₊₁)/2)
  • Trapezoidal: Δx/2 · [f(x₀) + 2f(x₁) + … + 2f(xₙ₋₁) + f(xₙ)]
  • Simpson (n even): Δx/3 · [f(x₀) + 4f(x₁) + 2f(x₂) + … + 4f(xₙ₋₁) + f(xₙ)]

The exact value is computed separately by adaptive Simpson integration to about ten digits.

Worked example

f(x) = x² on [0, 2] with n = 4, so Δx = 0.5 and f at 0, 0.5, 1, 1.5, 2 is 0, 0.25, 1, 2.25, 4.

  • Left: 0.5 · (0 + 0.25 + 1 + 2.25) = 1.75
  • Right: 0.5 · (0.25 + 1 + 2.25 + 4) = 3.75
  • Midpoint: 0.5 · (0.0625 + 0.5625 + 1.5625 + 3.0625) = 2.625
  • Trapezoidal: (1.75 + 3.75)/2 = 2.75
  • Simpson: 0.5/3 · (0 + 1 + 2 + 9 + 4) = 2.666666667

The integral is 8/3 = 2.666666667, so the midpoint error is −0.04166666667 and Simpson’s rule is exact, as expected for a quadratic.

Tips and common mistakes

  • n is the number of rectangles, not the number of points: n subintervals use n + 1 endpoints.
  • Doubling n should cut the midpoint and trapezoid errors by about 4 and Simpson’s error by about 16 for smooth functions.
  • If f is not finite somewhere in [a, b], for example 1/x across 0, the sums are meaningless and the calculator reports the point.

Frequently asked questions

What is a Riemann sum?

An approximation of the area under a curve by rectangles. Split [a, b] into n parts of width Δx, take a height f(xᵢ) in each part and add the areas f(xᵢ)·Δx. As n grows, the sum approaches the definite integral.

Which method is the most accurate?

For smooth functions the midpoint and trapezoidal rules have errors that shrink like 1/n², with the midpoint error about half the trapezoid error and of opposite sign. Simpson's rule shrinks like 1/n⁴ and is exact for polynomials up to degree 3.

When are left sums an overestimate?

For a decreasing function the left endpoint is the highest point of each part, so the left sum is too big and the right sum too small. For an increasing function it is the other way round.

Is the trapezoidal rule the average of the left and right sums?

Yes. With equal subintervals, T = (L + R)/2, which you can check in the results.

More in Math

All tools in this category: Math ·Updated November 4, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.