The trapezoidal rule

An integral whose antiderivative cannot be found is approximated numerically. Laying out trapezoids instead of rectangles is the trapezoidal rule1. We look at its accuracy for f(x)=x2f(x) = x^2 from 00 to 22.

Trying two pieces

The area of a trapezoid is the average of the two parallel sides times the width.

f(0)+f(1)2×1+f(1)+f(2)2×1=0+12+1+42=3\frac{f(0) + f(1)}{2} \times 1 + \frac{f(1) + f(2)}{2} \times 1 = \frac{0 + 1}{2} + \frac{1 + 4}{2} = 3

The true value is 832.667\dfrac{8}{3} \approx 2.667, so the error is 13\dfrac{1}{3}.

The general form

It is a sum with half weight on the two ends.

abf(x)dxh(f02+f1++fn1+fn2)\int_a^b f(x)\,dx \approx h \left( \frac{f_0}{2} + f_1 + \cdots + f_{n-1} + \frac{f_n}{2} \right)

It is also the average of the left-endpoint sum and the right-endpoint sum.

ConstructionValue
Left-endpoint sum11
Right-endpoint sum55
Their average, the trapezoidal rule33

An underestimate and an overestimate, added and halved.

Refining the partition

PartitionhhApproximationError
Two pieces113313\dfrac{1}{3}
Four pieces0.50.52.752.75112\dfrac{1}{12}

Halving hh quarters the error, which shows that the error is proportional to h2h^2. The error of a plain rectangle sum is proportional to hh, so the trapezoidal rule shrinks faster.

Which way the error goes

Concavity of the functionWhat the trapezoidal rule gives
Concave upan overestimate
Concave downan underestimate

It is decided by whether the top of the trapezoid lies above or below the curve. Knowing the concavity tells one the direction of the error.

Improving the accuracy further

Approximate with parabolas rather than lines. Joining three points at a time with a parabola gives Simpson's rule, whose error is proportional to h4h^4, and with the same four pieces it reproduces 83\dfrac{8}{3} exactly2. A quadratic is represented perfectly by a parabola.

The smooth curve on the graph is y=x2y = x^2, the polyline is the approximation joining the tops of the trapezoids, and the large dots are the division points.

  1. Trapezoidal rule, Wikipedia
  2. Simpson's rule, Wikipedia