Riemann Sum Calculator: Left, Right, Midpoint, Trapezoidal & Simpson

This Riemann sum calculator approximates the area under a curve with left, right, midpoint or trapezoidal rectangles. Enter f(x), the limits a and b, and the number of sub-intervals, and it returns the sum, compares all the methods side by side and shows how far each is from a reference value.

Math — Calculus, Algebra & Linear Algebra Calculators

Riemann Sum Calculator

Left, right, midpoint and trapezoidal Riemann sums for any f(x), with Simpson’s rule, upper and lower sums, error versus a reference value and a sub-interval table.

Use x as the variable, e.g. x^2, sin(x), exp(-x^2), sqrt(1+x^2).
Whole number from 1 to 200,000.
Upper and lower sums are estimated by sampling inside each sub-interval, so they are close to (not exactly) the true supremum and infimum sums for functions that rise and fall inside a sub-interval.

Starting values: f(x) = x^2 on [0, 2] with 4 sub-intervals and the left-endpoint method. The width of each strip is 0.5, and the left sum is 1.75. The exact area is 8/3 = 2.6667, so the left sum underestimates it.

What a Riemann sum is

A Riemann sum cuts the interval [a, b] into n strips of equal width, picks one point in each strip, and adds up the areas of the rectangles of height f at that point. As n grows, the sum approaches the definite integral.

Sum = f(x1*) × Δx + f(x2*) × Δx + … + f(xn*) × Δx

Where:

  • Δx = (b − a) ÷ n, the width of each strip
  • xi* = the sample point in strip i, which depends on the method
  • n = the number of sub-intervals

The four methods

  • Left endpoints: sample at the left edge of each strip.
  • Right endpoints: sample at the right edge.
  • Midpoints: sample at the centre of each strip.
  • Trapezoidal rule: average the left and right sums, which is the same as joining the edge heights with straight lines.

The calculator also reports Simpson’s rule and the upper and lower sums. It uses Simpson’s rule with 2,000 sub-intervals as the reference integral, so the error column compares each method against a very accurate answer rather than the true value.

Worked examples

Example 1: x squared on [0, 2], n = 4

Δx = 0.5 and the edges are 0, 0.5, 1, 1.5 and 2. Left sum: 0.5 × (0 + 0.25 + 1 + 2.25) = 1.75. Right sum: 0.5 × (0.25 + 1 + 2.25 + 4) = 3.75. Midpoint sum: the midpoints are 0.25, 0.75, 1.25 and 1.75, so 0.5 × (0.0625 + 0.5625 + 1.5625 + 3.0625) = 2.625. Trapezoidal: (1.75 + 3.75) ÷ 2 = 2.75. Simpson’s rule gives 2.6667, which equals the exact value 8/3, because Simpson’s rule is exact for quadratics.

Example 2: 1/x on [1, 2], n = 4

Left 0.7595, right 0.6345, midpoint 0.6912, trapezoidal 0.6970, Simpson 0.6933. The exact integral is ln 2 = 0.6931. Here f is decreasing, so the left sum overestimates and the right sum underestimates, the reverse of Example 1.

Example 3: more strips

For x squared on [0, 2] with n = 10: left 2.28, right 3.08, midpoint 2.66, trapezoidal 2.68. Compare these with n = 4. The left and right sums moved from 1.75 and 3.75 to 2.28 and 3.08, a change of about 0.5 and 0.7 toward the exact 2.6667.

Example 4: sine over half a period

f(x) = sin(x) from 0 to 3.14159265 with n = 6. The left and right sums are both 1.9541, the midpoint sum is 2.0230 and Simpson’s rule gives 2.0009. The exact integral is 2.

Over- or under-estimate?

The calculator’s trend line tells you which side the answer errs on. For a function that only increases on [a, b], the left sum is too small and the right sum too big. For a function that only decreases, it is the other way round. For a curve bending upward, such as x squared, the trapezoidal sum is too big and the midpoint sum too small.

The two kinds of sums converge at different speeds. Left and right sums improve roughly in proportion to 1/n, so doubling n roughly halves the error. Midpoint and trapezoidal sums improve roughly with 1/n², and Simpson’s rule with 1/n4. That is why Simpson’s rule was already exact in Example 1 while the left sum was still off by more than 0.9.

Entering your function

  • Use x as the variable, with ^ for powers: x^2, sqrt(1+x^2), exp(-x^2), sin(x).
  • Angles in trig functions are in radians.
  • n must be a whole number from 1 to 200,000.
  • The upper and lower sums are estimated by sampling inside each strip, so they are close to, not exactly equal to, the true supremum and infimum sums for curves that rise and fall within a strip.

For a one-method answer with an exact-rule check, the Simpson’s rule calculator gives the same reference integral.

Common mistakes

  • Entering n as the width of a strip instead of the number of strips. n is a count, and the width is worked out for you.
  • Forgetting that sin and cos expect radians.
  • Comparing a left sum with the exact value and concluding the method is wrong. A left sum with few strips can be far from the integral, and the trend line tells you which direction it errs.
  • Using a function that is undefined inside [a, b], such as 1/x on an interval that crosses 0.

Frequently asked questions

What is the difference between left, right and midpoint Riemann sums?

They differ in where each strip is sampled. Left uses the left edge, right uses the right edge and midpoint uses the centre. Midpoint is usually the most accurate of the three.

How many sub-intervals should I use?

Use as many as you need for the accuracy you want. The error shrinks as n grows, and the calculator accepts up to 200,000.

Why is the trapezoidal sum the average of left and right?

Each trapezoid has parallel sides equal to the left and right heights, so its area is their average times the width.

What does the reference integral mean?

It is Simpson’s rule with 2,000 sub-intervals, a very accurate estimate that the calculator uses to measure the error of the other methods.

Does the calculator use radians or degrees?

Radians, for sin, cos and the other trigonometric functions.

Mark Danny

Mark Danny

Mark Danny builds and maintains the free calculators and guides on Area of Irregular Shapes Calculator. Every calculator page explains its formula and shows a worked example, so you can check the working yourself. Spotted a mistake or have a suggestion? Email gulsher.hingoro101@gmail.com.

Articles: 752