Trapezoidal Rule Explained
The Trapezoidal Rule approximates the area under a curve by dividing the interval [a, b] into n equal sub-intervals and connecting adjacent points on the curve with straight lines, forming trapezoids. The area of each trapezoid is averaged between its two heights and multiplied by the width h = (b − a)/n.
The composite formula is:
∫[a→b] f(x) dx ≈ (h/2) [f(x₀) + 2f(x₁) + 2f(x₂) + … + 2f(xₙ₋₁) + f(xₙ)]
The global error is O(h²): halving the interval width reduces the error by a factor of 4. The rule is exact for linear functions.
Simpson's Rule — Why It's More Accurate
Simpson's Rule fits a quadratic (parabola) through every three consecutive points rather than a straight line. Because it captures curvature, the error order jumps to O(h⁴) — halving h reduces the error by a factor of 16.
∫[a→b] f(x) dx ≈ (h/3) [f(x₀) + 4f(x₁) + 2f(x₂) + 4f(x₃) + … + 4f(xₙ₋₁) + f(xₙ)]
Note the alternating 4, 2, 4, 2, … pattern of coefficients (except for the endpoints which have coefficient 1). Simpson's Rule requires n to be even.
It is exact for polynomials of degree 3 or less, which is why it dramatically outperforms the Trapezoidal Rule on smooth functions.
Choosing the Number of Intervals
The appropriate number of intervals n depends on the smoothness of f(x) and the accuracy required:
- n = 10–50: Sufficient for smooth, well-behaved functions using Simpson's Rule.
- n = 100–500: A safe default that gives excellent accuracy for most common functions.
- n = 1000+: Needed for functions with rapid oscillations, sharp peaks or near-singularities.
A practical strategy is Richardson extrapolation: compute the integral with n and 2n intervals. If the results agree to the required decimal places, convergence has been achieved.