Numerical methods
Composite trapezoidal rule
num.trapezoidAlso called trapezoid, trapezoidal rule, trapz, trapezoidal
Integral estimate from n equally spaced samples y0 … yn−1 with spacing h: the sum of trapezoid areas over the n − 1 intervals.
Notation
function values at equally spaced points y0 … yn−1
y ∈ ℝn
spacing between points
h > 0 · default 1
number of sample points
Size, at least 2
Result: the integral estimate
scalar
Worked examples
Each result is solved exactly and confirmed by two independent computations.
Given
Result
Given
Result
≈ 0.5
Given
Result
≈ 9.5
Common mistakes
Left Riemann sum
Each interval uses only its left value, h Σ y0 … yn−2, a rectangle rule.
Fix: Average the two endpoint values of each interval.
Sums every sample with weight h
The two endpoints get weight h instead of h/2.
Fix: Weight the first and last samples by h/2 and the interior ones by h.
Source
DLMF, eq. 3.5.2
NIST Digital Library of Mathematical Functions. https://dlmf.nist.gov/ Release 1.2.8 of 2026-09-15. F. W. J. Olver, A. B. Olde Daalhuis, D. W. Lozier, B. I. Schneider, R. F. Boisvert, C. W. Clark, B. R. Miller, B. V. Saunders, H. S. Cohl, and M. A. McClain, eds.