Numerical AnalysisDerivatives and Integrals

Error in the Trapezoid and Simpson's Rules

The composite trapezoid rule has error of order h² and Simpson's rule of order h⁴, so halving h cuts the error by about 4 or 16.

Not started Jump to practice

You have used the trapezoid and Simpson's rules with their error bounds in Trapezoid and Simpson's Rules. Here we read those bounds as statements about order: how fast does the error shrink as the panels get thinner, and for which functions is a rule exact?

Key idea

With step $h = \frac{b - a}{n}$, the composite trapezoid rule has error $-\frac{(b - a)h^{2}}{12}f''(\xi)$: order $h^{2}$. Composite Simpson's rule has error $-\frac{(b - a)h^{4}}{180}f^{(4)}(\xi)$: order $h^{4}$. Doubling $n$ cuts the errors by about 4 and 16. Simpson's rule is exact for every cubic.

Why it works

On one panel the trapezoid rule integrates the line through the endpoints; by the interpolation error formula the gap is $\frac{f''(\xi)}{2}(x - x_i)(x - x_{i+1})$, whose integral over the panel is $-\frac{h^{3}}{12}f''$. There are $n = \frac{b - a}{h}$ panels, so the total is $-\frac{(b - a)h^{2}}{12}f''$ for some average point: one power of $h$ is lost in the sum. Simpson's rule integrates a parabola through three points, which should make it exact only for quadratics. But it is symmetric about the middle point, so it also integrates the odd function $(x - m)^{3}$ exactly (both sides give 0). Hence it is exact for cubics, and its error involves $f^{(4)}$.
Trapezoids under eˣ on [0, 1]. Doubling n divides the trapezoid error by about 4.

Worked example: Measuring the orders

For $\int_0^1 e^{x}\,dx = e - 1$, compare errors with $n = 4, 8, 16$.
  1. Trapezoid: $8.94 \times 10^{-3}$, $2.24 \times 10^{-3}$, $5.59 \times 10^{-4}$: each doubling divides by $4.0$.
  2. Simpson: $3.70 \times 10^{-5}$, $2.33 \times 10^{-6}$, $1.46 \times 10^{-7}$: each doubling divides by $16$.
  3. $\log_2 4 = 2$ and $\log_2 16 = 4$: the orders, read straight from the data.

Answer: orders $2$ and $4$

Worked example: Simpson is exact for cubics

Apply Simpson's rule with $n = 2$ to $\int_0^2 x^{3}\,dx$.
  1. $h = 1$: $S = \frac{1}{3}[f(0) + 4f(1) + f(2)] = \frac{1}{3}[0 + 4 + 8] = 4$.
  2. Exact: $\frac{2^{4}}{4} = 4$. No error at all, with a parabola fitted to a cubic.

Answer: $4$

Errors of the composite trapezoid and Simpson rules for ∫₀¹ eˣ dx as h shrinks: slopes 2 and 4.

Worked example: Error for a quadratic, exactly

Find the trapezoid error for $\int_0^1 x^{2}\,dx$ with $n = 2$.
  1. $T_2 = \frac{1}{2}\left[\frac{0 + 1}{2} + 0.25\right] = 0.375$; the integral is $\frac{1}{3}$.
  2. Error $0.375 - \frac{1}{3} = \frac{1}{24}$, exactly $\frac{(b - a)h^{2}}{12}f'' = \frac{1 \cdot 0.25}{12} \cdot 2$, because $f''$ is constant.

Answer: $\frac{1}{24}$

For the same number of function values, Simpson's rule is almost always the better choice for smooth integrands. The trapezoid rule has one surprising strength: for smooth periodic functions integrated over a full period, its error falls faster than any power of $h$.

Common mistake

Thinking Simpson's rule is exact only for quadratics. It is exact for cubics too, thanks to its symmetry, and its error depends on the fourth derivative. A quick test: try Simpson on $x^{3}$ over any interval; the answer is exact.

Practice

Pass with 3 right answers, the last 2 in a row. Each right answer earns 2 XP.

Loading practice…

Builds on

Leads to

Sources and further reading

  • Tobin A. Driscoll and Richard J. Braun, Fundamentals of Numerical Computation (University of Delaware, free online edition): chapter "Piecewise interpolation", section "Numerical integration"
  • Autar Kaw, Holistic Numerical Methods (University of South Florida): Integration, "Trapezoidal Rule" and "Simpson's 1/3 Rule"
@teddyrookbook GitHub