Numerical integration and differentiation · Definition
Trapezoidal rule
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))\).
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 is the step \(h\) when applying the composite trapezoidal rule to \(\int_0^2 f(x)\,dx\) with \(n=4\) subintervals?
- What geometric shape does the trapezoidal rule use on each subinterval?
- What is the coefficient of \(f(x_i)\) for an interior node \(x_i\) in the composite trapezoidal rule?
- For which type of functions is the trapezoidal rule exact?
- What is the order of the error of the composite trapezoidal rule with respect to the step \(h\)?
- Apply the composite trapezoidal rule to \(\int_0^2 x^2\,dx\) with \(n=2\). What value do you get?
- Using the trapezoidal rule with \(n=4\) on \(\int_0^1 e^x\,dx\), what is the approximation given nodes \(f(0)=1\), \(f(0.25)\approx1.2840\), \(f(0.5)\approx1.6487\), \(f(0.75)\approx2.1170\), \(f(1)\approx2.7183\)?
- If the error of the composite trapezoidal rule with \(n=2\) on \(\int_0^1 x^2\,dx\) is \(0.0417\), what is the approximate error with \(n=4\)?
- What value does the trapezoidal rule give with \(n=1\) for \(\int_1^3 \frac{1}{x}\,dx\)?
- Let \(f\) satisfy \(|f''(x)|\le M\) on \([0,1]\). Show that the composite trapezoidal rule with \(n\) subintervals for \(\int_0^1 f\) has error bounded by \(\frac{M}{12n^2}\). Which statement is correct?
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.