Riemann Sum Calculator
Enter a function, an interval and the number of subintervals, and get the left, right, midpoint, trapezoid or Simpson's rule approximation of the integral, with the full table of sample points, the error against an accurate reference value, a comparison of all five rules, and a graph with the rectangles, trapezoids or parabolas drawn in. Free, no sign-up.
Use + − * / ^ and brackets. Functions: sin, cos, tan, sec, csc, cot, asin, acos, atan, sinh, cosh, tanh, exp, ln, log (base 10), sqrt, abs. Constants: pi and e.
A number or constant such as 0, −2 or pi/2.
A whole number from 1 to 1000.
Results
1.75
Approximation
2.666666667
Exact value (adaptive quadrature)
-0.9167
Error (approximation − exact)
0.5
Subinterval width h
The formula
L = h·[f(x₀) + f(x₁) + … + f(xₙ₋₁)], with h = 0.5 and xᵢ = a + i·h
0.5 × 3.5 = 1.75
Sample points
| i | xᵢ | f(xᵢ) |
|---|---|---|
| 0 | 0 | 0 |
| 1 | 0.5 | 0.25 |
| 2 | 1 | 1 |
| 3 | 1.5 | 2.25 |
All five rules at n = 4
| Rule | n | Value | Error |
|---|---|---|---|
| Left endpoints | 4 | 1.75 | -0.9167 |
| Right endpoints | 4 | 3.75 | +1.083 |
| Midpoint | 4 | 2.625 | -0.04167 |
| Trapezoid rule | 4 | 2.75 | +0.08333 |
| Simpson's rule | 4 | 2.666666667 | 0 |
How the error shrinks as n grows (Left endpoints)
| n | Value | Error |
|---|---|---|
| 4 | 1.75 | -0.9167 |
| 8 | 2.1875 | -0.4792 |
| 16 | 2.421875 | -0.2448 |
| 32 | 2.54296875 | -0.1237 |
| 64 | 2.604492188 | -0.06217 |
| 128 | 2.635498047 | -0.03117 |
Doubling n cuts the error of the left and right sums about 2×, of the midpoint and trapezoid rules about 4×, and of Simpson's rule about 16×.
Graph
- y = f(x)
- Left endpoints, n = 4
How to Use the Riemann Sum Calculator
- 1. Type the function and the interval. For example
x^2from 0 to 2, orsin(x)from 0 topi. Limits can be numbers or constants such aspi/2. - 2. Choose the number of subintervals n. More subintervals give a better approximation. The tool accepts n from 1 to 1,000.
- 3. Pick the rule. Left or right endpoints, midpoint, trapezoid, or Simpson's rule. Simpson's rule needs an even n and raises an odd one by 1, telling you so.
- 4. Read the table, the error and the graph. Every sample point and its weight is listed, the sum is assembled in front of you, and the shapes are drawn under the curve.
The Five Rules
Split [a, b] into n equal pieces of width h = (b − a)/n, with points xᵢ = a + i·h. Each rule adds up weighted values of f at sample points and multiplies by a common factor:
| Rule | Formula | Error shrinks like |
|---|---|---|
| Left | h·[f(x₀) + … + f(xₙ₋₁)] | h |
| Right | h·[f(x₁) + … + f(xₙ)] | h |
| Midpoint | h·[f(m₁) + … + f(mₙ)], mᵢ = midpoint | h² |
| Trapezoid | (h/2)·[f(x₀) + 2f(x₁) + … + 2f(xₙ₋₁) + f(xₙ)] | h² |
| Simpson | (h/3)·[f(x₀) + 4f(x₁) + 2f(x₂) + … + 4f(xₙ₋₁) + f(xₙ)] | h⁴ |
The error orders are for smooth functions; they describe how fast each rule improves as n grows.
Worked Example: x² on [0, 2] with n = 4
Here h = 0.5 and the exact integral is 8/3 ≈ 2.6667. The points are 0, 0.5, 1, 1.5, 2 with f = 0, 0.25, 1, 2.25, 4.
| Rule | Working | Value | Error |
|---|---|---|---|
| Left | 0.5 × (0 + 0.25 + 1 + 2.25) | 1.75 | −0.9167 |
| Right | 0.5 × (0.25 + 1 + 2.25 + 4) | 3.75 | +1.0833 |
| Midpoint | 0.5 × (0.0625 + 0.5625 + 1.5625 + 3.0625) | 2.625 | −0.0417 |
| Trapezoid | 0.25 × (0 + 2×0.25 + 2×1 + 2×2.25 + 4) | 2.75 | +0.0833 |
| Simpson | (0.5/3) × (0 + 4×0.25 + 2×1 + 4×2.25 + 4) | 2.6667 | 0 (exact for cubics) |
x² is increasing on [0, 2], so the left sum underestimates and the right sum overestimates, and the trapezoid value is their average. The midpoint rule is about twice as accurate as the trapezoid and off in the opposite direction, which is why Simpson's rule — in effect (2M + T)/3 computed on pairs of subintervals — does so well. For sin x on [0, π] with n = 4 the rules give 1.8961 (left, right and trapezoid), 2.0523 (midpoint) and 2.0046 (Simpson) against an exact 2.
Reading the Error
The exact value comes from the same adaptive quadrature as the Definite Integral Calculator, accurate to about twelve digits, so the error column is trustworthy for any rule you try. The convergence table shows the error at n = 4, 8, 16, … : double n and the left-sum error halves, the midpoint and trapezoid errors drop to a quarter, and Simpson's drops to a sixteenth. If your integrand has a singularity or diverges, there is no reference value and the error is left out.
Frequently Asked Questions
- What is a Riemann sum?
- A Riemann sum approximates the area under a curve by adding the areas of rectangles of width h = (b − a)/n whose heights are values of f at one sample point per subinterval. As n grows and h shrinks, the sums approach the definite integral.
- How do I know if a left or right sum is an overestimate?
- On an increasing function the left sum underestimates and the right sum overestimates; on a decreasing function it is the other way round. For a function that rises and falls, the errors partly cancel and no general rule applies.
- What is the difference between the midpoint and trapezoid rules?
- The midpoint rule uses rectangles whose height is f at the middle of each piece; the trapezoid rule joins the endpoint values with a straight line. Both are second-order accurate, with opposite-signed errors of roughly 1 : 2, so the midpoint rule is normally the more accurate of the two.
- Why must n be even for Simpson's rule?
- Simpson's rule fits a parabola through three points, covering two subintervals at a time, so the subintervals have to pair up. If you enter an odd n the calculator raises it by 1 and says so.
- How many subintervals do I need?
- Enough that the error is below what your problem needs, which the convergence table shows directly. Smooth functions with Simpson's rule need few: 16 subintervals often give four to six digits. Left and right sums can need thousands for the same accuracy.
- Does it do upper and lower sums?
- Not as separate options. For a monotonic function the upper and lower sums are the left and right sums in some order. For other functions the upper sum takes the maximum of f on each piece, which this tool does not compute.