Fitting the Curve Better

The trapezoidal rule

First improvement: instead of a flat-topped rectangle, we join the two values of ff at the endpoints of each piece with a segment. We then approximate the area by trapezoids, which follow the curve much better since the segment follows the local slope.

The area of a trapezoid is short base+long base2×height\dfrac{\text{short base} + \text{long base}}{2} \times \text{height}. When we add up all the trapezoids, the interior values f(x1),…,f(xn−1)f(x_1), \ldots, f(x_{n-1}) are counted twice, since each serves as an edge of two neighboring trapezoids, hence the formula:

∫abf(x) dx≈Δx2[f(x0)+2f(x1)+2f(x2)+⋯+2f(xn−1)+f(xn)]\int_a^b f(x)\,\mathrm{d}x \approx \frac{\Delta x}{2}\Bigl[f(x_0) + 2f(x_1) + 2f(x_2) + \cdots + 2f(x_{n-1}) + f(x_n)\Bigr]

The two endpoint values count once, all the interior values count double: this is the pattern 1,2,2,…,2,11, 2, 2, \ldots, 2, 1.

For the same number of points, trapezoids are much more accurate than rectangles: the error decreases like 1n2\dfrac{1}{n^2} instead of 1n\dfrac{1}{n}. Dividing the error by 44 then only takes twice as many points.

Method Top Order of the error
rectangles flat 1n\dfrac{1}{n}
trapezoids slanted segment 1n2\dfrac{1}{n^2}

Remember the principle: replacing the flat top with a slope that follows the curve makes accuracy leap forward. One last idea remains for an even better approximation — curving the top itself.