Skip to main content

Riemann Sum Calculator

Approximate the area under any curve using Left, Right, Midpoint, Trapezoid, or Simpson's Rule — with a live graph showing exactly how the rectangles fit under your function, a step-by-step subinterval table, and a full method comparison.

Background

A Riemann sum approximates a definite integral by dividing the interval [a, b] into n equal subintervals and summing the areas of shapes (rectangles or trapezoids) built on each one. How you choose the height of each shape gives you different methods — Left, Right, Midpoint, Trapezoid, and Simpson's Rule — each with different accuracy characteristics. As n increases, all methods converge to the exact integral value.

Set up your Riemann sum

Step 1 — Enter the function f(x)

Use standard notation: x^2 sin(x) sqrt(x) exp(x) ln(x) abs(x) 1/x

Step 2 — Set the interval and subintervals

Step 3 — Choose approximation method

In Compare mode all five methods run automatically.

Step 4 — Exact integral value (optional)

If you know the exact value of ∫f(x)dx from a to b, enter it here to see the approximation error for each method.

Learning options

Result

No result yet. Enter a function and interval, then click Calculate.

How to use this calculator

  • Enter any function using standard notation — x^2, sin(x), sqrt(x), exp(x), ln(x), and arithmetic operators all work.
  • Set the interval [a, b] and the number of subintervals n. More subintervals gives a more accurate approximation.
  • Choose a method: Left, Right, Midpoint, Trapezoid, or Simpson's Rule. Check Compare to see all five at once.
  • Optionally enter the exact integral value to see the approximation error for each method.

How each method works

Left Riemann Sum: Uses the left endpoint of each subinterval as the rectangle height. Overestimates for increasing functions, underestimates for decreasing ones.

Right Riemann Sum: Uses the right endpoint. Opposite behavior to Left — underestimates increasing functions, overestimates decreasing ones.

Midpoint Rule: Uses the function value at the center of each subinterval. Generally more accurate than Left or Right and is exact for linear functions.

Trapezoid Rule: Averages the left and right endpoint heights, forming a trapezoid instead of a rectangle. More accurate than Left/Right individually; equals their average.

Simpson's Rule: Fits a parabola through three points per pair of subintervals. Requires n to be even and is typically the most accurate of all five methods. Exact for polynomials of degree ≤ 3.

Formulas used

Subinterval width: Δx = (b − a) / n

Left sum: Lₙ = Δx · [f(x₀) + f(x₁) + … + f(xₙ₋₁)]

Right sum: Rₙ = Δx · [f(x₁) + f(x₂) + … + f(xₙ)]

Midpoint rule: Mₙ = Δx · [f(x̄₁) + f(x̄₂) + … + f(x̄ₙ)] where x̄ᵢ = (xᵢ₋₁ + xᵢ)/2

Trapezoid rule: Tₙ = (Δx/2) · [f(x₀) + 2f(x₁) + 2f(x₂) + … + 2f(xₙ₋₁) + f(xₙ)]

Simpson's rule (n even): Sₙ = (Δx/3) · [f(x₀) + 4f(x₁) + 2f(x₂) + 4f(x₃) + … + 4f(xₙ₋₁) + f(xₙ)]

Example Problems & Step-by-Step Solutions

Example 1 — Left Riemann Sum: f(x) = x² on [0, 3], n = 4

Step 1: Δx = (3 − 0) / 4 = 0.75

Step 2: Left endpoints: x₀ = 0, x₁ = 0.75, x₂ = 1.5, x₃ = 2.25

Step 3: Evaluate f(x) = x² at each:

f(0) = 0
f(0.75) = 0.5625
f(1.5) = 2.25
f(2.25) = 5.0625

Step 4: L₄ = 0.75 × (0 + 0.5625 + 2.25 + 5.0625) = 0.75 × 7.875 = 5.90625

Exact value = 9. Error = 3.09375 (Left underestimates because x² is increasing).

Example 2 — Midpoint Rule: f(x) = sin(x) on [0, π], n = 4

Step 1: Δx = π / 4 ≈ 0.7854

Step 2: Midpoints: π/8, 3π/8, 5π/8, 7π/8

Step 3: Evaluate sin(x) at each midpoint:

sin(π/8) ≈ 0.3827
sin(3π/8) ≈ 0.9239
sin(5π/8) ≈ 0.9239
sin(7π/8) ≈ 0.3827

Step 4: M₄ = (π/4) × (0.3827 + 0.9239 + 0.9239 + 0.3827) ≈ 0.7854 × 2.6131 ≈ 2.0528

Exact value = 2. Error ≈ 0.0528. Compare: Left sum ≈ 1.896, Right sum ≈ 1.896 — Midpoint is already much closer.

Example 3 — Trapezoid Rule: f(x) = x² on [0, 2], n = 4

Step 1: Δx = (2 − 0) / 4 = 0.5

Step 2: All endpoints: x₀=0, x₁=0.5, x₂=1, x₃=1.5, x₄=2

Step 3: f values: 0, 0.25, 1, 2.25, 4

Step 4: T₄ = (0.5/2) × [f(x₀) + 2f(x₁) + 2f(x₂) + 2f(x₃) + f(x₄)]

= 0.25 × [0 + 0.5 + 2 + 4.5 + 4]
= 0.25 × 11 = 2.75

Exact value = 8/3 ≈ 2.6667. Error = 0.0833. Left gives 2.25, Right gives 3.25 — Trapezoid (their average) beats both.

Example 4 — Simpson's Rule: f(x) = x³ + 1 on [1, 3], n = 4

Step 1: Δx = (3 − 1) / 4 = 0.5

Step 2: Points: x₀=1, x₁=1.5, x₂=2, x₃=2.5, x₄=3

Step 3: f(x) = x³+1 values: 2, 4.375, 9, 16.625, 28

Step 4: S₄ = (0.5/3) × [1·f(x₀) + 4·f(x₁) + 2·f(x₂) + 4·f(x₃) + 1·f(x₄)]

= (1/6) × [2 + 17.5 + 18 + 66.5 + 28]
= (1/6) × 132 = 22

Exact value = [(3⁴/4 + 3) − (1⁴/4 + 1)] = 22. Simpson's Rule is exact — x³+1 is a degree 3 polynomial, confirming the rule is exact for degree ≤ 3.

Frequently Asked Questions

Which method is most accurate?

Generally: Simpson's Rule > Midpoint ≈ Trapezoid > Right ≈ Left. Simpson's Rule is exact for polynomials up to degree 3. For highly oscillatory functions, higher n with any method can be more reliable than a fancier rule with small n.

What is the error bound for each method?

Left and Right errors are O(Δx) — halving n halves the error. Trapezoid and Midpoint are O(Δx²) — halving n quarters the error. Simpson's Rule is O(Δx⁴) — very rapid convergence for smooth functions.

When do Left and Right sums over/underestimate?

For a monotonically increasing function, Left always underestimates and Right always overestimates. For decreasing functions the roles reverse. The true integral always lies between Lₙ and Rₙ for monotone functions.

Is the Trapezoid Rule just the average of Left and Right?

Yes — Tₙ = (Lₙ + Rₙ)/2 exactly. Because Left and Right errors partially cancel for monotone functions, their average is more accurate than either alone, which is why Trapezoid consistently beats both.

Why does Simpson's Rule require even n?

Simpson's Rule groups subintervals in pairs and fits a parabola through three consecutive points. Pairs require even n. The 1–4–2–4–...–4–1 coefficient pattern comes from integrating those parabolas exactly over each pair.

Why does the number of subintervals matter?

With n = 2, a Left sum for x² on [0,3] gives 4.5, far from the exact 9. With n = 100 it gives 8.955 — much closer. Every method converges to the exact value as n → ∞, which is the formal definition of the definite integral.

Can I use Riemann sums for negative-valued functions?

Yes. Areas below the x-axis contribute negative values, exactly matching signed area in definite integration. The calculator handles this correctly for all five methods.

What is the connection to the definite integral?

The definite integral ∫[a,b] f(x)dx is formally defined as the limit of Riemann sums as n → ∞ and Δx → 0. Every method shown here is a Riemann sum approximating this limiting value.

Back to all calculatorsAll calculators