Chapter 4 Area from rectangles

Riemann sums and the integral

The area under a curve is the limit of sums of thin rectangles. Change the number of rectangles and the rule for their heights, and watch every rule converge on the same number.

10 min read · 6 interactive figures

Raise n, or drag a and b. The rectangles' total area closes in on the area under the curve.

A Riemann sum approximates the area under a curve by a row of thin rectangles: chop the interval from a to b into n equal pieces, give each piece a rectangle whose height is the function’s value at some point of the piece, and add up the rectangles’ areas. As n grows, every reasonable choice of heights gives sums that close in on one number. That number is the definite integral, ∫ab f(x) dx, the exact area.

The derivative chapters asked how fast something changes. This chapter asks the opposite kind of question: if you know how fast something changes at every moment, how much does it change in total? A car’s speedometer reading, added up over a trip, gives the distance travelled. Water flowing into a tank at a known rate, added up over an hour, gives the volume. Both are areas under curves, and both are found with the same rectangles.

Area from rectangles

Rectangles are the one shape whose area everyone knows. To use them under a curve y = f(x) between x = a and x = b, split [a, b] into n pieces of width Δx = (b − a)/n, with endpoints x0 = a, x1, …, xn = b. On each piece, choose a height. Taking the height at each piece’s left end gives the left sum; the right end, the right sum[1]:

Ln = n∑i=1 f(xi−1) Δx,Rn = n∑i=1 f(xi) Δx(4.1)
Question 1 Predict before you use the figure.#
Figure 1 Change the number of pieces n and the rule for the heights. Drag a and b along the axis. Magenta dots mark where each height is taken. Notice that left and right sums bracket the true area on a rising curve, that the midpoint and trapezoid rules are far closer for the same n, and that all four agree as n grows.#

With six left rectangles under ex/2 from −2 to 2.6, the sum is about 5.42, while the true area is about 6.60: an error of more than a whole unit, all from the triangular slivers between the rectangle tops and the curve. Push n to 60 and the error falls to about 0.13; to 200, about 0.04. The slivers get thinner and there are more of them, but their total shrinks in proportion to 1/n.

For a few functions the limit can be found exactly, by algebra. For f(x) = x² on [0, 1], the right sum is

Rn = ∑i=1n i²n² · 1n = n(n + 1)(2n + 1)6n³ → 13(4.2)

using the classical formula for the sum of the first n squares[1]. At n = 10 it is 0.385; at n = 1000, 0.3338; and in the limit, exactly ⅓. The area under a parabola from 0 to 1 is one third of the unit square. Archimedes knew this, in a different form, more than two thousand years ago; the last section of this chapter shows how.

The definite integral

Nothing forces the heights to come from the ends of the pieces. Any point xi* in the i-th piece will do, and the result, ∑ f(xi*) Δx, is called a Riemann sum. The remarkable fact is that for a continuous function the choice does not matter in the limit: every Riemann sum converges to the same number as n → ∞[1]. That number is the definite integral:

∫ab f(x) dx = limn → ∞ ∑i=1n f(xi*) Δx(4.3)
established

Leibniz’s notation carries the construction inside it. The ∫ is an elongated S, for summa: a sum. f(x) is the height of a rectangle, and dx its width, shrunk to the limit. The whole expression reads “the sum of height times width,” with the limit understood.

Students are often more comfortable computing Riemann sums than believing equation (4.3). In a classic set of interviews with 110 students aged 16 to 22, Orton found that they could evaluate a given Riemann sum with little difficulty, but most did not see the integral as the limit of those sums, and described the limit as one more approximation rather than the exact answer[2][3]. The limit is exact. Each finite sum is an approximation; the integral is not, any more than the limit of 1.9, 1.99, 1.999, … is “approximately 2.”

documented

Area below the axis counts negative

Equation (4.3) never mentions area. It multiplies heights by widths, and when f is negative the products are negative. So the integral measures signed area: area above the axis minus area below it[1].

Figure 2 The parabola y = x² − 2 dips below the axis between −√2 and √2. Rectangles below the axis are hatched: they subtract. Drag a and b to include more or less of the dip and watch the total change sign.#

Signed area is not a nuisance; it is usually what you want. If f is a car’s velocity, the integral is its displacement, and driving backwards should reduce it. The integral of sin x over a whole period is exactly 0: the hump above cancels the trough below. If you need the total area regardless of sign, integrate |f| instead, or split the interval where f crosses zero.

Reversing the limits flips the sign too: ∫ba = −∫ab, because the width Δx = (a − b)/n is now negative. Drag b to the left of a in the figure to see it.

Better rules: midpoint, trapezoid and Simpson

The left and right sums converge, but slowly: doubling n only halves the error. Two small changes do much better. The midpoint rule takes each height at the centre of its piece, where it is a fair average of the piece. The trapezoid rule replaces each rectangle with a trapezoid joining the curve’s values at the two ends, which is the same as averaging the left and right sums. For both, the error falls like 1/n²: doubling n cuts it by four. There are guaranteed bounds[5]:

|error of Mn| ≤ K(b − a)³24n² |error of Tn| ≤ K(b − a)³12n²(4.4)

where K is the largest value of |f″| on the interval. Curvature is the enemy: on a straight line both rules are exact. The bounds also hint at something sharper. On a curve that bends one way, the midpoint rule errs in one direction and the trapezoid rule in the other, and for smooth functions the midpoint error is very nearly half the trapezoid error, with opposite sign. Combine them as (2Mn + Tn)/3 and the errors cancel to leading order. The result is Simpson’s rule, which fits a parabola through each triple of points and whose error falls like 1/n⁴[5].

Figure 3 The error of each rule against the number of pieces n, on logarithmic scales, for the same integral. Each rule is a straight line: left and right fall with slope −1, midpoint and trapezoid with slope −2, Simpson with slope −4. Move n and read off the errors. Simpson reaches the limits of 16-digit arithmetic at about a thousand pieces.#

The slopes on that plot are the practical lesson. To gain six more correct digits, a left sum needs a million times as many pieces, the midpoint rule a thousand times, and Simpson’s rule about thirty times. Choosing a good rule beats brute force by a wide margin.

Archimedes and the parabola

The idea of trapping an area between ever-finer approximations is far older than calculus. In the third century BC, Archimedes of Syracuse found the area of a parabolic segment, the region between a parabola and a chord across it, without any algebra at all[6].

His method inscribes the largest possible triangle in the segment, with its apex where the parabola’s tangent is parallel to the chord. That leaves two smaller segments, and he inscribes a triangle in each. Then four, then eight. Archimedes proved that each new stage of triangles has exactly one quarter of the area of the stage before. So if the first triangle has area T, the triangles fill

T (1 + ¼ + ¼² + ¼³ + …) = 43 T(4.5)
Figure 4 The segment of y = x² cut off by the chord from x = −1 to x = 2. Add stages of triangles; each stage is a paler shade. Notice that each stage adds a quarter of the previous one, and that the uncovered area shrinks by a factor of four each time.#

Every segment of a parabola is four-thirds of the triangle with the same base and the same height: that is Proposition 24 of his Quadrature of the Parabola, which he proved by the method of exhaustion, showing that the area could be neither more nor less than 4T/3[7]. Earlier in the same work, Proposition 17 reaches the same result by imagining the segment balanced on a lever. In the figure, the chord from −1 to 2 gives a first triangle of area 27/8 and a segment of area 27/6 = 4.5, exactly four-thirds as much. Archimedes did not have limits, but the method of exhaustion does the same logical work: it pins the answer between bounds that can be made as tight as you like.

An integrator that explains itself

A Riemann sum with equally spaced pieces wastes effort where the curve is nearly straight and skimps where it bends sharply. Practical integrators adapt. The calculator below uses adaptive Simpson quadrature: it applies Simpson’s rule to a panel, then to its two halves, and compares. If the two answers agree to within the tolerance, the panel is done; if not, each half is split again[8]. The tick marks along the bottom of the plot are the panel edges it chose, crowded where the function bends.

Figure 5 Type a function and the limits a and b. The calculator shades the signed area, marks its adaptive panels along the axis, and reports the integral with an error estimate and the number of function evaluations it needed. Try sqrt(x) from 0 to 1, whose steep start draws a crowd of panels near 0.#

The function e−x² is the shape of the bell curve of statistics. Its integral from −2 to 2 is about 1.7642, which is 99.5 percent of √π ≈ 1.7725, the area under the whole curve. Because e−x² has no antiderivative in elementary functions (a theorem of Liouville[9]), no antiderivative formula gives the first number; rectangles, refined adaptively, do.

Computing integrals as limits of sums works, but it is laborious. The next chapter shows the shortcut that made calculus a practical tool: the area under f can be read off from any function whose derivative is f.