Quadrature Measures Area in Strips
A definite integral is the area under a curve. But countless functions have no closed-form antiderivative you can integrate by hand, and often you have only sampled points, like experimental data, with no formula at all. So how do you find the area? The idea is as simple as grade-school area: chop the interval [a,b] into thin vertical strips, approximate each strip's area with an easy shape, and add them up. Filling with rectangles is crude; slicing the top diagonally into trapezoids is better; pairing strips and fitting a parabola is far more accurate. The finer the strips (the larger n), the closer you get to the truth, but the rate of approach differs from rule to rule. In this lesson we fix one integral whose exact value is known (f=1+sin x, answer π+2) and compare, with our eyes, how differently three rules perform for the same effort.
The gray curve is f(x)=1+sin x, and the area we want is below it between 0 and π. The exact value is precisely π+2≈5.1416, so we can truly measure the error. The gold bars are rectangles cutting the interval into n strips. Use the toggle above to choose where each bar's height is read: left end, right end, or midpoint. Raise the n slider and the bars thin out as the estimate approaches the truth. Left and right lean to one side, but the midpoint lets the over- and under-shoots cancel, so it is usually the most accurate.
Same integral, same true value π+2. This time, instead of leaving the bar top flat, we join the two endpoints with a straight line and fill each strip with a trapezoid. A rectangle leaves an empty triangle between curve and bar, but the trapezoid follows that slanted part with a line and greatly shrinks the gap. Move the n slider and confirm the error is smaller than in block 1 at the same n. The trapezoid error is proportional to h², so doubling n drops the error to about a quarter. Compared with the rectangle's halving, that is convergence a whole order faster.
The trapezoid approximated the curve with straight lines. What if we approximate a curve with a curve? Simpson's rule pairs the intervals two at a time and fits a parabola that passes exactly through those three points, capturing the very bending that straight lines miss. The dashed line is the true curve, and the gold lying almost on top of it is the parabolic fit. Step n through even values and watch the error number shrink by whole digits below the trapezoid. Simpson's error is proportional to h⁴, so doubling n drops the error to a striking one sixteenth. For the same strip count, the precision improves explosively.
Now one picture exposes the true nature of the three rules. The vertical axis is log10(error), the horizontal axis is the strip count n. Pick a rule and sweep n, and a falling error curve is drawn. The key is the slope of the fall: that is the accuracy order p, with an estimate shown in the readout. Rectangle descends gently (p≈1), trapezoid more steeply (p≈2), Simpson like a cliff (p≈4). The steeper the curve, the more a given rise in n carves away the error. Note that Simpson stops descending once it hits the floor of machine precision.
Finally we line up all three and compare them head to head under the same conditions. The three bars are the errors of midpoint, trapezoid, and Simpson using the same n, the very same amount of work. The vertical scale is logarithmic, so a bar's length is the number of digits of error. Move n: all three shorten, but the Simpson bar crushes the other two by far. The message is clear. For the same effort spent, which formula you choose splits the accuracy by orders of magnitude. The core lesson of numerical analysis is not to blindly crank up n but to choose a smarter rule.