Riemann Sum Calculator

A Riemann sum approximates the definite integral of a function by dividing the region under the curve into a finite number of rectangles and summing their areas. It is the foundation of integral calculus and gives you a concrete way to see how the exact integral emerges as the number of rectangles grows without limit. The three most common versions differ only in where on each subinterval you sample the function to set the rectangle height. The left Riemann sum samples the left endpoint of each subinterval, the right sum samples the right endpoint, and the midpoint sum samples the centre. For an increasing function the left sum will underestimate and the right sum will overestimate the true area, with the midpoint sum generally splitting the error and converging fastest. This calculator accepts any function of x in standard notation, the lower limit a and upper limit b of integration, and the number of rectangles n. It returns the left sum, the right sum, and the midpoint sum simultaneously so you can see how the three approximations compare. You can use standard operators +, -, *, / and ^ for powers, along with functions such as sin, cos, exp, log, sqrt, and abs. Increase n to watch all three sums converge toward the true integral. The default example uses f(x) = x^2 from 0 to 3 with 6 rectangles, which gives a clear demonstration of the difference between the three methods.

Calculate.co.nz is proud to be partnered with Health Based Building, a leader in sustainable and health-conscious building innovation. With over a century of experience, they develop high-performance systems like Foreverbreathe Specification, Magnum Board, and Foreverbreathe Paints to support energy-efficient, non-toxic living environments. Their commitment to healthier homes aligns with our belief that informed choices lead to better outcomes for Kiwi households.
Calculate.co.nz partner: Health Based Building
8.938
midpoint Riemann sum
Left sum6.875
Right sum11.375
True integral (Simpson's)9.000

Exact integral uses Simpson's rule with 1000 subintervals for reference. Use ^ for powers and * for multiplication.

How it works

The interval [a, b] is divided into n equal subintervals each of width dx = (b - a) / n. For the left sum, the height of each rectangle is f evaluated at the left edge of the subinterval: f(a + i * dx) for i from 0 to n-1. For the right sum, the height is f(a + (i+1) * dx) for i from 0 to n-1. For the midpoint sum, the height is f at the centre: f(a + (i + 0.5) * dx). Each sum multiplies the rectangle height by dx and accumulates the total. The exact reference uses Simpson's rule with 1000 subintervals, which is accurate to many decimal places for smooth functions.

Worked example

For f(x) = x^2 from a = 0 to b = 3 with n = 6 rectangles, each rectangle has width dx = 0.5. The left endpoints are 0, 0.5, 1, 1.5, 2, 2.5 and the left sum is (0 + 0.25 + 1 + 2.25 + 4 + 6.25) * 0.5 = 6.875. The right endpoints are 0.5, 1, 1.5, 2, 2.5, 3 and the right sum is (0.25 + 1 + 2.25 + 4 + 6.25 + 9) * 0.5 = 11.375. The midpoints are 0.25, 0.75, 1.25, 1.75, 2.25, 2.75: f values are 0.0625, 0.5625, 1.5625, 3.0625, 5.0625, 7.5625. Sum * 0.5 = (0.0625 + 0.5625 + 1.5625 + 3.0625 + 5.0625 + 7.5625) * 0.5 = 17.875 * 0.5 = 8.938. The true integral of x^2 from 0 to 3 is exactly 9, shown by Simpson's rule reference.

Related calculators