About the Riemann Sum Calculator
This Riemann sum calculator approximates the area under a curve f(x) between x = a and x = b by splitting the interval into n equal sub-intervals and adding up rectangles. It computes all four common versions at once — left endpoint, right endpoint, midpoint and trapezoidal — so you can see how much each one over- or under-estimates.
It is built for calculus students learning how the definite integral is defined, and for checking textbook and AP Calculus exercises that ask for L₄, R₆ or M₈. The chart shows the height of each rectangle next to the curve, and the table lists every sub-interval with its sample point, height and area.
For comparison the tool also estimates the exact integral with high-precision adaptive Simpson integration and reports the error of your chosen method. Rectangles below the x-axis count as negative area, exactly as in the definition of the integral.
With the default inputs, the selected sum is 2.625. Change any value above to recalculate instantly.
How to use the riemann sum calculator
- 1Type the function f(x), e.g. x^2 or sin(x).
- 2Enter the lower and upper limits a and b.
- 3Choose the number of sub-intervals n (e.g. 4 for L₄, R₄, M₄).
- 4Pick the method to highlight in the chart and table.
- 5Compare the four sums with the high-precision integral to see each method’s error.
Formula and method
The interval [a, b] is cut into n equal pieces of width Δx, with endpoints xᵢ = a + iΔx. Each method picks a different height for the rectangle on [xᵢ₋₁, xᵢ]: the left endpoint, the right endpoint or the midpoint. The trapezoidal rule joins the two endpoint heights with a straight line, which is the same as averaging the left and right sums.
As n grows every Riemann sum approaches the definite integral ∫ₐᵇ f(x) dx. For an increasing function the left sum underestimates and the right sum overestimates; for a concave-up function the midpoint sum underestimates and the trapezoid overestimates. The "integral" output uses adaptive Simpson’s rule to near machine precision so you can measure each method’s error.
- n
- Number of equal sub-intervals
- Δx
- Width of each sub-interval
- xᵢ
- Grid points a + iΔx, i = 0 … n
- Lₙ, Rₙ, Mₙ, Tₙ
- Left, right, midpoint and trapezoidal sums
Worked examples
f(x) = x² on [0, 2] with n = 4
Δx = 0.5. Left heights 0, 0.25, 1, 2.25 sum to 3.5, × 0.5 = 1.75; right heights 0.25, 1, 2.25, 4 give 3.75. Midpoints 0.25, 0.75, 1.25, 1.75 square to 0.0625 + 0.5625 + 1.5625 + 3.0625 = 5.25, × 0.5 = 2.625. The exact area is 8/3 ≈ 2.6667.
sin(x) on [0, π] with n = 6, right endpoints
With Δx = π/6 the right-endpoint heights are sin(π/6) … sin(π), which add to 2 + √3 ≈ 3.7321; times π/6 gives ≈ 1.9541. The midpoint sum is ≈ 2.0230, and the true area under one arch of sine is exactly 2.
1/x on [1, 2] with n = 10, trapezoid
The trapezoidal rule with ten strips gives ≈ 0.693771, just above ln 2 ≈ 0.693147 because 1/x is concave up. The error is only about 0.0006.
Frequently asked questions
What is a Riemann sum?+
A Riemann sum approximates the area under a curve by adding the areas of rectangles. Each rectangle has width Δx and a height equal to the function value at a chosen point in its sub-interval. Taking the limit as the number of rectangles goes to infinity defines the definite integral.
Which Riemann sum is most accurate?+
For smooth functions the midpoint and trapezoidal rules are far more accurate than left or right sums: their error shrinks with 1/n² instead of 1/n. The midpoint rule’s error is typically about half the trapezoid’s and of opposite sign, which is why Simpson’s rule combines them.
How do I know if a Riemann sum is an overestimate?+
If f is increasing on the interval, left sums underestimate and right sums overestimate (and vice versa for decreasing f). If f is concave up, the trapezoidal rule overestimates and the midpoint rule underestimates; concave down reverses this.
Is the trapezoidal rule a Riemann sum?+
Strictly it is not, because it uses trapezoids rather than rectangles, but it equals the average of the left and right Riemann sums. Textbooks usually teach it alongside Riemann sums as a better approximation.
What happens when the function is negative?+
Rectangles below the x-axis have negative height, so they subtract from the sum. The Riemann sum therefore approximates the signed (net) area, just like the definite integral. To get total area, integrate |f(x)| instead.