All formulas

Numerical methods

Composite trapezoidal rule

num.trapezoidAlso called trapezoid, trapezoidal rule, trapz, trapezoidal

T=h2∑i=1n−1(yi−1+yi)T = \frac{h}{2}\sum_{i=1}^{n-1}\left(y_{i-1} + y_{i}\right)

Integral estimate from n equally spaced samples y0 … yn−1 with spacing h: the sum of trapezoid areas over the n − 1 intervals.

Notation

yy

function values at equally spaced points y0 … yn−1

y ∈ ℝn

hh

spacing between points

h > 0 · default 1

nn

number of sample points

Size, at least 2

TT

Result: the integral estimate

scalar

Worked examples

Each result is solved exactly and confirmed by two independent computations.

  1. Given

    y=[0,1,2],h=1y = [0, 1, 2], h = 1

    Result

    T=2\displaystyle T = 2
  2. Given

    y=[1,1],h=0.5y = [1, 1], h = 0.5

    Result

    T=12\displaystyle T = \frac{1}{2}

    ≈ 0.5

  3. Given

    y=[0,1,4,9]y = [0, 1, 4, 9]

    Result

    T=192\displaystyle T = \frac{19}{2}

    ≈ 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.

    dlmf.nist.gov