math.wiki
Calculus › Integrals › The trapezoidal rule and Simpson's rule
Open on the map
Calculus 1

The trapezoidal rule and Simpson's rule

The width of a field, or the depth of a river, is known only at evenly spaced marks. Joining the readings with straight lines, or with parabolas, estimates the area far better than rectangles do. How much better, and in which direction is the estimate wrong?

Where you are 16 in Integrals

Why this exists

Curdin wants the area of a field whose far edge wanders; every 10 meters along a straight fence he measures the width across. Ladina and Gian want the area of a river’s cross-section; they wade across reading the depth with a pole. Either way the data is a table of heights at known positions, and the area wanted lies under the graph through them.

Left, right and midpoint sums give each piece a rectangle with one height, yet each piece of a table has a measured height at both ends. Joining them with a straight segment makes a trapezoid, which follows a slanting edge exactly; joining three neighboring points with a parabola follows a bending edge too. These are the trapezoidal rule and Simpson’s rule, and concavity tells which way the trapezoids err.

Definition

Let f be continuous on [a, b], cut into n pieces of width \displaystyle \Delta x = \frac{b-a}{n}, with cut points x_k = a + k\,\Delta x and heights y_k = f(x_k). For f \ge 0 write A for the area under the graph; its exact value is the integral \int_a^b f(x)\,dx of The definite integral as a limit of Riemann sums.

The trapezoid on piece k has parallel sides y_{k-1} and y_k and width \Delta x, so its area is \displaystyle \Delta x \cdot \frac{y_{k-1} + y_k}{2} (Area of parallelograms and trapezoids). The trapezoidal sum adds them:

T_n = \frac{\Delta x}{2}\big(y_0 + 2y_1 + 2y_2 + \dots + 2y_{n-1} + y_n\big).

Each inside height is a side of two trapezoids, so it counts twice. With pieces of different widths \Delta x_k = x_k - x_{k-1}, each trapezoid takes its own width: the estimate is \displaystyle \sum_{k=1}^{n} \frac{y_{k-1} + y_k}{2}\,\Delta x_k.

Simpson’s sum needs n even. It takes the pieces in pairs, replaces the graph over each pair by the parabola through its three points, and adds the areas under the parabolas. Why it is true shows that this gives

\begin{aligned} S_n = \frac{\Delta x}{3}\big(&y_0 + 4y_1 + 2y_2 + 4y_3 + \cdots \\ &+ 2y_{n-2} + 4y_{n-1} + y_n\big). \end{aligned}

The middle point of a pair has weight 4, a point shared by two pairs gets 1 + 1 = 2, and the ends get 1. The rule is named for Thomas Simpson, an eighteenth-century mathematician.

The error of an estimate is the estimate minus the exact value: E_T = T_n - A, and likewise E_M and E_S. A positive error is an overestimate.

Intuition

x w 0 10 20 30 40 50 60 10 20 30 40
Figure 1Curdin’s field as six trapezoids. Each top joins two measured widths with a straight segment.

Where the true edge between two marks bends, a trapezoid’s straight top misses a sliver, and the bend decides on which side.

x_{k-1}
m_k
x_k
chord tangent
y = f(x)
Figure 2On a concave up curve the chord lies above the graph and the midpoint tangent lies below it, so the trapezoid overestimates the strip and the midpoint rectangle underestimates it.

A concave up graph sags below the chord joining two of its points, so the trapezoid holds the strip and a little more. The midpoint rectangle has the same area as the trapezoid under the tangent at the midpoint (Approximating area with Riemann sums), and a concave up graph lies above that tangent. So the exact area is caught between the two sums. The gap above the curve is the wider one, for narrow pieces about twice as wide. A parabola, unlike a straight top, can bend with the curve.

x_0
x_1
x_2
Figure 3Simpson’s rule replaces the curve over a pair of pieces by the parabola (dashed) through three of its points.

Results

Trapezoids average the end sums. With equal pieces, \displaystyle T_n = \frac{1}{2}(L_n + R_n) for every f.

Concavity decides the direction. If f is concave up on (a, b), for instance with f''(x) > 0 there, then M_n \le A \le T_n for every n. If f is concave down, T_n \le A \le M_n. If f is linear, all three are equal.

Midpoint against trapezoid (stated without proof). If f'' is continuous on [a, b], then for large n, \displaystyle E_M \approx -\frac{1}{2}E_T: opposite sign, half the size. Doubling n divides each error by about 4.

Simpson’s rule. \displaystyle S_{2n} = \frac{2M_n + T_n}{3}, and S_n is exact for every polynomial of degree at most 3. If f^{(4)} is continuous, doubling n divides E_S by about 16 for large n (stated without proof).

Error bounds (stated without proof, optional). If |f''(x)| \le K on [a, b], then \displaystyle |E_T| \le \frac{K(b-a)^3}{12n^2} and \displaystyle |E_M| \le \frac{K(b-a)^3}{24n^2}. If |f^{(4)}(x)| \le K_4, then \displaystyle |E_S| \le \frac{K_4(b-a)^5}{180n^4}.

Why it is true

The average. Split each trapezoid’s \displaystyle \frac{\Delta x}{2}(y_{k-1} + y_k) into its two halves. The left halves add to \displaystyle \frac{1}{2}L_n and the right halves to \displaystyle \frac{1}{2}R_n.

The chord lies above a concave up graph. Take a piece [p, q] and p < x < q. The chord’s height at x is the weighted average

\ell(x) = \frac{q - x}{q - p}\,f(p) + \frac{x - p}{q - p}\,f(q).

A concave up graph lies above its tangent lines; Concavity and inflection points proves this, and it is used here as given. The tangent at x, read at p and at q, gives

\begin{aligned} f(p) &\ge f(x) + f'(x)(p - x), \\ f(q) &\ge f(x) + f'(x)(q - x). \end{aligned}

Multiply the first by \displaystyle \frac{q-x}{q-p} and the second by \displaystyle \frac{x-p}{q-p}, both positive, and add. The weights add to 1, and the f'(x) terms cancel since (q - x)(p - x) + (x - p)(q - x) = 0. What is left is \ell(x) \ge f(x). So each strip lies inside its trapezoid, and adding gives A \le T_n. The other half, M_n \le A, is the midpoint result of Approximating area with Riemann sums. For concave down every inequality reverses.

The area under a parabola. Slide the pair sideways, which changes no area, so its points sit at -h, 0, h with heights y_0, y_1, y_2. The parabola p(x) = Ax^2 + Bx + C through them (The shape of a parabola) has C = y_1, y_0 = Ah^2 - Bh + C and y_2 = Ah^2 + Bh + C, so y_0 + y_2 = 2Ah^2 + 2C.

Heights that add give areas that add, a property of the integral used here as given; Properties of definite integrals proves it. The line Bx + C over [-h, h] is a trapezoid of area 2h \cdot C. For x^2, the right sums over [0, h] are

\frac{h}{n}\sum_{k=1}^{n}\left(\frac{kh}{n}\right)^2 = h^3\,\frac{n(n+1)(2n+1)}{6n^3}

(Sigma notation), which approach \displaystyle \frac{h^3}{3}, so by symmetry the area under x^2 over [-h, h] is \displaystyle \frac{2h^3}{3}. The area under p is

\frac{2Ah^3}{3} + 2Ch = \frac{h}{3}\big(2Ah^2 + 6C\big) = \frac{h}{3}\big(y_0 + 4y_1 + y_2\big).

With h = \Delta x, adding over the pairs gives the weights of S_n.

Exact for cubics. A quadratic is its own parabola, so the rule is exact for it. A cubic, written around the middle point m of a pair, is c(x - m)^3 plus a quadratic. For (x - m)^3 the rule gives \displaystyle \frac{h}{3}\big((-h)^3 + 0 + h^3\big) = 0, and the signed area is 0 too: the part below the axis left of m mirrors the part above it on the right (Signed area and integrals from geometry).

Simpson from T and M. With 2n pieces of width \displaystyle \frac{\Delta x}{2}, the cut points of T_n get weights \displaystyle \frac{\Delta x}{6}(1, 2, \dots, 2, 1), which make \displaystyle \frac{1}{3}T_n, and the n midpoints get \displaystyle \frac{4\Delta x}{6} each, which make \displaystyle \frac{2}{3}M_n.

Worked examples

Example 1

Curdin’s field from equal steps

Curdin’s widths w at marks x along the fence, both in meters:

xw
032
1038
2041
3040
4036
5030
6022

Find L_6, R_6 and T_6, and check that T_6 is the average of the other two.

Solution

Here \Delta x = 10. The left sum uses the first six widths and the right sum the last six:

\begin{aligned} L_6 &= 10(32 + 38 + 41 + 40 + 36 + 30) = 2170, \\ R_6 &= 10(38 + 41 + 40 + 36 + 30 + 22) = 2070. \end{aligned}

The trapezoidal sum counts the five inside widths twice:

\begin{aligned} T_6 &= \tfrac{10}{2}\big(32 + 2(38 + 41 + 40 + 36 + 30) + 22\big) \\ &= 5(32 + 370 + 22) = 5(424) = 2120. \end{aligned}

Indeed \displaystyle \frac{2170 + 2070}{2} = 2120: about 2120 square meters. The table says nothing about how the edge bends between marks, so the direction of T_6’s error is unknown.

Example 2

Ladina’s soundings across the river

Ladina reads the depth d at distances x from the left bank, both in meters:

xd
00
10.8
31.6
42.1
71.5
100

Estimate the area of the cross-section. If the water passes through it at an average 0.4 meters per second, about how much flows by each second?

Solution

The widths are 1, 2, 1, 3, 3, so each trapezoid takes its own. Depth is drawn as a positive height; turning the picture over changes no area.

\begin{aligned} &1 \cdot \tfrac{0 + 0.8}{2} + 2 \cdot \tfrac{0.8 + 1.6}{2} + 1 \cdot \tfrac{1.6 + 2.1}{2} \\ &\quad + 3 \cdot \tfrac{2.1 + 1.5}{2} + 3 \cdot \tfrac{1.5 + 0}{2} \\ &= 0.4 + 2.4 + 1.85 + 5.4 + 2.25 = 12.3. \end{aligned}

The cross-section is about 12.3 square meters; the end pieces are triangles. Each second a slab of water 0.4 meters thick passes, about 12.3 \times 0.4 = 4.92 cubic meters. Simpson’s weights need equal spacing, so they do not apply here.

Example 3

Over and under for one concavity

For \displaystyle f(x) = \frac{1}{x} on [1, 2], find T_n and M_n for n = 2, 4, 8 and compare them with the exact area, \displaystyle \int_1^2 \frac{1}{x}\,dx = \ln 2 \approx 0.693147. Take that value on trust; The fundamental theorem of calculus will produce it.

Solution

Since \displaystyle f''(x) = \frac{2}{x^3} > 0 on [1, 2], f is concave up, so M_n \le \ln 2 \le T_n for every n.

For n = 2, \displaystyle \Delta x = \frac{1}{2} and the heights at \displaystyle 1, \frac{3}{2}, 2 are \displaystyle 1, \frac{2}{3}, \frac{1}{2}:

T_2 = \tfrac{1}{4}\left(1 + \tfrac{4}{3} + \tfrac{1}{2}\right) = \tfrac{17}{24} \approx 0.708333.

The midpoints are \displaystyle \frac{5}{4} and \displaystyle \frac{7}{4}, so \displaystyle M_2 = \frac{1}{2}\left(\frac{4}{5} + \frac{4}{7}\right) \displaystyle = \frac{24}{35} \approx 0.685714. By computer:

nT_nM_n
20.7083330.685714
40.6970240.691220
80.6941220.692661
nE_TE_M
20.015186-0.007433
40.003877-0.001927
80.000975-0.000487

Trapezoid errors are positive and midpoint errors negative, as concavity requires. Each E_M is about \displaystyle -\frac{1}{2} of the E_T beside it, and doubling n divides both by about 4. At n = 8 the bracket 0.692661 \le \ln 2 \le 0.694122 holds without knowing \ln 2 at all.

Example 4

Simpson’s rule on Curdin’s field

Estimate the area of Curdin’s field from Example 1 with S_6.

Solution

Six pieces make three pairs. Each parabola has area \displaystyle \frac{10}{3}(\text{left} + 4 \cdot \text{middle} + \text{right}):

\begin{aligned} \tfrac{10}{3}(32 + 152 + 41) &= 750, \\ \tfrac{10}{3}(41 + 160 + 36) &= 790, \\ \tfrac{10}{3}(36 + 120 + 22) &\approx 593.33. \end{aligned}

The widths 41 and 36 end one pair and start the next, which is where the weight 2 comes from:

\begin{aligned} S_6 &= \tfrac{10}{3}(32 + 4 \cdot 38 + 2 \cdot 41 + 4 \cdot 40 \\ &\qquad + 2 \cdot 36 + 4 \cdot 30 + 22) \\ &= \tfrac{10}{3}(640) = \tfrac{6400}{3} \approx 2133.33. \end{aligned}

That is about 13 square meters more than T_6 = 2120; the table alone cannot say which is closer.

Example 5

Simpson’s errors for one concavity

Find S_2, S_4 and S_8 for \displaystyle f(x) = \frac{1}{x} on [1, 2] and compare them with \ln 2.

Solution

S_2 uses the heights \displaystyle 1, \frac{2}{3}, \frac{1}{2} with \displaystyle \Delta x = \frac{1}{2}:

S_2 = \tfrac{1}{6}\left(1 + \tfrac{8}{3} + \tfrac{1}{2}\right) = \tfrac{25}{36} \approx 0.694444.

S_4 needs no new heights: \displaystyle S_4 = \frac{2M_2 + T_2}{3} \displaystyle = \frac{1}{3}\left(\frac{48}{35} + \frac{17}{24}\right) \displaystyle = \frac{1747}{2520} \approx 0.693254. By computer for n = 8:

nS_nE_S
20.6944440.001297
40.6932540.000107
80.6931550.0000074

S_4 uses the same five heights as T_4, yet its error is about 36 times smaller. Doubling n divides the error by about 12, then 15, on the way to 16.

Example 6

A cubic and one parabola

Let f(x) = x^3 - 3x^2 + 4 = (x + 1)(x - 2)^2, which is at least 0 on [0, 3]. Find S_2 and T_2 and compare them with the exact area \displaystyle \frac{21}{4}, taken on trust.

Solution

With \displaystyle \Delta x = \frac{3}{2}, the heights at \displaystyle 0, \frac{3}{2}, 3 are \displaystyle 4, \frac{5}{8}, 4:

\begin{aligned} S_2 &= \tfrac{1}{2}\left(4 + \tfrac{5}{2} + 4\right) = \tfrac{21}{4}, \\ T_2 &= \tfrac{3}{4}\left(4 + \tfrac{5}{4} + 4\right) = \tfrac{111}{16} = 6.9375. \end{aligned}

One parabola gives the exact area; the trapezoids overshoot by \displaystyle \frac{27}{16}. The parabola through the three points is \displaystyle p(x) = \frac{5}{8} + \frac{3}{2}\left(x - \frac{3}{2}\right)^2, and \displaystyle f(x) - p(x) = x\left(x - \frac{3}{2}\right)(x - 3), which is odd about \displaystyle x = \frac{3}{2}: f rises above p on one side by what it falls below on the other. Since f''(x) = 6x - 6 changes sign at x = 1, the concavity result says nothing about T_2 here.

Boundaries

  • The over and under results need one concavity on each piece. Across an inflection point there is no guarantee (Example 6).
  • A table records heights only at its marks. Calling an estimate high or low needs knowledge between them, such as the sign of f''.
  • Simpson’s rule needs equal spacing and an even number of pieces.
  • The factors \displaystyle \frac{1}{2}, 4 and 16 need continuous f'' (for Simpson, f^{(4)}) and large n; the bounds need a number K. For \displaystyle \sqrt{x} on [0, 1], f'' is unbounded and the trapezoid bound says nothing.
  • For a function that dips below the axis, the sums estimate signed area (Signed area and integrals from geometry).

Where this goes next

The fundamental theorem of calculus gives exact values such as \ln 2 without pieces. For e^{-x^2}, which has no antiderivative in the usual functions, or for a table of measurements, these rules are how the number is found. Totals from tables of rates return in The net change theorem in context.

Exercises

Trapezoids

  1. Find T_4 for f(x) = x^2 on [1, 3], and say whether it is over or under the area, with the reason.
  2. Gian reads the depth of a narrower river every 1.5 meters across its 9-meter width: 0, 0.6, 1.3, 1.7, 1.5, 0.9, 0 meters. Find T_6, and explain why L_6, R_6 and T_6 agree here.
  3. Curdin’s second field has widths 18, 24, 27, 21, 12 meters at the marks x = 0, 15, 25, 40, 50 meters. Estimate its area with trapezoids.
  4. For some f on [0, 3], L_6 = 5.2 and R_6 = 4.6. Find T_6 and f(3) - f(0).
  5. Find T_4 for f(x) = \cos x on \displaystyle \left[0, \frac{\pi}{2}\right] to four decimal places. The exact area is 1; explain why T_4 falls on the side it does.

Over, under and the midpoint

  1. For f(x) = e^x on [0, 2], find T_2 and M_2 to four decimal places and state the bracket they give for the area.
  2. For f(x) = \ln x on [1, 4], find T_3 and M_3. Which is over the area, and why?
  3. The far edge of a field bows outward, so its width w(x) is concave down. The widths at x = 0, 20, 40 meters are 50, 58, 54 meters. Find T_2 and say whether it is over or under.
  4. A function of one concavity on [a, b] has T_4 = 3.52 and M_4 = 3.40. Is it concave up or down? Give the best estimate of the area these numbers allow.

Simpson’s rule

  1. Find S_6 for Gian’s depths in Exercise 2.
  2. For f(x) = x^4 on [0, 2], find S_2 and S_4. The exact area is \displaystyle \frac{32}{5}; find both errors and their ratio.
  3. For \displaystyle f(x) = \frac{4}{1+x^2} on [0, 1], the exact area is \pi. Find T_4 and S_4 and compare.
  4. For f(x) = 2x^3 + x on [0, 2], find S_2 and T_2; the exact area is 10. Why is one of them exact?
  5. Use T_3 and M_3 from Exercise 7 to find S_6, and compare it with the exact area 4\ln 4 - 3.

Error bounds

  1. For f(x) = \sin x on [0, \pi], find the smallest n for which the bounds guarantee an error under 10^{-4}, for T_n and for S_n.

Reasoning

  1. Prove that T_n = A for every n when f \ge 0 is linear on [a, b].
  2. For f(x) = x^2, show that the chord over [p, q] minus the graph equals (x - p)(q - x), and conclude that T_n overestimates for every n.
  3. Explain why Simpson’s rule needs an even number of pieces. Gian has 8 depth readings at equal steps; what can he do?
  4. Show that \displaystyle S_{2n} - A = \frac{2E_M + E_T}{3}, where E_M and E_T are the errors of M_n and T_n. Explain why, for large n, it is far smaller than either.
  5. For f(x) = x^3 + 1 on [-1, 1], show that T_2 equals the exact area 2, and explain why this does not contradict the concavity result.
Answers
  1. Heights 1, 2.25, 4, 6.25, 9: T_4 = 0.25(1 + 2(12.5) + 9) = 8.75. Over, since f'' = 2 > 0.
  2. \displaystyle T_6 = \frac{1.5}{2}\big(2(0.6 + 1.3 + 1.7 + 1.5 + 0.9)\big) = 9 square meters. Both end depths are 0, so L_6 and R_6 also equal 1.5(6.0) = 9.
  3. Widths 15, 10, 15, 10: 315 + 255 + 360 + 165 = 1095 square meters.
  4. \displaystyle T_6 = \frac{5.2 + 4.6}{2} = 4.9. Since \displaystyle R_6 - L_6 = \frac{3}{6}\big(f(3) - f(0)\big) = -0.6, f(3) - f(0) = -1.2.
  5. \displaystyle T_4 = \frac{\pi}{16}\big(1 + 2(c_1 + c_2 + c_3)\big) \approx 0.9871, with c_1, c_2, c_3 the cosines of \displaystyle \frac{\pi}{8}, \frac{\pi}{4}, \frac{3\pi}{8}. Under, because f''(x) = -\cos x < 0 on \displaystyle \left(0, \frac{\pi}{2}\right).
  6. \displaystyle T_2 = \frac{1}{2}(1 + 2e + e^2) \approx 6.9128 and M_2 = e^{0.5} + e^{1.5} \approx 6.1304. Concave up, so 6.1304 \le A \le 6.9128.
  7. \displaystyle T_3 = \frac{1}{2}(0 + 2\ln 2 + 2\ln 3 + \ln 4) = \ln 12 \approx 2.4849 and M_3 = \ln 1.5 + \ln 2.5 + \ln 3.5 \approx 2.5745. \displaystyle f'' = -\frac{1}{x^2} < 0, so M_3 is over.
  8. T_2 = 10(50 + 2 \cdot 58 + 54) = 2200 square meters, under: a concave down edge lies above its chords.
  9. Concave down would give T_4 \le M_4, so it is concave up. Best estimate: \displaystyle S_8 = \frac{2(3.40) + 3.52}{3} = 3.44.
  10. \displaystyle S_6 = \frac{1.5}{3}(0 + 2.4 + 2.6 + 6.8 + 3.0 + 3.6 + 0) = 0.5(18.4) = 9.2 square meters.
  11. \displaystyle S_2 = \frac{1}{3}(0 + 4 + 16) = \frac{20}{3} and \displaystyle S_4 = \frac{1}{6}(0.25 + 2 + 20.25 + 16) \displaystyle = \frac{77}{12}. Errors \displaystyle \frac{4}{15} and \displaystyle \frac{1}{60}, ratio 16.
  12. Heights \displaystyle 4, \frac{64}{17}, \frac{16}{5}, \frac{64}{25}, 2: T_4 \approx 3.1312 and S_4 \approx 3.14157, against \pi \approx 3.14159. Both fall short, T_4 by about 0.01 and S_4 by about 0.00002.
  13. Heights 0, 3, 18: \displaystyle S_2 = \frac{1}{3}(0 + 12 + 18) = 10 and \displaystyle T_2 = \frac{1}{2}(0 + 6 + 18) = 12. Simpson’s rule is exact for cubics.
  14. \displaystyle S_6 = \frac{2M_3 + T_3}{3} \displaystyle \approx \frac{2(2.5745) + 2.4849}{3} \approx 2.5446, against 4\ln 4 - 3 \approx 2.5452.
  15. K = 1: \displaystyle \frac{\pi^3}{12n^2} < 10^{-4} needs n^2 > 25838.6, so n = 161. K_4 = 1: \displaystyle \frac{\pi^5}{180n^4} < 10^{-4} needs n^4 > 17001.1, so n > 11.42 and, being even, n = 12.
  16. On each piece the graph is the segment joining (x_{k-1}, y_{k-1}) and (x_k, y_k), so the strip is exactly the trapezoid. Adding gives T_n = A.
  17. The chord is \ell(x) = (p + q)x - pq, and \ell(x) - x^2 = -(x - p)(x - q) = (x - p)(q - x), positive for p < x < q. Each trapezoid contains its strip with room to spare, so T_n > A for every n.
  18. Each parabola covers two pieces, so the pieces must pair off. Eight readings make 7 pieces: Gian can use Simpson’s rule on 6 of them and a trapezoid on the last, or trapezoids throughout.
  19. Subtract \displaystyle A = \frac{2A + A}{3} from \displaystyle S_{2n} = \frac{2M_n + T_n}{3} to get \displaystyle \frac{2(M_n - A) + (T_n - A)}{3}, which is \displaystyle \frac{2E_M + E_T}{3}. For large n, \displaystyle E_M \approx -\frac{1}{2}E_T, so 2E_M + E_T \approx 0: the errors nearly cancel.
  20. \displaystyle T_2 = \frac{1}{2}(0 + 2 + 2) = 2. Here f''(x) = 6x changes sign at 0: the left trapezoid is under and the right one over. Since f(x) + f(-x) = 2, the graph is symmetric about (0, 1) and the two errors cancel. The concavity result needs one concavity, so it makes no claim here.
unattributed · CC-BY-SA-4.0