Numerical integration and differentiation · Definition

Trapezoidal rule

numerical methodsnumerical integration and differentiation

Before you start you need to know

It is one of the first numerical integration rules studied. Its geometric idea is simple: add up trapezoid areas instead of rectangle areas.

Definition

The trapezoidal rule is a quadrature method that approximates the definite integral of a function \(f\) on \([a,b]\) by replacing the curve with the straight line joining \((a,f(a))\) and \((b,f(b))\).

\[\int_a^b f(x)\,dx \approx \frac{h}{2}\left[f(a)+2\sum_{i=1}^{n-1}f(x_i)+f(b)\right]\]

If \(f\) has a continuous second derivative on \([a,b]\), the error of the composite rule with step \(h=(b-a)/n\) is \(-\frac{(b-a)h^2}{12}f''(\xi)\) for some \(\xi\in(a,b)\), so the error is of order \(O(h^2)\). The rule is exact for polynomials of degree 1, since a line coincides with its trapezoid.

Worked example: for \(\int_0^1 x^2\,dx\) with \(n=2\) (\(h=0.5\)), we get \(\frac{0.5}{2}[0+2(0.25)+1]=0.375\), versus the exact value \(1/3\); the error \(0.0417\) matches the bound from the error term.

Typical error: applying the formula with \(n\) subintervals but using \(h=(b-a)/(n-1)\), or multiplying by \(h\) instead of \(h/2\) at the endpoints. Another common mistake is forgetting the factor 2 on the interior nodes.

Think about it

Why does the trapezoidal rule error depend on \(f''\) and not on \(f'\)?

Because the rule uses a straight line on each subinterval, and \(f''\) measures how far the curve departs from that line; if \(f''=0\), the error is zero.

Exercises 10

What comes next

References

  • Richard L. Burden, J. Douglas Faires, Annette M. Burden, Numerical Analysis, 10th edition, Cengage Learning, 2016.
  • Lloyd N. Trefethen, David Bau III, Numerical Linear Algebra, 1st edition, SIAM, 1997.