Fundamentals / Numerical mathematics / Approximation and quadrature

Divided differences and derivative data

Build an interpolating polynomial one measurement at a time and incorporate a measured slope at a repeated node.

From first principles

Append a node without changing earlier interpolation values

Suppose \(p_{k-1}\) already interpolates \(f\) at \(k\) distinct nodes \(x_0,\ldots,x_{k-1}\). A new polynomial can preserve all these values by adding a multiple of a product which vanishes at every old node. The new data at \(x_k\) then determine the only free coefficient,

\[p_k(x)=p_{k-1}(x)+a_k\prod_{j=0}^{k-1}(x-x_j),\]
\[a_k=\frac{f(x_k)-p_{k-1}(x_k)}{\prod_{j=0}^{k-1}(x_k-x_j)}.\]

This coefficient is the divided difference \(f[x_0,\ldots,x_k]\). For two nodes it is the ordinary secant slope. The higher coefficients can also be obtained by subtracting divided differences for overlapping node lists and dividing by the total interval width,

\[f[x_i,\ldots,x_j]=\frac{f[x_{i+1},\ldots,x_j]-f[x_i,\ldots,x_{j-1}]}{x_j-x_i}.\]

Each level has one more inverse power of the input unit than the preceding one. When nodes coincide, these formulas require limits; for example the first divided difference tends to \(f'(x_i)\) when the function is differentiable.

Derivation and applications

Convert a second divided difference into a curvature estimate

Three unequally spaced readings carry information about how fast a signal’s slope changes. Let the times be \(x_-=x_0-a,\ x_0,\ x_+=x_0+b\), with \(a,b>0\). Divide each consecutive value difference by its own interval before subtracting the two slopes. The second divided difference is that slope change divided by the full interval \(a+b\). Twice this value is the exact second derivative of the interpolating quadratic,

\[D_2=\frac{2}{a+b}\left[\frac{f(x_+)-f(x_0)}{b}-\frac{f(x_0)-f(x_-)}{a}\right].\]

To infer its error as an estimate of the true curvature at \(x_0\), expand the right and left secants about the central reading. Assuming four continuous derivatives locally, their leading terms are

\[s_+=f'+\frac b2 f''+\frac{b^2}{6}f'''+O(b^3),\]
\[s_-=f'-\frac a2 f''+\frac{a^2}{6}f'''+O(a^3).\]

Subtract and divide by half the full span. For \(h=\max(a,b)\) the result is

\[D_2=f''(x_0)+\frac{b-a}{3}f'''(x_0)+O(h^2).\]

The leading error changes sign if the sampling geometry is reflected through \(x_0\). A symmetric panel cancels it and produces a second-order estimate; an arbitrary asymmetric panel with both spacings scaled together generally gives first-order accuracy at the middle node. This geometric error can matter even if every reading is exact.

Worked example

Detect curvature bias from asymmetric time stamps

Take \(f(t)=t^3\) and times \(-1,0,2\). The left secant is 1 and the right secant is 4. The formula gives \(D_2=2(4-1)/3=2\), whereas \(f''(0)=0\). The predicted error is \((2-1)6/3=2\), exactly since the function is cubic. For the same data the estimator measures the exact curvature at \(t=1/3\).

Second application

Propagate bounded noise into an acceleration measurement

In a different experiment the times are \(-0.10,0,+0.10\,\mathrm s\), with independent unknown position errors bounded in magnitude by \(0.001\,\mathrm m\). The second-derivative weights are \(100,-200,100\,\mathrm{s^{-2}}\). Thus the worst noise error is

\[(100+200+100)(0.001)=0.400\,\mathrm{m/s^2}.\]

Doubling the spacing quarters this noise bound while increasing smooth-signal truncation error, a practical trade-off even on a symmetric grid.

OneSimulation laboratory

Measure what interpolation does to a heat integral

Start from this chapter. A quadratic has constant second divided difference. Use that coefficient to explain why the four- and eight-cell runs show a factor of four at midpoints.

Compare recorded OneSimulation runs on this page. To test your own inputs, download the Python model and run the model in an activated OneSimulation environment.

OneSimulation maps source samples to the original nodes and their midpoints. Integrating those segments gives the area under the interpolant. Keep the quadratic temperature law and double the number of source intervals. Then restore four intervals and replace the quadratic law with \(300+20x/L\). Download the Python experiment · OneSimulation point interpolation.

python approximation-and-quadrature.py
python approximation-and-quadrature.py --cells 8
python approximation-and-quadrature.py --law linear
Errors against the exact source function and its integral.
Profile, intervalsMax. midpoint error (K)Integral (K·m)Integral error (K·m)
Quadratic, 40.3125306.875+0.208333
Quadratic, 80.078125306.71875+0.0520833
Linear, 403100
For a quadratic field, doubling the sampling density cuts the integral bias by four. The linear field has zero interpolation bias at the coarser spacing.
For a quadratic field, doubling the sampling density cuts the integral bias by four. The linear field has zero interpolation bias at the coarser spacing.

Halving the spacing divides both quadratic-profile errors by four. The linear-profile result tests exactness on the function space represented by the interpolant.

Change parameters · Change the laboratory inputs

Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.

Problem sheet 2 · Recover an integral using two biased readings

Read the model setup and preparatory problems

Keep the previous fit

A new measurement arrives after a polynomial has been fitted to \(x_0,\ldots,x_{k-1}\). To preserve those measurements, add a multiple of \(\omega_k(x)=\prod_{j=0}^{k-1}(x-x_j)\). At each old node the correction vanishes. At a new distinct node \(x_k\) its coefficient is fixed by \(c_k=(f(x_k)-p_{k-1}(x_k))/\omega_k(x_k)\). This gives a triangular construction. Once a coefficient has been determined it remains in every subsequent polynomial provided the original order is retained.

The coefficients can also be obtained using a table. Put \(f[x_i]=f(x_i)\) and subtract adjacent entries of the previous order before dividing by the distance between the two outer nodes. The subtraction cancels shared lower-order information. Algebraically the leading coefficient of the polynomial through \(x_i,\ldots,x_{i+k}\) is

\[f[x_i,\ldots,x_{i+k}]=\frac{f[x_{i+1},\ldots,x_{i+k}]-f[x_i,\ldots,x_{i+k-1}]}{x_{i+k}-x_i}.\]

This follows by combining the two lower-degree interpolants with factors \(x-x_i\) and \(x-x_{i+k}\). Their difference divided by the outer spacing agrees with every tabulated value and has the required leading coefficient.

Three temperatures and a test point

Suppose a temperature sensor reports 2, 5 and 17 degrees at 0, 1 and 3 hours. First divided differences are 3 and 6 degrees per hour. The second difference is \((6-3)/3=1\) degree per hour squared. Hence \(p(x)=2+3x+x(x-1)\). At hour 2 this gives 10 degrees; the original straight line would give 8. The correction shows how strongly the additional observation changes that prediction. Neither interpolant by itself certifies that the temperature really did reach its predicted value between readings.

Nested evaluation uses \(2+x[3+(x-1)]\) here. Each new layer adds one multiplication and one addition. Reordering the nodes changes the intermediate table, but uniqueness ensures the same final polynomial in exact arithmetic. Strongly unequal spacings can magnify noise in higher differences and make numerical results sensitive to the order.

Let two nodes coalesce

If a second node approaches the first, the corresponding difference quotient tends to \(f'(x_0)\) for differentiable \(f\). An independently available derivative therefore supplies the diagonal entry directly. For a value 1 and slope 2 at zero and a value 4 at one, the required quadratic is \(1+2x+cx^2\); matching the final value gives \(c=1\). Its prediction at one half is 2.25. Perturb the initial slope by 0.1 while keeping endpoints fixed. The correction becomes \(0.1x(1-x)\), attaining 0.025 at the midpoint. Endpoint agreement alone would miss that uncertainty.

Rescale before comparing coefficients

The coefficients have different units at successive orders. In the temperature example, expressing time in minutes divides the first divided differences by 60 and the second difference by \(60^2\). Their smaller printed magnitudes do not mean the curvature has become less significant. Evaluating the second term at the same physical instant multiplies by two correspondingly larger node differences and recovers exactly the original contribution. Scaling the node interval near unit size can make intermediate arithmetic more convenient; interpret a coefficient together with the product of distances it multiplies.

Differentiate a local interpolant on an uneven grid

For samples at \(x_0-a,x_0,x_0+b\), where \(a,b>0\), the derivative of their quadratic interpolant gives a three-point estimate of \(f'(x_0)\). Write it as \(w_- f(x_0-a)+w_0 f(x_0)+w_+f(x_0+b)\). Reproducing the derivatives of a constant, the centred coordinate and its square gives three equations: the weights must sum to zero, \(-a w_-+b w_+=1\), and \(a^2w_-+b^2w_+=0\). Solving yields

\[w_-=-b/[a(a+b)],\ w_0=(b-a)/(ab),\ w_+=a/[b(a+b)].\]

These are the same weights one obtains by differentiating Newton's divided-difference polynomial at the central node.

A Taylor expansion exposes the leading cubic contribution. On \(f(x)=(x-x_0)^3\), the estimate is \(-a^3w_-+b^3w_+=ab\), although the exact derivative is zero. Thus the leading smooth-data bias is \(ab f'''(x_0)/6\), with higher-order terms controlled by higher derivatives and panel geometry. Moving the nearest observation closer can reduce this deterministic bias while greatly increasing the magnitude of the weights. The calculation reveals the same conflict between localisation and noise that occurs when derivatives are inferred from independently measured values.

Estimate a heating rate from unsymmetrical sampling times

Choose \(x_0=0\), \(a=1\) minute and \(b=2\) minutes. The weights are \(-2/3,\ 1/2,\ 1/6\) per minute. Let the exact temperature over this short interval be \(T(t)=10+3t+t^3/10\) degrees. The sampled readings are

\[T(-1)=6.9,\ T(0)=10,\ T(2)=16.8.\]

Applying the formula gives \(-4.6+5+2.8=3.2\) degrees per minute. The analytical derivative at zero is three. Its 0.2 bias equals \(ab T'''/6=(1)(2)(0.6)/6\), exactly because the temperature has no higher powers.

If each sample has independent standard deviation 0.12 degrees, the rate standard deviation is \(0.12\sqrt{4/9+1/4+1/36}=0.12\sqrt{26}/6\approx0.102\) degrees per minute. Halving both spacings reduces the cubic bias by four to 0.05, but doubles every derivative weight, increasing standard deviation to approximately 0.204. For the original grid, combining bias squared and variance gives mean squared error about 0.0504; for the refined grid it is about 0.0441. A further halving would make random error dominate still more strongly.

The weights sum to zero, so a truly common temperature offset cancels, while time-dependent drift need not. Also, using a symmetric central-difference formula on these asymmetric sample times would estimate a slope centred elsewhere and introduce a contribution from any quadratic term. Keeping the acquisition times in the coefficient equations is essential when observations are irregular because of missed triggers or variable sampling intervals.

A further check compares sampling the same temperatures with a fit that assumes the instrument clock is correct only to a tenth of a minute. At the central point the true local slope is three degrees per minute, so a timing error of 0.1 minute can by itself move a value by approximately 0.3 degrees. This is larger than the assumed independent temperature standard deviation. Errors in the sample locations would enter the divided differences through both numerator and denominator, and the simple fixed-time variance calculation would no longer describe the experiment.

Change parameters · Divided differences and derivative data

Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.

Study the full derivation

Approximating a resonance with a rational function · Function approximation and numerical integration

A smooth response on a measured interval can be governed by a nearby pole. Derive a low-order Padé fit, construct a barycentric rational approximant from samples and check whether a predicted pole survives independent data.