All courses › Numerical Methods › Trapezoidal rule

Trapezoidal rule

The trapezoidal rule approximates ∫abf(x) dx\int_a^b f(x)\,dx by replacing the curve with straight segments between the points, so the area becomes a sum of trapezoids. Halving the step size hh roughly quarters the error, since the global error is O(h2)O(h^2).

∫abf dx≈h(f02+f1+⋯+fn−1+fn2)\int_a^b f\,dx \approx h\Big(\tfrac{f_0}{2} + f_1 + \cdots + f_{n-1} + \tfrac{f_n}{2}\Big)the trapezoidal rule with nn intervals

Symbols

hhstep size, (b−a)/n(b-a)/n
fif_ifunction value at point ii

Example

∫03x2 dx\int_0^3 x^2\,dx with 2 intervals, h=1.5h = 1.5:

h(f0/2+f1+f2/2)=10.125h(f_0/2 + f_1 + f_2/2) = 10.125 (exact is 9).

The trapezoidal rule overestimates the area for a convex (upward-curving) function.
Practise interpolation and integration for free →

← Fixed-point iteration · Simpson's rule →

Part of Numerical Methods: Interpolation and integration.