Riemann Sum Calculator
- Subinterval width dx = (b - a) / n = (2.00 - 0.00) / 4 = 0.5000.
- Left endpoints: sample f(x^2) at the left endpoints of each of the 4 subintervals, add the heights and multiply by dx: the Riemann sum is 1.7500.
- The exact integral is 2.6667, so this approximation is off by -0.9167.
- Left and right sums converge like 1/n — doubling the subintervals roughly halves the error — while the midpoint rule converges like 1/n^2, which is why it is usually far more accurate at the same n.
A Riemann sum approximates a definite integral by adding the areas of n rectangles whose heights are sampled from the function. Our Riemann sum calculator lets you choose left, right, or midpoint sampling, then returns the estimated integral along with the exact value and the error. For example, the left Riemann sum of x^2 on [0, 2] with n = 4 is 1.7500, against an exact integral of 2.6667 — an error of -0.9167. The midpoint sum for the same integral is 2.6250 — an error of only -0.0417 at the same n. Similarly, the right sum of e^x on [0, 1] with n = 5 is 1.8958 against an exact 1.7183.
The Riemann sum is the accepted standard for approximating definite integrals because it is simple, reliable, and its convergence behavior is well understood. Left and right sums converge like 1/n, meaning doubling the rectangles roughly halves the error. The midpoint rule converges like 1/n^2, making it far more efficient. For an increasing function the left sum always underestimates and the right sum always overestimates, bracketing the true integral. This page shows the formula, step-by-step workings, worked examples, and sources so you can understand and verify every calculation.
Worked examples
Left sum of x^2 on [0, 2]
Primary result: 1.7500 — four left rectangles under x^2 — an underestimate at 1.7500. (x^2 · Left endpoints · 0 · 2 · 4)
| Riemann sum | 1.7500 |
| Subinterval width dx | 0.5000 |
| Exact integral | 2.6667 |
| Approximation error | -0.9167 |
Midpoint sum of x^2 on [0, 2]
Primary result: 2.6250 — the midpoint rule at the same n is far closer: 2.6250. (x^2 · Midpoints · 0 · 2 · 4)
| Riemann sum | 2.6250 |
| Subinterval width dx | 0.5000 |
| Exact integral | 2.6667 |
| Approximation error | -0.0417 |
Right sum of e^x on [0, 1]
Primary result: 1.8958 — five right rectangles over e^x overshoot to 1.8958. (e^x · Right endpoints · 0 · 1 · 5)
| Riemann sum | 1.8958 |
| Subinterval width dx | 0.2000 |
| Exact integral | 1.7183 |
| Approximation error | 0.1776 |
The Riemann sum formula
A Riemann sum approximates a definite integral by adding the areas of n rectangles whose heights are sampled from the function. The formula starts with the width of each rectangle, dx = (b - a) / n, where [a, b] is the interval and n is the number of rectangles. The area of each rectangle equals its height, given by the function value at a chosen sample point, multiplied by this width dx. The full Riemann sum is the sum of f(x) times dx across all n rectangles.
The sample point you choose determines the method. For the left rule, sample the function at the left edge of each subinterval. For the right rule, sample at the right edge. For the midpoint rule, sample at the center of each subinterval. A Riemann sum calculator applies these rules automatically, but the underlying math is straightforward multiplication and addition repeated for each rectangle.
Consider the left Riemann sum of x^2 on [0, 2] with n = 4. The result is 1.7500, against an exact integral of 2.6667 — an error of -0.9167. The midpoint sum for the same integral is 2.6250 — an error of only -0.0417 at the same n. This dramatic improvement comes from the midpoint rule's faster convergence. Left and right sums converge like 1/n, meaning doubling the rectangles roughly halves the error. The midpoint rule converges like 1/n^2, so the same doubling shrinks the error by roughly a factor of four.
For an increasing function the left sum always underestimates and the right sum always overestimates, bracketing the true integral. This property makes left and right sums useful as a check on each other. A separate example shows the right sum of e^x on [0, 1] with n = 5 is 1.8958 against an exact 1.7183, again an overestimate since e^x is increasing on that interval. The midpoint rule, by contrast, tends to balance over- and underestimation across the subintervals, which is one reason it achieves much smaller errors at the same n.
Worked examples
A Riemann sum approximates a definite integral by adding the areas of n rectangles whose heights are sampled from the function. The three most common sampling choices — left endpoints, midpoints, and right endpoints — can produce noticeably different results from the same setup. Walking through verified cases helps show why a riemann sum calculator may return values above or below the exact integral, and why some methods converge faster than others.
Consider the integral of x^2 on [0, 2] with n = 4. The exact integral is 2.6667. The left Riemann sum for this case is 1.7500, which gives an error of -0.9167. Because x^2 is increasing on this interval, the left sum undersamples the larger function values near the right end, so it underestimates. The midpoint sum for the same integral is 2.6250 — an error of only -0.0417 at the same n. Sampling at the center of each subinterval balances the underestimate on the left with the overestimate on the right within each rectangle, producing a far closer result with no additional rectangles.
For an increasing function the left sum always underestimates and the right sum always overestimates, bracketing the true integral between them. This bracketing property gives users a quick check on accuracy: if the left and right sums are far apart, the approximation is coarse. If they are close, the true integral lies between them and the estimate is already tight. A separate case confirms the overestimate behavior: the right sum of e^x on [0, 1] with n = 5 is 1.8958 against an exact 1.7183. Since e^x is increasing, the right sum samples the largest value in each subinterval, so it overshoots the exact integral by 0.1775.
The convergence rates explain why the midpoint result was so much closer in the x^2 case. Left and right sums converge like 1/n, so doubling the rectangles roughly halves the error. The midpoint rule converges like 1/n^2, so doubling the rectangles cuts the error by about a factor of four. This is why the midpoint sum reached an error of only -0.0417 with just four rectangles while the left sum at the same n still carried an error of -0.9167.
| Function | Interval | n | Method | Riemann sum | Exact integral | Error |
|---|---|---|---|---|---|---|
| x^2 | [0, 2] | 4 | Left | 1.7500 | 2.6667 | -0.9167 |
| x^2 | [0, 2] | 4 | Midpoint | 2.6250 | 2.6667 | -0.0417 |
| e^x | [0, 1] | 5 | Right | 1.8958 | 1.7183 | 0.1775 |
Left vs right vs midpoint sums
A Riemann sum approximates a definite integral by adding the areas of n rectangles whose heights are sampled from the function. Where you sample the height inside each subinterval — at the left edge, the right edge, or the midpoint — determines whether the estimate sits above or below the true value. For an increasing function the left sum always underestimates and the right sum always overestimates, bracketing the true integral. Decreasing functions flip the pattern: the left sum overshoots while the right sum falls short. In both cases the gap between the two estimates shrinks as you add rectangles, but the direction of the error is baked in by the choice of sample point.
The midpoint rule sidesteps this one-sided bias. By sampling at the center of each subinterval, the rectangle tends to cut through the curve in a way that roughly balances the overestimate on one side against the underestimate on the other. The accuracy gain is dramatic. In the worked example for x^2 on [0, 2] with n = 4, the left Riemann sum is 1.7500 against an exact integral of 2.6667, an error of -0.9167. The midpoint sum for the same integral is 2.6250, an error of only -0.0417 at the same n — more than twenty times smaller.
The convergence rates tell the rest of the story. Left and right sums converge like 1/n, meaning doubling the rectangles roughly halves the error. The midpoint rule converges like 1/n^2, so doubling n cuts the error by about a factor of four. This is why a riemann sum calculator that offers the midpoint option can deliver a much tighter answer without requiring you to crank up n to an impractical level.
The same principles hold for exponential and other monotonic functions. The right sum of e^x on [0, 1] with n = 5 is 1.8958 against an exact 1.7183, an overestimate consistent with e^x being increasing on that interval. Switching the same calculation to midpoint sampling would typically bring the estimate much closer to the exact value at the same n.
- Increasing function: left sum underestimates, right sum overestimates — the two estimates bracket the true integral.
- Decreasing function: the pattern reverses — left sum overestimates, right sum underestimates.
- Midpoint sampling balances over- and underestimation within each subinterval, which is why it is usually far more accurate at the same n.
- Left and right sums converge like 1/n; the midpoint rule converges like 1/n^2, so doubling n cuts midpoint error roughly fourfold.
How fast do Riemann sums converge?
The speed at which a Riemann sum approaches the exact integral depends heavily on where you sample the function inside each rectangle. Left and right endpoint sums converge at a rate of 1/n, meaning doubling the number of rectangles roughly halves the error. The midpoint rule converges much faster, at a rate of 1/n^2, so doubling the rectangles cuts the error to about one quarter of its previous size. This difference matters when you are deciding how large n needs to be for a trustworthy result.
The worked examples make the gap concrete. The left Riemann sum of x^2 on the interval [0, 2] with n = 4 is 1.7500, while the exact integral is 2.6667 — an error of -0.9167. The midpoint sum for the same integral at the same n is 2.6250, with an error of only -0.0417. That is a dramatic improvement from simply changing where the height is sampled, without adding any extra rectangles. A riemann sum calculator that lets you switch between methods makes this comparison easy to see.
For an increasing function, the left sum always underestimates and the right sum always overestimates, which means the two results bracket the true integral between them. The right sum of e^x on [0, 1] with n = 5 is 1.8958 against an exact value of 1.7183, so the overshoot is clear. Because endpoint rules only converge like 1/n, shrinking that gap requires a large jump in n. The midpoint rule, converging like 1/n^2, reaches comparable accuracy with far fewer rectangles.
- Left and right sums: error shrinks roughly as 1/n, so doubling n halves the error.
- Midpoint sum: error shrinks roughly as 1/n^2, so doubling n cuts the error to about one quarter.
- For increasing functions, left sums underestimate and right sums overestimate, bracketing the exact integral.
FAQs
How do you calculate a Riemann sum?
Split [a, b] into n subintervals of width dx = (b - a) / n, sample the function at the chosen point of each, and add f(x) times dx. For example, x^2 on [0, 2] with 4 left rectangles gives 1.7500.
What is the difference between left and right Riemann sums?
Left sums sample the left edge of each subinterval and right sums sample the right edge. For an increasing function the left sum underestimates and the right sum overestimates the true value.
Why is the midpoint rule more accurate?
Its error falls like 1/n^2 instead of 1/n. In the worked example it misses the exact integral by 0.0417 where the left sum misses by 0.9167 at the same n, making it far more precise.
How many subintervals should I use?
Use enough that doubling n barely moves the answer. Midpoint sums typically reach 3-4 decimal places at modest n for smooth functions, so a small number of subintervals often gives good accuracy.
Is a Riemann sum the same as the trapezoidal rule?
No. The trapezoidal rule averages the left and right sums, equivalently using trapezoids instead of rectangles, and shares the midpoint rule's 1/n^2 convergence. A Riemann sum uses rectangles alone.
Can a Riemann sum be negative?
Yes. Where the function is below the axis, the rectangles subtract area, which is why the definite integral is signed area. Negative contributions from below the x-axis reduce the total sum.