Riemann Sums: Area Under a Curve with Rectangles (Interactive Practice)

A Riemann sum estimates the area under a curve by adding up the areas of thin rectangles. Use more rectangles and the sum closes in on the exact area, which is the definite integral.

Start with the explorer: change the function, the rule and the number of pieces, and watch the error. Then practice with problems that change every time.

Riemann sum explorer

Drag the slider to change the number of pieces. Watch the sum close in on the exact area.

Rule
Same function and rule with more pieces
nSumError
Practice

A new problem every time. Work out the Riemann sum, type it in and check. Show steps gives the full calculation.

Find the Riemann sum for f(x) on the interval, using the rule given:

Type a number (two decimals are enough) or a fraction such as 25/4.

Contents

  1. What a Riemann sum is
  2. The four common rules
  3. Worked examples
  4. How accurate is the estimate?
  5. Common mistakes
  6. Frequently asked questions
  7. Related calculators
  8. See also

What a Riemann sum is

Take a function $latex f$ on an interval $latex [a, b]$. Cut the interval into $latex n$ pieces of equal width, draw one rectangle on each piece and add up the areas. Every rectangle is $latex \Delta x$ wide, and its height is the value of $latex f$ at one chosen point of its piece.

$$\Delta x = \frac{b-a}{n}$$

$$S_n = \sum_{i=1}^{n} f(x_i^*)\,\Delta x = f(x_1^*)\,\Delta x + f(x_2^*)\,\Delta x + \cdots + f(x_n^*)\,\Delta x$$

Here $latex x_i^*$ is the sample point you picked in piece $latex i$. When $latex n$ grows without limit, the sum approaches the definite integral:

$$\int_a^b f(x)\,dx = \lim_{n\to\infty} \sum_{i=1}^{n} f(x_i^*)\,\Delta x$$

The four common rules

The only choice is where in each piece you read the height.

RuleSample point in piece iSum
Left$latex x_i^* = a + (i-1)\,\Delta x$$latex L_n$
Right$latex x_i^* = a + i\,\Delta x$$latex R_n$
Midpoint$latex x_i^* = a + \left(i-\tfrac{1}{2}\right)\Delta x$$latex M_n$
Trapezoidaverage of left and right$latex T_n = \frac{L_n + R_n}{2}$

If $latex f$ is increasing, the left sum comes out too small and the right sum too big, because every left rectangle sits under the curve and every right rectangle pokes above it. If $latex f$ is decreasing, it flips. The midpoint rule is usually much closer, since the part of a rectangle that sticks out on one side roughly fills the gap on the other. The trapezoid rule swaps rectangles for strips with a slanted top. It needs $latex n+1$ heights, with half weight at the two ends, while the other rules need only $latex n$ heights:

$$T_n = \Delta x\left(\frac{f(x_0)}{2} + f(x_1) + \cdots + f(x_{n-1}) + \frac{f(x_n)}{2}\right)$$

Worked examples

Example 1: left and right sums

Estimate the area under $latex f(x) = x^2$ on $latex [0, 2]$ with $latex n = 4$. The width is

$$\Delta x = \frac{2-0}{4} = 0.5$$

Left endpoints are 0, 0.5, 1 and 1.5:

$$L_4 = 0.5\,(0 + 0.25 + 1 + 2.25) = 0.5 \cdot 3.5 = 1.75$$

Right endpoints are 0.5, 1, 1.5 and 2:

$$R_4 = 0.5\,(0.25 + 1 + 2.25 + 4) = 0.5 \cdot 7.5 = 3.75$$

The exact area is $latex \int_0^2 x^2\,dx = \frac{8}{3} \approx 2.6667$. The left sum is 0.9167 short and the right sum is 1.0833 over. Because $latex x^2$ is increasing on this interval, the true area is trapped between them.

Example 2: midpoint and trapezoid

Same function, same $latex n = 4$. The midpoints are 0.25, 0.75, 1.25 and 1.75:

$$M_4 = 0.5\,(0.0625 + 0.5625 + 1.5625 + 3.0625) = 0.5 \cdot 5.25 = 2.625$$

$$T_4 = \frac{L_4 + R_4}{2} = \frac{1.75 + 3.75}{2} = 2.75$$

The midpoint sum is off by 0.0417 (under) and the trapezoid sum by 0.0833 (over). For a parabola like this one, the trapezoid error is exactly twice the midpoint error and has the opposite sign.

Example 3: distance from speed

A car moves with speed $latex v(t) = 6t - t^2$ meters per second from $latex t = 0$ to $latex t = 6$ seconds. The distance is the area under the speed curve. Use $latex n = 3$ pieces of 2 seconds each.

$$L_3 = 2\,(0 + 8 + 8) = 32, \qquad R_3 = 2\,(8 + 8 + 0) = 32$$

$$M_3 = 2\,(5 + 9 + 5) = 38$$

The exact distance is $latex \int_0^6 (6t - t^2)\,dt = 108 - 72 = 36$ meters. Both endpoint sums say 32 m, because the speed rises and then falls and the endpoints miss the top of the hill. The midpoint sum lands at 38 m. With only three pieces no rule is safe, and you can see why more pieces help.

Example 4: negative heights

Estimate $latex \int_0^4 (x^2 - 4x + 3)\,dx$ with the midpoint rule and $latex n = 4$. Here $latex \Delta x = 1$ and the midpoints are 0.5, 1.5, 2.5 and 3.5.

$$M_4 = 1\cdot\left(1.25 -0.75 -0.75 +1.25\right) = 1$$

The exact value is $latex \frac{4}{3} \approx 1.3333$. Rectangles below the x-axis count as negative, so a Riemann sum estimates the signed area, which is exactly what the definite integral gives. To get the plain geometric area, split the interval at the zeros of $latex f$, here $latex x = 1$ and $latex x = 3$.

Example 5: watching the error shrink

Take $latex f(x) = x^2$ on $latex [0, 3]$, whose exact area is 9. Sums rounded to four decimals:

nΔxLeftRightMidpointTrapezoid
315148.759.5
60.56.87511.3758.93759.125
120.257.906310.15638.98449.0313
240.1258.44539.57038.99619.0078

Each time $latex n$ doubles, the left error is cut roughly in half (-4, -2.125, -1.0938, -0.5547), while the midpoint error is cut to a quarter (-0.25, -0.0625, -0.0156, -0.0039). That is why the midpoint and trapezoid rules reach a given accuracy with far fewer rectangles.

How accurate is the estimate?

For left and right sums, the error usually shrinks in proportion to $latex \Delta x$: double $latex n$ and the error roughly halves. The exception is a curve with $latex f(a) = f(b)$, like the speed in Example 3: then the left, right and trapezoid sums are all equal and shrink as fast as the trapezoid rule. If $latex f$ only increases or only decreases on $latex [a, b]$, the error is at most $latex |f(b) - f(a)|\,\Delta x$, because the left and right sums sit on opposite sides of the area and differ by exactly that amount. For the midpoint and trapezoid rules the error shrinks with $latex \Delta x^2$ when $latex f$ is smooth: double $latex n$ and the error drops to about a quarter.

When the graph curves like a bowl, the trapezoid sum overshoots and the midpoint sum undershoots. On a hill shape it is the other way around. Use the explorer with the function $latex -x^2 + 4x$ to check it. On the cubic $latex x^3 - 6x^2 + 9x + 1$ the midpoint and trapezoid sums give exactly 12 for every $latex n$: the bowl part and the hill part cancel, and the explorer marks the result as exact.

Common mistakes

  • Forgetting to multiply by $latex \Delta x$. The sum of the heights is not an area.
  • Using $latex b-a$ as the width. The width of one rectangle is $latex (b-a)/n$.
  • Using only $latex n$ heights for the trapezoid rule. It needs $latex n+1$ heights, with half weight at the two ends.
  • Mixing up left and right. The left sum starts at $latex a$ and stops one step before $latex b$. The right sum skips $latex a$ and ends at $latex b$.
  • Reading negative heights as area. Below the axis they subtract.
  • Rounding the f values too early. Keep the digits until the last step.

Frequently asked questions

What is the difference between a Riemann sum and a definite integral?

A Riemann sum is a finite estimate for one chosen $latex n$. The definite integral is the value those sums approach as $latex n$ grows. For a polynomial you find the integral exactly with an antiderivative. The sums show what the integral means, and they are how a computer handles curves that have no neat antiderivative.

Which rule should I use?

The one the problem names. If you can choose, take the midpoint or the trapezoid rule, since they are usually more accurate for the same number of pieces.

How many rectangles do I need?

It depends on the accuracy you need. Doubling $latex n$ roughly halves a left or right error and cuts a midpoint or trapezoid error to about a quarter, so the midpoint and trapezoid rules need far fewer pieces.

Is the trapezoid sum a Riemann sum?

Strictly, it is the average of the left and right sums, and each of those is a Riemann sum. Many textbooks treat it as a separate rule from the same family.

See also