numerical integration
The Trapezoidal Rule
You should know: numerical integration
Overview
The trapezoidal rule approximates a definite integral by replacing the curve y = f(x) with straight-line segments connecting consecutive sampled points, then summing the areas of the resulting trapezoids. It is the simplest quadrature rule beyond a single rectangle and is exact for any linear function. Applied over n equal subintervals of width h = (b−a)/n (the 'composite' trapezoidal rule), its error is O(h²): halving the step size quarters the error. Because it needs only function values (no derivatives) and is trivial to implement, it is a standard tool for integrating both formulas and tabulated experimental data.
Intuition
Instead of trying to measure the exact area under a curved boundary, draw a straight line between each pair of neighboring sample points and measure the area of the resulting trapezoid — a shape whose area is easy to compute exactly as the average of the two parallel heights times the width. Adding up many thin trapezoids traces the curve closely, and because straight lines are a good local approximation to any smooth curve over a short enough interval, the total area converges to the true integral as the panels get narrower.
Formal Definition
On a single interval [x₀, x₁] the area under the chord connecting the endpoints is:
Worked Examples
Step size h = (1−0)/4 = 0.25; nodes x = 0, 0.25, 0.5, 0.75, 1.
Function values f(x) = 1/(1+x²).
Apply the composite formula (h/2)[f₀ + 2(f₁+f₂+f₃) + f₄].
Compare with the exact value π/4 ≈ 0.785398.
Answer: Trapezoidal estimate ≈ 0.782794 vs. exact π/4 ≈ 0.785398 (error ≈ 0.0026, about 0.33%).
Practice Problems
Approximate ∫₀² x dx using the trapezoidal rule with n = 2, and state whether it matches the exact value.
River depth (m) measured every 2 m across a 8 m-wide channel is 0, 1.5, 2.0, 1.2, 0. Use the trapezoidal rule to estimate the cross-sectional area.
Doubling the number of subintervals n in the composite trapezoidal rule (halving h) reduces the error by approximately a factor of:
Quiz
Summary
- The trapezoidal rule sums trapezoid areas formed by connecting consecutive samples with straight lines: (h/2)[f₀+2(f₁+...+fₙ₋₁)+fₙ].
- It is exact for linear functions and has O(h²) truncation error for smooth f, so halving h quarters the error.
- It requires only function values (no derivatives), making it simple to apply to both formulas and tabulated data.
References
- WebsiteWikipedia — Trapezoidal rule
Mathematics