∫Numerical Differentiation and Integration
Finite Differences and Richardson Extrapolation
Difference formulas from Taylor series, the step-size trade-off, noisy data, Richardson extrapolation, complex step
A static fire, one sample per millisecond
A solid rocket motor is bolted horizontally to a test stand. When it fires, a load cell records thrust and a transducer records chamber pressure, a thousand times a second, for three seconds.
The engineers want more than the curves. The burning rate of the propellant depends on how fast pressure rises; ignition transients are judged by ; nozzle erosion shows up as a slow drift in the ratio of thrust to pressure. All of these are derivatives — of numbers sampled every millisecond, each carrying a little electrical noise.
The first attempt is always the same: subtract consecutive samples and divide by the time step. On a pressure signal with noise of 0.2% of full scale, the result is a derivative whose noise is ten times larger than the derivative itself. Nothing was programmed wrongly. Differentiation of data is simply one of the most ill-conditioned operations in this course.
Every difference formula comes from Taylor's theorem (lesson 1-3). Expanding about :
Subtracting cancels the even terms. Combining more points cancels more terms:
Forward, central and fourth-order central differences (fₖ = f(x + kh)). Second derivative: (f(x+h) − 2f(x) + f(x−h))/h² = f″ + O(h²) — the stencil of every heat and beam equation in Units 3 and 4.
💡The step-size trade-off
Truncation error shrinks as , but is a difference of nearly equal numbers, and each carries a rounding error of about . Divided by , that becomes — growing as shrinks. For the forward difference the total error is about , smallest at with about 8 correct digits. Central differences do better: and about 11 digits; the fourth-order formula, and about 13. No finite-difference formula reaches full precision, and pushing smaller makes things worse.
Noisy data is the same problem, worse. Measurement noise plays the role of , and it is millions of times larger. A central difference turns noise into a derivative error of about : with MPa and ms, about 10 MPa/s — while the true during the burn is under 1 MPa/s. The cure is to smooth while differentiating: fit a low-degree polynomial to a window of samples by least squares (Unit 5) and differentiate the fit. That is the Savitzky–Golay filter (1964); with a 51-sample cubic window the derivative error drops thirtyfold, to 0.33 MPa/s. Wider windows remove more noise but blur fast events — the step-size trade-off again, now with instead of .
Derivation
How much a difference amplifies noise
Let each sample carry an independent random error of standard deviation : . The central difference adds the error
Variances of independent errors add (lesson 1-2's random walk), and a minus sign does not change a variance, so has variance and standard deviation . Dividing by :
With MPa and s that is MPa/s. Halving the step doubles it — the opposite of what truncation error wants.
💡Richardson extrapolation
If an approximation has error , compute it twice:
The terms cancel without our ever knowing . Lewis Fry Richardson called it 'the deferred approach to the limit' (1911, 1927). For Squire and Trapp's test function at , central differences with are off by ; one Richardson step brings that to . The same idea powers Romberg integration (lesson 8-3) and error estimation in ODE solvers (Unit 9).
Derivation
Richardson's combination, and the fourth-order stencil it produces
The central difference has an error expansion with only even powers (lesson 1-3 showed the odd terms cancel):
Multiply the second by 4 and subtract the first: the terms cancel, and remains, so
Nothing about was needed except that the error goes like . In general, for an error , the combination is ; for a first-order error () it is , the extrapolation used for seepage in lesson 4-4.
The fourth-order formula. Apply the same combination to central differences with steps and , written out with :
That is the five-point stencil above: every higher-order difference formula is a Richardson extrapolation of a lower-order one.
They are neither finite Quantities nor Quantities infinitely small, nor yet nothing. May we not call them the Ghosts of departed Quantities?
🕰The complex-step trick
For an analytic function implemented with complex arithmetic, Taylor's theorem in the imaginary direction gives , so
with error and no subtraction at all. There is nothing to cancel, so can be or and the derivative is correct to machine precision. James Lyness and Cleve Moler described it in 1967; William Squire and George Trapp popularised it in 1998, and it became a standard tool for computing sensitivities in aerospace design codes.
💡Where you will use this
Rocket Propulsion: burn rates and ignition transients from test data — always smoothed. Structures: strains from displacement measurements (digital image correlation, extensometers). Optimal Guidance and Control: finite-difference and complex-step Jacobians for Newton and gradient methods (Units 2 and 11). Every PDE course: the difference stencils of this lesson are the finite-difference method.
📚Further reading
- Bengt Fornberg, 'Generation of finite difference formulas on arbitrarily spaced grids', Mathematics of Computation 51(184), 699–706 (1988) — a short algorithm that produces every stencil in this lesson, and more.
- Abraham Savitzky and Marcel Golay, 'Smoothing and differentiation of data by simplified least squares procedures', Analytical Chemistry 36(8), 1627–1639 (1964).
- Joaquim Martins, Peter Sturdza and Juan Alonso, 'The complex-step derivative approximation', ACM Transactions on Mathematical Software 29(3), 245–262 (2003) — the complex step in engineering design codes.
↓But there is a problem
Differentiation divides small differences by small numbers and amplifies every error. Its inverse does the opposite: integration adds many small contributions, and random errors partly cancel. The total impulse from the same noisy thrust record is accurate to a few hundredths of a percent.
The oldest integration rule still in daily use was written down because of a wedding. In 1613 Johannes Kepler, astronomer to the Emperor, bought barrels of wine for his marriage in Linz — and did not like the way the merchant measured how much was in them.