Consider the numerical evaluation:
∫0π/2 sin(x) dx
whose exact value is 1. Using the trapezoidal method:
∫0π/2 sin(x) dx ≃ (π/2)/2 [sin(0) + sin(π/2)] = π/4 ≈ 0.785398164
This is a poor approximation of the exact value 1, due to approximating sin(x) over [0, π/2] with a degree 1 polynomial.
A better approach is to divide the integration interval [a,b] into n subintervals of length:
h = (b−a)/n
Let the points be xi, i = 0,1,2,...,n with x₀ = a and xₙ = b. Applying the trapezoidal method on each subinterval [xi,xi+1]:
∫ab f(x) dx ≃ ∑i=0n-1 ∫xixi+1 f(x) dx ≃ ∑i=0n-1 h/2 [f(xi) + f(xi+1)]
Summing these contributions, all interior f(xi) appear twice except the first and last:
∫ab f(x) dx ≃ h/2 [ f(x₀) + 2(f(x₁) + f(x₂) + ... + f(xn-1)) + f(xₙ) ]
This is the composite trapezoidal formula. Regarding the error, each subinterval contributes an error − f″(ηi) / 12 h³. Denoting n = (b−a)/h, the total error becomes:
E ≃ − (b−a) / 12 f″(η) h², η ∈ [a,b]
Although the derivation is not fully rigorous (since each subinterval has a potentially different ηi), applying the mean value theorem gives the global error. The composite trapezoidal method is therefore of order 2.