Mathematics.

numerical integration

The Trapezoidal Rule

Numerical Analysis15 minDifficulty2 out of 10

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

Definition

On a single interval [x₀, x₁] the area under the chord connecting the endpoints is:

x0x1f(x)dxh2[f(x0)+f(x1)],h=x1x0\int_{x_0}^{x_1} f(x)\,dx \approx \dfrac{h}{2}\big[f(x_0)+f(x_1)\big], \quad h = x_1-x_0
Single-panel trapezoidal rule
abf(x)dxh2[f0+2i=1n1fi+fn],h=ban\int_a^b f(x)\,dx \approx \dfrac{h}{2}\Big[f_0 + 2\sum_{i=1}^{n-1}f_i + f_n\Big], \quad h=\dfrac{b-a}{n}
Composite trapezoidal rule
E=(ba)h212f(ξ),ξ(a,b)E = -\dfrac{(b-a)h^2}{12}f''(\xi), \quad \xi \in (a,b)
Error term (f twice continuously differentiable)

Worked Examples

  1. Step size h = (1−0)/4 = 0.25; nodes x = 0, 0.25, 0.5, 0.75, 1.

    h=0.25h = 0.25
  2. Function values f(x) = 1/(1+x²).

    f0=1,  f1=0.941176,  f2=0.8,  f3=0.64,  f4=0.5f_0=1,\; f_1=0.941176,\; f_2=0.8,\; f_3=0.64,\; f_4=0.5
  3. Apply the composite formula (h/2)[f₀ + 2(f₁+f₂+f₃) + f₄].

    0.252[1+2(0.941176+0.8+0.64)+0.5]=0.125[1+4.762353+0.5]=0.125(6.262353)=0.782794\tfrac{0.25}{2}\big[1 + 2(0.941176+0.8+0.64) + 0.5\big] = 0.125\,[1 + 4.762353 + 0.5] = 0.125(6.262353) = 0.782794
  4. Compare with the exact value π/4 ≈ 0.785398.

    0111+x2dx=π40.785398\int_0^1 \dfrac{1}{1+x^2}\,dx = \dfrac{\pi}{4} \approx 0.785398

Answer: Trapezoidal estimate ≈ 0.782794 vs. exact π/4 ≈ 0.785398 (error ≈ 0.0026, about 0.33%).

Practice Problems

Difficulty 2/10

Approximate ∫₀² x dx using the trapezoidal rule with n = 2, and state whether it matches the exact value.

Difficulty 5/10

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.

Difficulty 3/10

Doubling the number of subintervals n in the composite trapezoidal rule (halving h) reduces the error by approximately a factor of:

Quiz

The trapezoidal rule approximates the integrand between two nodes with a:
The trapezoidal rule gives the exact integral whenever f is:
The composite trapezoidal rule's truncation error is of order:

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