Derivation: trapezoid rule

Integrating the linear Lagrange interpolant on [a,b] to obtain the trapezoid rule and its geometric interpretation.

Integrating the interpolating line

We want to approximate abf(x)dx\int_a^b f(x)\,dx using only the values of the function at the endpoints. Replace the curve by the line through (a,f(a))(a,f(a)) and (b,f(b))(b,f(b)), then integrate that line.

abf(a)f(b)interpolating linefunction fapproximate area
The curve is replaced by the interpolating line. The area under that line is the trapezoid approximation.
Expand diagram

The curve is replaced by the interpolating line. The area under that line is the trapezoid approximation.

Derivation with Lagrange
  1. Take the endpoint nodes x0=ax_0=a and x1=bx_1=b, with h=bah=b-a. The linear Lagrange bases equal 1 at their node and 0 at the other one:

    L0(x)=xbab,L1(x)=xabaL_0(x)=\frac{x-b}{a-b},\qquad L_1(x)=\frac{x-a}{b-a}
  2. The linear interpolant is the combination of the known values:

    p1(x)=f(a)L0(x)+f(b)L1(x)p_1(x)=f(a)L_0(x)+f(b)L_1(x)
  3. Approximate the integral of ff by the integral of p1p_1. The weights of the formula are the integrals of the bases:

    If(a)abL0(x)dx+f(b)abL1(x)dxI\approx f(a)\int_a^b L_0(x)\,dx+f(b)\int_a^b L_1(x)\,dx
  4. Compute the first weight with the change s=xas=x-a. Then xb=shx-b=s-h, ab=ha-b=-h, dx=dsdx=ds, and the limits x=a,bx=a,b become s=0,hs=0,h:

    abL0(x)dx=abxbabdx=0hhshds=1h[hss22]0h=h2\begin{aligned}\int_a^b L_0(x)\,dx&=\int_a^b\frac{x-b}{a-b}\,dx\\&=\int_0^h\frac{h-s}{h}\,ds\\&=\frac{1}{h}\left[hs-\frac{s^2}{2}\right]_0^h=\frac{h}{2}\end{aligned}
  5. Compute the second weight with the same change. Now xa=sx-a=s and ba=hb-a=h:

    abL1(x)dx=abxabadx=0hshds=1h[s22]0h=h2\begin{aligned}\int_a^b L_1(x)\,dx&=\int_a^b\frac{x-a}{b-a}\,dx\\&=\int_0^h\frac{s}{h}\,ds=\frac{1}{h}\left[\frac{s^2}{2}\right]_0^h=\frac{h}{2}\end{aligned}
  6. Both weights are h/2h/2. Substituting them in the quadrature formula gives the simple trapezoid rule:

    abf(x)dxh2[f(a)+f(b)]\int_a^b f(x)\,dx\approx\frac{h}{2}\left[f(a)+f(b)\right]
ab1L₀(x)area h/2ab1L₁(x)area h/2
Each Lagrange basis has area h/2h/2 on [a,b][a,b]. That gives the two endpoints the same weight.
Expand diagram

Each Lagrange basis has area h/2h/2 on [a,b][a,b]. That gives the two endpoints the same weight.

Geometric reading
  1. The integral of p1p_1 is the area under a line. That region is a trapezoid with base h=bah=b-a and parallel heights f(a)f(a) and f(b)f(b).

    Atrapecio=base2(altura1+altura2)A_{\text{trapecio}}=\frac{\text{base}}{2}\left(\text{altura}_1+\text{altura}_2\right)
  2. Identifying the base and heights gives the same expression as the Lagrange derivation:

    Atrapecio=ba2[f(a)+f(b)]A_{\text{trapecio}}=\frac{b-a}{2}\left[f(a)+f(b)\right]
abbase h=b-af(a)f(b)A = h(f(a)+f(b))/2
The formula is the area of a trapezoid: base times the average of the two heights.
Expand diagram

The formula is the area of a trapezoid: base times the average of the two heights.

Error term
  1. If fC2[a,b]f\in\mathcal{C}^2[a,b], the linear interpolation error at each point has this form:

    f(x)p1(x)=f(ξx)2(xa)(xb)f(x)-p_1(x)=\frac{f''(\xi_x)}{2}(x-a)(x-b)
  2. Integrate the product multiplying ff''. With s=xas=x-a, (xa)(xb)=s(sh)(x-a)(x-b)=s(s-h):

    ab(xa)(xb)dx=0hs(sh)ds=h36\int_a^b(x-a)(x-b)\,dx=\int_0^h s(s-h)\,ds=-\frac{h^3}{6}
  3. By the mean value theorem for integrals, there is ξ(a,b)\xi\in(a,b) such that:

    abf(x)dxh2[f(a)+f(b)]=h312f(ξ)\int_a^b f(x)\,dx-\frac{h}{2}\left[f(a)+f(b)\right]=-\frac{h^3}{12}f''(\xi)
  4. The rule has local order 2: the error depends on the curvature of ff and grows like (ba)3(b-a)^3 on a single interval.