∫Numerical Differentiation and Integration
Newton–Cotes and Composite Rules
Trapezoid and Simpson rules, degree of precision, composite rules and their error, total impulse
Linz, autumn 1613
Johannes Kepler, Imperial Mathematician and author of the laws of planetary motion, is getting married. He buys a supply of wine for the wedding, and the merchant comes to measure how much each barrel holds. He pushes a graduated rod through the bung hole at the top of the barrel diagonally down to the far edge of the bottom, reads off a number, and charges accordingly — whatever the barrel's actual shape.
Kepler is not satisfied. One diagonal cannot capture the volume of barrels that bulge differently. He sets out to find the volumes of solids of revolution, slicing them into thin discs and summing, and in 1615 publishes Nova stereometria doliorum vinariorum — a new solid geometry of wine barrels.
Among its results is a rule for a barrel's volume from three cross-sections — the two ends and the middle: . German textbooks still call it Keplersche Fassregel, Kepler's barrel rule. English ones call it Simpson's rule, after Thomas Simpson, who published it 128 years later.
To integrate over , replace it by its interpolating polynomial on equally spaced points (Unit 7) and integrate that exactly. These are the Newton–Cotes rules, after Newton and Roger Cotes, whose tables appeared in 1722. The first two:
The trapezoid rule (a straight line through two points) and Simpson's rule (a parabola through three). Kepler's barrel rule is Simpson's rule with the cross-sectional area as the integrand.
Derivation
Finding the weights, and Simpson's free extra degree
A rule of the form has three unknown weights. Ask it to be exact for , and — three equations:
The second gives , the third , and the first :
which, with , is Simpson's rule. (Two points and exactness for and give the trapezoid weights the same way.)
Degree 3 for free. For both sides are zero — the integral of an odd function over a symmetric interval, and the rule's . The first power it misses is : the rule gives , the integral .
The error constant from that miss. For a smooth the error is dominated by its part, . The rule overestimates by , so the error of one panel is
exactly the formula quoted below (a careful version replaces the constant by its value at some ).
💡Degree of precision
A rule has degree of precision if it integrates every polynomial of degree exactly. The trapezoid rule has . Simpson's rule, built from a parabola, should have — but by symmetry the error of the cubic term cancels too, and it has : on it gives exactly for and for , but instead of for . The error of one Simpson panel of width is .
High-degree Newton–Cotes rules on one panel suffer exactly Runge's problem (lesson 7-2): from nine points on, some weights become negative and errors in are amplified. The practical answer is composite rules: split into panels of width and apply a low-order rule on each.
Composite trapezoid and Simpson rules (n even for Simpson). Errors: −(b − a)h²f″/12 and −(b − a)h⁴f⁽⁴⁾/180. Doubling n divides the trapezoid error by 4 and Simpson's by 16.
Derivation
The composite error, from one panel to many
One trapezoid panel. The trapezoid rule integrates the straight line through the two ends. Lesson 7-1's error formula with two nodes says . Integrate over the panel of width :
The factor never changes sign on the panel, so the mean value theorem for integrals lets come out at a single point :
Many panels. The composite rule makes this error in each of its panels. Adding them, and replacing the sum of values of by times their average (itself a value of somewhere):
since . Each panel's error is , but there are of them: the total is — the same 'one order lost to accumulation' as Euler's method in lesson 9-1. Simpson's panels of width have error and there are of them: .
📐The orders, measured
For : with panels the trapezoid errors are , , , , — ratios 4.03, 4.01, 4.00, 4.00. Simpson: down to , ratios 16.9, 16.2, 16.06, 16.01. Watching the ratio settle at is the standard check that a quadrature code — or any discretisation — is implemented correctly.
Nature uses as little as possible of anything.
📐Total impulse from a static fire
Thrust sampled at 1 kHz for 3 s, with a little sensor noise. The trapezoid rule gives a total impulse of 6169.0 N s; Simpson gives the same to the reported precision. With 2.90 kg of propellant, the delivered specific impulse is s. The noise changes the impulse by only 0.32 N s: integration averages random errors, the opposite of differentiation. A logger recording only 20 samples per second would have reported 6143.8 N s — off by 0.4%, because the sharp ignition rise and burnout are under-resolved. For data, the grid is given, and the trapezoid rule is usually the honest choice.
⚠Kinks spoil the order
The error formulas assume (or ) exists across each panel. A thrust curve has a kink at burnout; a stress–strain curve at yield; a piecewise material property at its breakpoints. A panel straddling the kink drops the rule to first or second order. Place panel boundaries at known kinks, or split the integral there.
💡Where you will use this
Rocket Propulsion: total and specific impulse from test-stand data. Structures: section properties (area, centroid, second moment) of shapes defined by measured coordinates; work and energy from load–displacement curves. Hydraulics: discharge from velocity profiles measured across a river (the velocity–area method). Orbital Mechanics: averaging perturbations over an orbit.
📚Further reading
- Philip Davis and Philip Rabinowitz, Methods of Numerical Integration (2nd ed., Academic Press, 1984; Dover reprint 2007) — the encyclopedia of quadrature rules and their errors.
- Endre Süli and David Mayers, An Introduction to Numerical Analysis (Cambridge University Press, 2003), chapter 7, 'Numerical integration — I' — Newton–Cotes and composite rules with full error proofs.
- Michael Heath, Scientific Computing: An Introductory Survey (2nd ed.; SIAM Classics 2018), chapter 8, 'Numerical Integration and Differentiation'.
↓But there is a problem
Composite rules spend their points evenly. For a smooth integrand that is fine. For one with a sharp feature — a peak, a near-singularity, the square-root behaviour near a crack tip — most of the points land where the function is easy, and the error is set by the few that land where it is hard.
When you call
scipy.integrate.quad, it does not ask you for a grid. It hands the problem to a Fortran library written in the early 1980s by four numerical analysts in Belgium, Austria and the United States — QUADPACK — which decides by itself where to look.