Closed Newton-Cotes: trapezoid, Simpson and more

Closed rules for equally spaced nodes that include the endpoints: trapezoid, Simpson 1/3, Simpson 3/8, Milne and their errors.

Simple rules

Closed rules interpolate using equally spaced nodes that include a and b. More nodes can give a higher degree of exactness, but sensitivity also increases if the function oscillates.

RuleSimple approximationLeading error
Trapecioh/2 [f(a)+f(b)]-h^3 f''(xi)/12
Simpson 1/3h/3 [f(a)+4f((a+b)/2)+f(b)]-h^5 f^(4)(xi)/90
Simpson 3/83h/8 [f(a)+3f((2a+b)/3)+3f((a+2b)/3)+f(b)]-3h^5 f^(4)(xi)/80
Milne2h/45 [7f(a)+32f((3a+b)/4)+12f((a+b)/2)+32f((a+3b)/4)+7f(b)]-8h^7 f^(6)(xi)/945
In each row, h is the spacing between the nodes of that simple rule.

Composite trapezoid

To reduce the error, [a,b] is split into n subintervals and the trapezoid rule is applied on each one. Interior nodes appear twice, so they receive weight 2.

width hx₀x₁x₂x₃xₙinterior nodes: weight 2
The composite trapezoid rule sums simple trapezoids. Each interior node is the right endpoint of one subinterval and the left endpoint of the next.
Expand diagram

The composite trapezoid rule sums simple trapezoids. Each interior node is the right endpoint of one subinterval and the left endpoint of the next.

Derivation for n subintervals
  1. Split the interval with xi=a+ihx_i=a+ih and h=(ba)/nh=(b-a)/n.

    a=x0<x1<<xn=ba=x_0<x_1<\cdots<x_n=b
  2. Apply the simple trapezoid rule on each subinterval [xi,xi+1][x_i,x_{i+1}]:

    Ti=h2[f(xi)+f(xi+1)]T_i=\frac{h}{2}\left[f(x_i)+f(x_{i+1})\right]
  3. Sum all trapezoids. After expanding the sum, interior nodes appear twice:

    Tn=i=0n1h2[f(xi)+f(xi+1)]=h2[f(x0)+2i=1n1f(xi)+f(xn)]\begin{aligned}T_n&=\sum_{i=0}^{n-1}\frac{h}{2}\left[f(x_i)+f(x_{i+1})\right]\\&=\frac{h}{2}\left[f(x_0)+2\sum_{i=1}^{n-1}f(x_i)+f(x_n)\right]\end{aligned}
  4. The global error comes from summing the local errors h3f(ξi)/12-h^3 f''(\xi_i)/12 and applying the mean value theorem:

    ET=h312i=0n1f(ξi)=ba12h2f(ξ)E_T=-\frac{h^3}{12}\sum_{i=0}^{n-1}f''(\xi_i)=-\frac{b-a}{12}h^2 f''(\xi)
Ih2[f(x0)+2i=1n1f(xi)+f(xn)],h=banI\approx\frac{h}{2}\left[f(x_0)+2\sum_{i=1}^{n-1}f(x_i)+f(x_n)\right],\qquad h=\frac{b-a}{n}
ET=ba12h2f(ξ)E_T=-\frac{b-a}{12}h^2 f''(\xi)
Global error of the composite trapezoid rule.

Composite Simpson

Simpson 1/3 groups subintervals in pairs, so n must be even. The weights alternate 4 and 2: odd nodes are midpoints of each parabola, while interior even nodes connect consecutive blocks.

Ih3[f(x0)+4i imparf(xi)+2i par, 0<i<nf(xi)+f(xn)]I\approx\frac{h}{3}\left[f(x_0)+4\sum_{i\ \mathrm{impar}}f(x_i)+2\sum_{i\ \mathrm{par},\ 0<i<n}f(x_i)+f(x_n)\right]
ES=ba180h4f(4)(ξ)E_S=-\frac{b-a}{180}h^4 f^{(4)}(\xi)
Global error of composite Simpson.

Derivations

DerivationDerivation: trapezoid ruleView as its own page →

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.

DerivationDerivation: composite trapezoidView as its own page →
width hx₀x₁x₂x₃xₙinterior nodes: weight 2
Each subinterval contributes one trapezoid. Interior nodes are counted twice.
Expand diagram

Each subinterval contributes one trapezoid. Interior nodes are counted twice.

Formula for n subintervals
  1. Split [a,b][a,b] into n equal subintervals:

    xi=a+ih,h=ban,i=0,,nx_i=a+ih,\qquad h=\frac{b-a}{n},\qquad i=0,\ldots,n
  2. On [xi,xi+1][x_i,x_{i+1}], apply the simple trapezoid rule:

    Ti=h2[f(xi)+f(xi+1)]T_i=\frac{h}{2}\left[f(x_i)+f(x_{i+1})\right]
  3. The total approximation is the sum of the n trapezoids:

    Tn=i=0n1Ti=h2i=0n1[f(xi)+f(xi+1)]\begin{aligned}T_n&=\sum_{i=0}^{n-1}T_i\\&=\frac{h}{2}\sum_{i=0}^{n-1}\left[f(x_i)+f(x_{i+1})\right]\end{aligned}
  4. When the full sum is written out, f(x0)f(x_0) and f(xn)f(x_n) appear once. Every interior value appears twice:

    Tn=h2[f(x0)+2i=1n1f(xi)+f(xn)]T_n=\frac{h}{2}\left[f(x_0)+2\sum_{i=1}^{n-1}f(x_i)+f(x_n)\right]
  5. The global error is obtained by summing the local errors of the simple trapezoid rule:

    ET=h312i=0n1f(ξi)=ba12h2f(ξ)\begin{aligned}E_T&=-\frac{h^3}{12}\sum_{i=0}^{n-1}f''(\xi_i)\\&=-\frac{b-a}{12}h^2f''(\xi)\end{aligned}
DerivationDerivation: Simpson 1/3View as its own page →
  1. Take x0=ax_0=a, x1=a+b2x_1=\frac{a+b}{2} and x2=bx_2=b. Write h=ba2h=\frac{b-a}{2} and use t=xaht=\frac{x-a}{h}, so tt runs over [0,2][0,2].

    dx=hdtdx=h\,dt
  2. The quadratic bases in the variable t are:

    0(t)=(t1)(t2)2,1(t)=t(t2),2(t)=t(t1)2\ell_0(t)=\frac{(t-1)(t-2)}{2},\quad \ell_1(t)=-t(t-2),\quad \ell_2(t)=\frac{t(t-1)}{2}
  3. Integrate each basis on [0,2] and multiply by h:

    h020(t)dt=h3,h021(t)dt=4h3,h022(t)dt=h3h\int_0^2\ell_0(t)dt=\frac{h}{3},\quad h\int_0^2\ell_1(t)dt=\frac{4h}{3},\quad h\int_0^2\ell_2(t)dt=\frac{h}{3}
  4. Collecting the terms gives Simpson 1/3:

    abf(x)dxh3[f(a)+4f ⁣(a+b2)+f(b)]\int_a^b f(x)\,dx\approx\frac{h}{3}\left[f(a)+4f\!\left(\frac{a+b}{2}\right)+f(b)\right]