Approximate a definite integral using the composite trapezoidal rule with n subintervals.
The composite trapezoidal rule approximates ∫f(x)dx by connecting adjacent points with straight lines and summing the trapezoid areas. Error is O(h²), making it less accurate than Simpson's rule but simpler and applicable with any number of subintervals.
Trapezoidal rule
∫[a,b]f(x)dx ≈ h·[f(x₀)/2 + f(x₁) + f(x₂) + ... + f(xₙ)/2]
For periodic functions integrated over a full period, the trapezoidal rule can be exponentially accurate (superconvergence), outperforming even Simpson's rule.
Doubling n reduces error by a factor of 4 (quadratic convergence in n).