8.2 Elements of numerical integration

To approximate \(\int _a^bf(x)\,dx\), numerical quadrature uses a weighted sum \(\sum a_if(x_i)\). Integrating the Lagrange polynomial through equally spaced nodes gives the Newton–Cotes formulas. The two simplest are the following.

Theorem 8.2.1 (Trapezoidal rule). With \(h = b-a\), \[\int _a^bf(x)\,dx = \frac h2\bigl [f(a)+f(b)\bigr ]-\frac {h^3}{12}f''(\xi ),\qquad \xi \in (a,b).\]

Proof. The linear interpolant at \(x_0 = a\), \(x_1 = b\) has error \(\frac {f''(\xi (x))}{2}(x-a)(x-b)\). Its integral is \(\frac h2[f(a)+f(b)]\), the area of a trapezoid. The error integral is \(\frac 12\int _a^bf''(\xi (x))(x-a)(x-b)\,dx\); since \((x-a)(x-b)\) does not change sign on \([a,b]\), the Weighted Mean Value Theorem (Theorem 1.1.5) gives \[\frac {f''(\xi )}{2}\int _a^b(x-a)(x-b)\,dx = \frac {f''(\xi )}{2}\left (-\frac {h^3}{6}\right ) = -\frac {h^3}{12}f''(\xi ) .\] □

Theorem 8.2.2 (Simpson’s rule). With \(h = \frac {b-a}{2}\) and \(x_1 = a+h\), \[\int _a^bf(x)\,dx = \frac h3\bigl [f(a)+4f(x_1)+f(b)\bigr ]-\frac {h^5}{90}f^{(4)}(\xi ),\qquad \xi \in (a,b).\]

Proof. Integrating the quadratic interpolant gives the weights \(\frac h3,\frac {4h}3,\frac h3\). For the error, the direct approach gives only \(O(h^4)\), because the cubic \((x-a)(x-x_1)(x-b)\) changes sign. Instead expand \(f\) about \(x_1\): \(f(x) = f(x_1)+f'(x_1)(x-x_1)+\frac {f''(x_1)}{2}(x-x_1)^2+\frac {f'''(x_1)}{6}(x-x_1)^3+\frac {f^{(4)}(\xi (x))}{24}(x-x_1)^4\). Integrating over \([x_1-h,x_1+h]\), the odd powers vanish by symmetry, and the Weighted Mean Value Theorem applied to \((x-x_1)^4\geq 0\) gives \[\int _a^bf = 2hf(x_1)+\frac {h^3}{3}f''(x_1)+\frac {f^{(4)}(\xi _1)}{60}h^5 .\] Replacing \(f''(x_1)\) by the central difference \(\frac {f(a)-2f(x_1)+f(b)}{h^2}-\frac {h^2}{12}f^{(4)}(\xi _2)\) (derived by adding the Taylor expansions of \(f(x_1\pm h)\)) gives \[\int _a^bf = \frac h3[f(a)+4f(x_1)+f(b)]-\frac {h^5}{12}\left [\frac 13f^{(4)}(\xi _2)-\frac 15f^{(4)}(\xi _1)\right ],\] and a more careful argument shows that the bracket can be replaced by \(\frac {2}{15}f^{(4)}(\xi )\), giving \(-\frac {h^5}{90}f^{(4)}(\xi )\). □

Definition 8.2.3. The degree of precision of a quadrature formula is the largest \(n\) such that the formula is exact for \(x^k\), \(k = 0,1,\dots ,n\).

The error terms show that the trapezoidal rule has degree of precision \(1\) and Simpson’s rule degree \(3\): one more than its number of intervals suggests, because the error involves \(f^{(4)}\), which vanishes for cubics. The same happens for every Newton–Cotes formula with an odd number of points. With four points, \(h = \frac {b-a}3\), integration of the cubic interpolant gives Simpson’s three-eighths rule \[\int _a^bf(x)\,dx = \frac {3h}{8}\bigl [f(x_0)+3f(x_1)+3f(x_2)+f(x_3)\bigr ]-\frac {3h^5}{80}f^{(4)}(\xi ),\] which also has degree of precision \(3\), with a slightly smaller error constant than Simpson’s rule over the same interval.

Example 8.2.4. Compare the trapezoidal rule, Simpson’s rule and Simpson’s three-eighths rule for \(\int _0^2f(x)\,dx\) for several functions.

Solution.

\(f(x)\) \(x^2\) \(x^4\) \(\frac 1{x+1}\) \(\sqrt {1+x^2}\) \(\sin x\) \(e^x\)
exact \(2.667\) \(6.400\) \(1.099\) \(2.958\) \(1.416\) \(6.389\)
trapezoidal \(4.000\) \(16.000\) \(1.333\) \(3.236\) \(0.909\) \(8.389\)
Simpson \(2.667\) \(6.667\) \(1.111\) \(2.964\) \(1.425\) \(6.421\)
Simpson \(\frac 38\) \(2.667\) \(6.519\) \(1.105\) \(2.960\) \(1.420\) \(6.403\)

Both Simpson rules are exact for \(x^2\) (degree of precision \(3\)); neither is exact for \(x^4\). For the trapezoidal rule, \(h = 2\) is far too large; the next subsection shows how to use these rules on small subintervals.

Questions on this section

Stuck on something here? Ask below and it stays attached to this topic.