seegongsik
engineering mathematics

numerical integration quadrature

Rectangles, trapezoids and Simpson measure the area under a curve; more strips means more accuracy

A definite integral is the area under a curve. Many functions have no antiderivative you can write by hand. Sometimes, as with experimental data, you have only points and no formula at all. The idea is simple. Cut the interval [a,b] into thin vertical pieces and estimate each piece with an easy shape, then add them. Rectangles are rough, trapezoids with a slanted top are better, and pairing two panels into a parabola is much more accurate. The finer the pieces, that is the larger n, the closer you get to the true value, and the speed of that approach depends on the rule. Take one integral whose answer is known, f=1+sin x, with value π+2, and the pictures compare how different the three rules are for the same effort. The gold bars are those pieces and the gray curve is the function being integrated. The error printed under each picture is the true value minus the estimate, and the whole lesson is a comparison of the three rules at the same number of pieces.

The gray curve is f(x)=1+sin x, and the area we want sits under it on [0,π]. The true value is exactly π+2≈5.1416, so the error can be measured for real. The gold bars are the rectangles that cut the interval into n pieces. The buttons above choose whether the bar height is the left end, the right end, or the midpoint. Raise the n slider and the bars get thinner and the estimate moves toward the true value. The left and right ends lean to one side, while the midpoint cancels errors above and below and is usually the most accurate.

The same integral, and the same true value π+2. This time the top of each bar is not flat. The two endpoints are joined by a straight line, and the piece is a trapezoid. A rectangle leaves an empty triangle between the curve and the bar, while a trapezoid follows that slope with a line and shrinks the gap. Move the n slider and, at the same n, the error is smaller than the order-1 estimate of the previous picture. The trapezoid error is proportional to h², so doubling n drops the error to about 1/4. Compared with a rectangle, which drops it to 1/2, that is a faster order of convergence.

A trapezoid estimated the curve with a straight line. What if the curve is estimated with a curve? Simpson's rule bundles the interval two panels at a time and fits a parabola through those three points. It catches the bend that a line misses. The dotted line is the true curve, and the gold lying almost on top of it is the parabola. Move n through even values and the error is smaller than the trapezoid's by whole digits. Simpson's error is proportional to h⁴, so doubling n drops the error to 1/16. The same number of pieces buys a large gain in precision.

One picture shows what the three rules really are. The vertical axis is log10 of the error, and the horizontal axis is the number of pieces n. Pick a rule and sweep n, and a curve of the falling error is drawn. The slope of that fall is the order of accuracy p, and the readout shows the estimate. Rectangles fall gently (p≈1), trapezoids fall more steeply (p≈2), and Simpson falls like a cliff (p≈4). The steeper the curve, the more the same increase in n cuts the error. Once Simpson reaches the smallest number the machine can tell apart, it stops falling.

Last, the three stand side by side under the same conditions. The three bars are the errors of the midpoint rule, the trapezoid, and Simpson at the same n, that is the same amount of work. The vertical scale is logarithmic, so the length of a bar is the number of digits in the error. Move n and all three shorten, but Simpson's bar presses the other two down. The same effort, and the choice of formula splits the accuracy by digits. What matters is not raising n without thought. It is choosing a better rule. Setting the three rules side by side at one n is the comparison this lesson is built to make.

In PracticeNumerical integration, quadrature, estimates the area under a curve by cutting [a,b] into pieces. Rectangles are rough, with error proportional to h, order 1. Trapezoids join the top with a straight line, order 2. Simpson fits a parabola to each pair of panels, order 4. Raising the number of pieces n shrinks the error, and the speed of that shrink is set by the order of the rule. The slope of a graph of log of the error against n is the order. So at the same amount of work, the same n, Simpson leads the other rules by digits. The point is to choose a smarter rule rather than to add pieces without thought. As Taylor spreads a function into a polynomial, quadrature integrates those polynomial pieces exactly.
← engineering mathematics
Was this helpful? Support seegongsik