Riemann Sum
calculator.
Add up rectangles under a curve, and see how close they get to the true area.
- Strip width Δx
- 0.25
- Error
- −0.479167−0.4792
- Relative error
- 17.97%
The left sum is 0.479167 below the integral. f only rises here, so each rectangle takes the lowest height on its strip.
Left rectangles on the curve
The curve runs from x = 0 to x = 2. 8 rectangles of width 0.25 sit on it, and their signed areas add up to 2.1875. The integral is 2.666667.
All four sums
| Sum | Value | Error | Relative |
|---|---|---|---|
| Left | 2.1875 | −0.47916717.97% | 17.97% |
| Right | 3.1875 | 0.52083319.53% | 19.53% |
| Midpoint | 2.65625 | −0.0104170.39% | 0.39% |
| Trapezoid | 2.6875 | 0.0208330.78% | 0.78% |
Errors are the sum minus the integral. A positive error means the sum is too large.
Working
- 1Width of each strip: the interval split into n equal partsΔx =b − an=2 − 08= 0.25
- 2Height of each strip: f at the left end of each stripf(0) = 0, f(0.25) = 0.0625, f(0.5) = 0.25, f(0.75) = 0.5625, …
- 3Add width times height over every stripLeft sum = Δx × (sum of 8 heights) = 2.1875
- 4Check: the integral by adaptive quadrature, which uses no rectangles∫ = 2.666667, so the error is −0.479167
- 5Check: the trapezoid sum is the average of the left and right sums2.1875 + 3.18752= 2.6875
Strip by strip
| Strip | Interval | Height | Area |
|---|---|---|---|
| 1 | 0 to 0.25 | 0 | 0 |
| 2 | 0.25 to 0.5 | 0.0625 | 0.015625 |
| 3 | 0.5 to 0.75 | 0.25 | 0.0625 |
| 4 | 0.75 to 1 | 0.5625 | 0.140625 |
| 5 | 1 to 1.25 | 1 | 0.25 |
| 6 | 1.25 to 1.5 | 1.5625 | 0.390625 |
| 7 | 1.5 to 1.75 | 2.25 | 0.5625 |
| 8 | 1.75 to 2 | 3.0625 | 0.765625 |
Error as n doubles
| n | Left | Midpoint | Trapezoid |
|---|---|---|---|
| 8 | −0.479167 | −0.010417 | 0.020833 |
| 16 | −0.244792 | −0.002604 | 0.005208 |
| 32 | −0.123698 | −0.000651 | 0.001302 |
| 64 | −0.062174 | −0.000163 | 0.000326 |
| 128 | −0.031169 | −0.000041 | 0.000081 |
On a smooth curve, doubling n about halves the left error and cuts the midpoint and trapezoid errors about 4 times.
How many strips do you need?
The left sum needs 400 strips to come within 0.01 of the integral. Its error there is 0.009992.
How it's worked out
You split the interval from a to b into n strips of equal width, build a rectangle on each strip, and add the areas. OpenStax defines these sums with a strip width and a sample point in each strip. The only choice left is where you measure each height.
The left sum takes each height at the start of a strip, and the right sum takes it at the end. The midpoint sum takes it halfway across. The trapezoid sum joins the two ends of a strip with a straight line, and that works out to the average of the left and right sums.
Where f is below the x-axis, a height is negative, so that strip subtracts from the total. A Riemann sum therefore estimates signed area, as the definite integral does. As n grows, the sums close in on the integral, which is how the integral is defined in the first place.
One more figure is worth having. Two thirds of the midpoint sum plus one third of the trapezoid sum is Simpson's rule with twice as many strips. For from 1 to 2 with n = 5, this mix gives 0.69315, while the integral is 0.693147.
Worked examples
Nadia checks her homework with four rectangles
Nadia has to estimate the area under from 0 to 1 with n = 4, so each strip is 0.25 wide. Her left sum uses the heights at 0, 0.25, 0.5, 0.75, and it comes to 0.21875. Her right sum uses the heights at 0.25, 0.5, 0.75, 1, and it comes to 0.46875.
| Sum | Value | Size of error |
|---|---|---|
| Left | 0.21875 | 0.114583 |
| Right | 0.46875 | 0.135417 |
| Midpoint | 0.328125 | 0.005208 |
| Trapezoid | 0.34375 | 0.010417 |
The true area is 0.333333. It sits between her left and right sums, as it must, because only rises here. The midpoint sum misses by only 0.005208, even though it uses the same number of rectangles.
Omar turns speed readings into a distance
Omar logs a test car every 5 seconds for 40 seconds. Its speed in meters per second follows , so type x in place of t. Speed times time is distance, so the area under this curve is the distance covered.
The speed only rises, so the left sum of 825.8 m is too low and the right sum of 973 m is too high. The curve bends downward, so each straight trapezoid top sits under it, and the trapezoid sum of 899.4 m is a little low. The integral is 905.5 m. Omar can report the trapezoid figure and know which way it errs.
Rosa sees positive and negative strips cancel
Rosa tries from −2 to 2 with n = 8. This curve has an odd shape: its value at −x is minus its value at x. The midpoint sum is 0 and the integral is 0, because each strip on one side cancels its partner on the other.
The left sum is −1 and the right sum is 1. Neither one measures the region's size. For the total area, integrate the absolute value of f, or use the area between curves calculator with 0 as the second curve.
Reading your result
Which side of the integral. You can often predict it. A left sum on a rising curve takes the lowest height on each strip, so it runs low, and a right sum runs high. On a falling curve those swap. Bend matters for the other two: on a curve that bends upward, the trapezoid sum runs high and the midpoint sum runs low. These rules need the shape to hold across the whole interval.
| f(x), range | Shape | Left, right | Midpoint, trapezoid |
|---|---|---|---|
| , 0 to 2 | Rises, bends up | Under, Over | Under, Over |
| , 1 to 4 | Rises, bends down | Under, Over | Over, Under |
| , 0 to 2 | Falls, bends up | Over, Under | Under, Over |
| , 0 to 1.5 | Falls, bends down | Over, Under | Over, Under |
How fast the error falls. For from 0 to 1, going from 32 strips to 64 cuts the left error 1.99 times, and it cuts the midpoint and trapezoid errors 4 and 4 times. So the left and right errors shrink in step with n, while the other two shrink with n squared. OpenStax gives the bounds for the second pair, with M the largest size of on the interval.
How many strips you need. For from 0 to 2, staying within 0.01 of the integral takes 400 strips with the left sum and 9 with the midpoint sum. The search assumes the error keeps falling as n grows, which is true of smooth curves once n is not tiny.
What the error means. The default case, from 0 to 2 with n = 8, has a left sum of 2.1875 against an integral of 2.666667, a relative error of 17.97%. The integral here comes from adaptive quadrature, not from your rectangles, so it is a fair yardstick.
Common mistakes
- Counting one height too many. With n strips you have n + 1 dividing points. The left sum drops the last point and the right sum drops the first, so each adds exactly n heights.
- Forgetting to multiply by the width. Adding the heights alone gives a number with the wrong size. Every height needs the factor , which you can take outside the sum.
- Calling a signed sum the area. Strips below the axis subtract. A sum of 0 can sit on a large region, as with from −2 to 2.
- Applying the over and under rules to a mixed curve. On from 0 to , the curve rises and then falls, so the left and right sums come out equal. Split the interval where the shape changes.
- Sampling at a point where f has no value. from −1 to 1 has no value at 0, and every n puts a strip edge or a midpoint there. The tool names the point and gives no sum, and the integral across 0 does not exist in any case.