Unit 10, lesson 125

Integral Approximation Rules

How the midpoint, trapezoidal and Simpson's rules approximate a definite integral, how derivative bounds tell you how many subintervals are enough, and how adaptive methods put the work where it is needed.

  • Theory part 249
  • Practice part 250
  • Numerical Integration

Most integrals have no antiderivative in elementary functions. The area under e−x2e^{-x^2} is the standard example, and data from an experiment has no formula at all. Yet a definite integral is a limit of sums, so a well chosen finite sum gets close. The rules below are the everyday ones, and the error bounds tell you in advance how close they get.

Key terms

Composite midpoint rule

Definition Let ff be defined on [a,b][a, b], let nn be a positive integer, h=b−anh = \frac{b - a}{n} and xi=a+ihx_i = a + ih for i=0,1,…,ni = 0, 1, \dots, n. Let xˉi=xi−1+xi2\bar{x}_i = \frac{x_{i-1} + x_i}{2} be the midpoint of the iith subinterval. The composite midpoint rule is

Mn=h[f(xˉ1)+f(xˉ2)+⋯+f(xˉn)].M_n = h \left[ f(\bar{x}_1) + f(\bar{x}_2) + \dots + f(\bar{x}_n) \right].

It is the Riemann sum that samples each subinterval at its midpoint.

In plain words Cut the interval into nn equal strips and build each rectangle at the height of ff in the middle of the strip.

Example Approximate

∫121x dx=ln⁡2≈0.693147\int_1^2 \frac{1}{x} \, dx = \ln 2 \approx 0.693147

with n=4n = 4. Then h=0.25h = 0.25, the midpoints are 1.125,1.375,1.625,1.8751.125, 1.375, 1.625, 1.875, and

M4=0.25(11.125+11.375+11.625+11.875)≈0.691220,M_4 = 0.25 \left( \frac{1}{1.125} + \frac{1}{1.375} + \frac{1}{1.625} + \frac{1}{1.875} \right) \approx 0.691220,

with error M4−ln⁡2≈−0.00193M_4 - \ln 2 \approx -0.00193.

Composite trapezoidal rule

Definition With the same hh and xix_i, the composite trapezoidal rule is

Tn=h2[f(x0)+2f(x1)+2f(x2)+⋯+2f(xn−1)+f(xn)].T_n = \frac{h}{2} \left[ f(x_0) + 2f(x_1) + 2f(x_2) + \dots + 2f(x_{n-1}) + f(x_n) \right].

It adds the areas of the trapezoids under the line segments joining consecutive points (xi−1,f(xi−1))(x_{i-1}, f(x_{i-1})) and (xi,f(xi))(x_i, f(x_i)), and it equals the average of the left and right Riemann sums.

In plain words Replace the curve on each strip by the straight chord between its endpoints and add up the trapezoids.

Example For the same integral of 1x\frac{1}{x} over [1,2][1, 2] with n=4n = 4,

T4=0.125(1+2⋅11.25+2⋅11.5+2⋅11.75+12)≈0.697024,T_4 = 0.125 \left( 1 + 2 \cdot \frac{1}{1.25} + 2 \cdot \frac{1}{1.5} + 2 \cdot \frac{1}{1.75} + \frac{1}{2} \right) \approx 0.697024,

with error about +0.00388+0.00388. The midpoint error was about half as large and of the opposite sign, which is typical when f′′f'' does not change sign.

Simpson’s rule and the even-subinterval condition

Definition Let nn be even, h=b−anh = \frac{b - a}{n} and xi=a+ihx_i = a + ih. Simpson’s rule is

Sn=h3[f(x0)+4f(x1)+2f(x2)+4f(x3)+⋯+2f(xn−2)+4f(xn−1)+f(xn)],S_n = \frac{h}{3} \left[ f(x_0) + 4f(x_1) + 2f(x_2) + 4f(x_3) + \dots + 2f(x_{n-2}) + 4f(x_{n-1}) + f(x_n) \right],

with coefficients 1,4,2,4,…,2,4,11, 4, 2, 4, \dots, 2, 4, 1. On each pair of subintervals [x2j,x2j+2][x_{2j}, x_{2j+2}] it integrates the parabola through the three points at x2jx_{2j}, x2j+1x_{2j+1}, x2j+2x_{2j+2}. That is why nn must be even, since the strips are used two at a time. For every even nn Simpson’s rule is a weighted average of the trapezoidal and midpoint rules with half as many strips,

Sn=Tn/2+2Mn/23.S_{n} = \frac{T_{n/2} + 2M_{n/2}}{3}.

In plain words Fit a parabola through every three neighboring points instead of a line through every two. With an odd number of strips one strip has no partner, and the pattern of weights breaks.

Example For the integral of 1x\frac{1}{x} over [1,2][1, 2] with n=4n = 4, the points are 1,1.25,1.5,1.75,21, 1.25, 1.5, 1.75, 2 and

S4=0.253(1+41.25+21.5+41.75+12)≈0.693254,S_4 = \frac{0.25}{3} \left( 1 + \frac{4}{1.25} + \frac{2}{1.5} + \frac{4}{1.75} + \frac{1}{2} \right) \approx 0.693254,

with error about 0.0001070.000107, more than thirty times smaller than the trapezoidal error with the same five function values. As a check of the identity,

T4+2M43≈0.697024+2⋅0.6912203≈0.693155,\frac{T_4 + 2M_4}{3} \approx \frac{0.697024 + 2 \cdot 0.691220}{3} \approx 0.693155,

which is S8S_8.

To compare the three rules yourself, choose 1x\frac{1}{x} on [1,2][1, 2] with n=4n = 4 in the Riemann sum explorer, then raise nn and watch the errors shrink.

Derivative-based error bounds

Definition Let EM=∫abf(x) dx−MnE_M = \int_a^b f(x) \, dx - M_n and define ETE_T and ESE_S the same way. If f′′f'' is continuous on [a,b][a, b] and ∣f′′(x)∣≤K\lvert f''(x) \rvert \le K for all xx in [a,b][a, b], then

∣ET∣≤K(b−a)312n2,∣EM∣≤K(b−a)324n2.\lvert E_T \rvert \le \frac{K (b - a)^3}{12 n^2}, \qquad \lvert E_M \rvert \le \frac{K (b - a)^3}{24 n^2}.

If f(4)f^{(4)} is continuous on [a,b][a, b], ∣f(4)(x)∣≤K4\lvert f^{(4)}(x) \rvert \le K_4 for all xx in [a,b][a, b], and nn is even, then

∣ES∣≤K4(b−a)5180n4.\lvert E_S \rvert \le \frac{K_4 (b - a)^5}{180 n^4}.

In plain words Doubling nn cuts the trapezoidal and midpoint errors by about four and Simpson’s error by about sixteen. The bounds also let you pick nn before computing anything.

Example For f(x)=1xf(x) = \frac{1}{x} on [1,2][1, 2] the derivatives satisfy

∣f′′(x)∣=2x3≤2,∣f(4)(x)∣=24x5≤24.\lvert f''(x) \rvert = \frac{2}{x^3} \le 2, \qquad \lvert f^{(4)}(x) \rvert = \frac{24}{x^5} \le 24.

With n=4n = 4 the bounds are 212⋅16≈0.0104\frac{2}{12 \cdot 16} \approx 0.0104 for T4T_4, 224⋅16≈0.0052\frac{2}{24 \cdot 16} \approx 0.0052 for M4M_4 and 24180⋅256≈0.00052\frac{24}{180 \cdot 256} \approx 0.00052 for S4S_4. All three actual errors lie within them. To guarantee an error of at most 10−610^{-6}, the trapezoidal rule needs

212n2≤10−6,son≥409.\frac{2}{12 n^2} \le 10^{-6}, \quad \text{so} \quad n \ge 409.

Simpson’s rule needs

24180n4≤10−6,son≥19.1,\frac{24}{180 n^4} \le 10^{-6}, \quad \text{so} \quad n \ge 19.1,

and since nn must be even, n=20n = 20 is enough.

Adaptive subdivision

Definition An adaptive method chooses subintervals of different lengths according to how hard ff is to integrate on each piece. In adaptive Simpson integration with tolerance τ\tau on a piece [α,β][\alpha, \beta], compute S(1)S_{(1)}, Simpson’s rule with n=2n = 2 on [α,β][\alpha, \beta], and S(2)S_{(2)}, the sum of Simpson’s rule with n=2n = 2 on each half. If

∣S(2)−S(1)∣≤15τ,\lvert S_{(2)} - S_{(1)} \rvert \le 15 \tau,

accept S(2)S_{(2)} for that piece. Otherwise apply the same test to each half with tolerance τ2\frac{\tau}{2}. The factor 1515 comes from the error formula. On one piece the error of Simpson’s rule is proportional to h4f(4)h^4 f^{(4)} at some point. Write E1E_1 and E2E_2 for the errors of S(1)S_{(1)} and S(2)S_{(2)}. If f(4)f^{(4)} is nearly constant on the piece, halving hh gives E1≈16E2E_1 \approx 16 E_2, so

S(2)−S(1)=E1−E2≈15E2.S_{(2)} - S_{(1)} = E_1 - E_2 \approx 15 E_2.

The test therefore asks for ∣E2∣≲τ\lvert E_2 \rvert \lesssim \tau. This estimate is a heuristic, not a guaranteed bound, since f(4)f^{(4)} may change a lot on the piece.

In plain words Do not waste effort where ff is gentle. Compare a coarse and a finer answer on each piece and split only the pieces where they disagree.

Example Take

∫01x dx=23,\int_0^1 \sqrt{x} \, dx = \frac{2}{3},

where ff has an unbounded derivative near 00, so the error bounds above do not apply on [0,1][0, 1]. Comparing coarse and split Simpson values on each half gives this.

PieceCoarseSplitDifferenceExact
[0,0.5][0, 0.5]0.2255920.2255920.2321170.2321176.5×10−36.5 \times 10^{-3}0.2357020.235702
[0.5,1][0.5, 1]0.4309340.4309340.4309620.4309622.8×10−52.8 \times 10^{-5}0.4309640.430964

The right half is nearly settled after one split, while the left half, which touches 00, needs many more. An adaptive method keeps splitting near 00 and leaves the right half alone.

Check yourself

  1. Compute T2T_2 and M2M_2 for ∫02x2 dx\int_0^2 x^2 \, dx and compare with the exact value.
Show the answer

Here h=1h = 1, so

T2=12(0+2⋅1+4)=3,M2=1⋅(0.25+2.25)=2.5.T_2 = \frac{1}{2}(0 + 2 \cdot 1 + 4) = 3, \qquad M_2 = 1 \cdot (0.25 + 2.25) = 2.5.

The exact value is 83≈2.667\frac{8}{3} \approx 2.667, so T2T_2 is 13\frac{1}{3} too big and M2M_2 is 16\frac{1}{6} too small.

  1. Show that Simpson’s rule with n=2n = 2 gives the exact value of ∫02x3 dx\int_0^2 x^3 \, dx.
Show the answer

With h=1h = 1,

S2=13(0+4⋅1+8)=4,S_2 = \frac{1}{3}(0 + 4 \cdot 1 + 8) = 4,

and ∫02x3 dx=4\int_0^2 x^3 \, dx = 4. This agrees with the error bound, since f(4)=0f^{(4)} = 0 for a cubic.

  1. How large must nn be for the midpoint rule to approximate ∫01ex dx\int_0^1 e^{x} \, dx within 10−410^{-4}?
Show the answer

On [0,1][0, 1] we have ∣f′′∣=ex≤e\lvert f'' \rvert = e^x \le e. You need

e24n2≤10−4,son2≥e24⋅104≈1132.6,\frac{e}{24 n^2} \le 10^{-4}, \quad \text{so} \quad n^2 \ge \frac{e}{24} \cdot 10^4 \approx 1132.6,

which means n≥34n \ge 34.

How this lesson connects

It also uses approximation error.

Resources for this lesson