Leave lesson

Pure · Numerical methods

1 / 11

The trapezium rule

Estimating a definite integral by slicing the area into trapezium-topped strips: the formula (h/2)[y₀ + yₙ + 2(y₁ + … + y_(n−1))], choosing h, and deciding whether the estimate is an over- or under-estimate from the curve's shape.

Pure · Numerical methods

The trapezium rule

Estimating a definite integral by slicing the area into trapezium-topped strips: the formula (h/2)[y₀ + yₙ + 2(y₁ + … + y_(n−1))], choosing h, and deciding whether the estimate is an over- or under-estimate from the curve's shape.

Why it works

A definite integral abydx\int_a^b y\,dx is the area under a curve, and ideally you find it exactly by integrating. But many functions — x2+1\sqrt{x^2 + 1}, 2x2^x, 1+x3\sqrt{1 + x^3} — have no elementary integral. The trapezium rule estimates the area instead, by replacing the awkward curved region with strips you can measure.

Cut [a,b][a, b] into nn equal strips, each of width h=ban.h = \frac{b - a}{n}. Over one strip the curve is nearly straight, so approximate it by the straight line joining its two ends — turning each strip into a trapezium. A trapezium with parallel sides (the two ordinates) ylefty_{\text{left}} and yrighty_{\text{right}} a distance hh apart has area h2(yleft+yright)\tfrac{h}{2}(y_{\text{left}} + y_{\text{right}}). Add up all nn trapezia and every interior ordinate gets counted twice (it is the right side of one strip and the left side of the next), while the two ends are counted once: abydxh2[y0+yn+2(y1+y2++yn1)].\int_a^b y\,dx \approx \frac{h}{2}\Big[\,y_0 + y_n + 2(y_1 + y_2 + \dots + y_{n-1})\,\Big]. Ends once, middles twice. With nn strips there are n+1n + 1 ordinates y0,y1,,yny_0, y_1, \dots, y_n, taken at x=a,a+h,a+2h,,bx = a, a+h, a+2h, \dots, b.0.511.522.533.5412345xyOver- or under-estimate? It depends on which way the curve bends:
  • Where the curve is convex (bending upward, d2ydx2>0\frac{d^2y}{dx^2} > 0), each straight
chord lies above the curve, so the trapezia include a little extra — the rule over-estimates.
  • Where the curve is concave (bending downward), the chords lie below the curve
and the rule under-estimates.

So a quick look at the shape (or the sign of the second derivative) tells you the direction of the error. The curve above, y=x2+1y = \sqrt{x^2 + 1}, is convex, so the trapezium estimate of its area is an over-estimate.

Accuracy. More strips means thinner trapezia hugging the curve more closely, so a larger nn (smaller hh) gives a better estimate. Halving hh roughly quarters the error.