Fundamentals / Numerical mathematics / Approximation and quadrature

Piecewise interpolation and error bounds

Construct a continuous profile from sensor values, prove a local interpolation bound and distinguish sampling error from measurement uncertainty.

From first principles

Build a line from two measured endpoints

Suppose values \(y_0,y_1\) are known at \(x_0<x_1\) and no slopes are available. The simplest model reproducing both data is a line of constant slope. Let \(t\) denote the fraction of the panel traversed at the query point \(x\). Starting with the slope of the chord, rewrite the same line in terms of its endpoint weights:

\[\begin{aligned} t &= \frac{x-x_0}{x_1-x_0},\\[3pt] I(x) &= y_0+(x-x_0)\frac{y_1-y_0}{x_1-x_0}\\ &= (1-t)y_0+t y_1. \end{aligned}\]

Its weights are nonnegative on the panel and add to one, so constants and endpoint values are reproduced exactly. When the data come from a twice differentiable function with \(|f''|\le M\), curvature controls departure from the line. The two-node remainder gives

\[|f(x)-I(x)|\le\frac{M}{2}(x-x_0)(x_1-x)\le\frac{M(x_1-x_0)^2}{8}.\]

The last bound occurs at the midpoint. Halving panel width reduces this deterministic bound by a factor of four. Measurement errors in the endpoint values still enter through the interpolation weights and must be budgeted separately.

Derivation and applications

Balance curvature bias against uncertainty in interpolated readings

Consider a panel of length \(h=b-a\), with unknown smooth signal \(f\) and two independent noisy observations \(y_a=f(a)+\epsilon_a,\ y_b=f(b)+\epsilon_b\). Assume each error has zero mean and a known variance, and that \(|f''|\le M\) throughout the panel. For \(t=(x-a)/h\), linear interpolation gives the estimator \(\widehat f=(1-t)y_a+ty_b\). Its expectation follows simply by taking the expected value of each measured endpoint,

\[\operatorname{E}[\widehat f]-f(x)=(1-t)f(a)+tf(b)-f(x),\qquad |\operatorname{bias}|\le\tfrac12 M h^2t(1-t).\]

Independence eliminates the mixed error term when the noise contribution is squared. Consequently the noise variance depends on the interpolation location even on a flat signal,

\[\operatorname{var}(\widehat f)=(1-t)^2s_a^2+t^2s_b^2 .\]

Expanding the mean squared error about the estimator’s own expectation yields a sum of variance and squared bias. For equal endpoint standard deviations \(s\), the midpoint therefore satisfies

\[\operatorname{E}[(\widehat f-f)^2]\le \frac{s^2}{2}+\left(\frac{Mh^2}{8}\right)^2 .\]

Grid refinement changes the second term, whereas independent repeat measurements at each endpoint reduce the first. Common-mode drift adds a covariance contribution that survives averaging between the two endpoints. In particular, an identical unknown offset passes unchanged through the interpolation because the weights sum to one.

Worked example

Determine which uncertainty dominates a midpoint

At two stations \(0.40\,\mathrm m\) apart the reading errors have \(s=0.030\,\mathrm K\), while \(M=0.50\,\mathrm{K/m^2}\). The maximum midpoint bias is \(0.010\,\mathrm K\) and the noise deviation is \(0.0212\,\mathrm K\). Their root-mean-square budget is

\[\sqrt{0.030^2/2+0.010^2}=0.0235\,\mathrm K.\]

It is already dominated by reading noise.

Second application

Select a spacing from a root-mean-square target

For another instrument let \(s=0.020\), \(M=2.00\), and target midpoint root-mean-square error \(0.030\), in consistent units. The permitted bias magnitude is

\[\sqrt{0.030^2-0.020^2/2}=0.0265.\]

Thus

\[h\le\sqrt{8(0.0265)/2.00}=0.325.\]

If the noise were doubled at fixed error target, the remaining squared bias allowance would shrink to \(0.0001\).

OneSimulation laboratory

Measure what interpolation does to a heat integral

Start from this chapter. For a convex quadratic, the chord lies above the curve. Predict the sign and size change of the midpoint error when each source interval is halved.

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

Reconstruct from the information available

A line of thermometers supplies values \(y_i\) at increasing coordinates \(x_i\). It does not determine a unique continuous function: any function vanishing at every sensor can be added to a candidate profile. Choosing piecewise straight segments asserts that the unresolved curvature between consecutive readings is small enough for the intended measurement. This assumption may be excellent for predicting a mean temperature and poor for estimating a local heat flux, since differentiation increases the influence of measurement noise.

For \(x\in[x_i,x_{i+1}]\), let \(s=(x-x_i)/h_i\), where \(h_i=x_{i+1}-x_i>0\). The unique affine function matching both readings is \(I_hy=(1-s)y_i+sy_{i+1}\). It follows by writing an unknown intercept and slope, imposing the two endpoint values and eliminating both unknown coefficients. The weights are nonnegative and sum to one. The interpolated value lies between adjacent readings, constants are reproduced, and bounded additive errors of size \(\epsilon\) at the two sensors change the interpolant by at most \(\epsilon\). These properties can fail when extrapolating a considerable distance outside the measured interval.

Why the error is quadratic

Suppose \(f\) is twice continuously differentiable on a panel. Fix an interior point \(t\), and choose a coefficient \(c\) so that \(g(x)=f(x)-I_h f(x)-c(x-x_i)(x-x_{i+1})\) also vanishes at \(t\). It already vanishes at both panel endpoints. Rolle’s theorem applied twice gives a point \(\xi\) where \(g''(\xi)=0\). The interpolant has zero second derivative there, so \(c=f''(\xi)/2\). Evaluate the identity at \(t\) to obtain

\[f(t)-I_h f(t)=\frac{f''(\xi)}{2}(t-x_i)(t-x_{i+1}).\]

The product is nonpositive within the interval and has greatest magnitude \(h_i^2/4\) at its midpoint. Thus the uniform error is at most \(h_i^2\max|f''|/8\). If every panel width is halved, an upper bound based on the same curvature falls by four. When curvature is positive, the segment overestimates the function. Knowledge of the curvature sign supplies information that an absolute error bound would discard.

Background · Can refining noisy samples make interpolation less useful?

Take the midpoint of two independent sensor readings with the same random error variance \(\sigma^2\). The midpoint interpolant averages those readings. Its variance is \(\sigma^2/2\), regardless of how close together the sensors stand. Meanwhile the size of the curvature bias is approximately \(|f''|h^2/8\). For a twice differentiable field with nearly constant curvature and unbiased readings, the midpoint mean squared error is approximately

\[\mathbb E[(\hat f-f)^2]\simeq\frac{(f'' h^2)^2}{64}+\frac{\sigma^2}{2}.\]

Refining the sampling interval reduces the first term but leaves the second term. Once the two terms are comparable, repeat readings or a calibrated smoothing fit can improve a value estimate more efficiently. If both readings share the same offset, taking their average preserves that offset in full.

Turn the bound into a sampling decision

On the unit interval consider a temperature \(T=290+8x^2\) K, with \(x\) given numerically in metres. On the first panel of length 0.25 m the endpoint readings are 290 and 290.5 K. Their average is 290.25 K. The actual midpoint is 290.125 K, an overestimate of 0.125 K. The bound \(16(0.25)^2/8=0.125\) K is attained because the curvature is constant. A second panel of the same width has the same maximum interpolation error even though its temperature change is different.

Now allow an uncertainty of 0.03 K at every source node. A conservative total bound is \(2h^2+0.03\) K for \(h\) in metres. Achieving 0.05 K requires \(h\leq0.10\) m, or at least 11 measurements including both ends. No amount of interpolation onto a denser display grid changes this source requirement. For the slope, two readings with opposite errors can change the estimated derivative by \(2\epsilon/h\), which grows when \(h\) shrinks. Choosing sensor spacing therefore depends on the quantity to be estimated. A spacing suitable for accurate point values may require additional smoothing before slopes inferred from noisy data are useful.

Interpret a finite sensor footprint

Sometimes the observation is already a mean over a finite sensor footprint. For a symmetric footprint of width \(w\) centred at \(x\), the mean of a smooth field is \(f(x)+f''(x)w^2/24+O(w^4)\), by Taylor expansion and symmetry. For the quadratic temperature above this correction is exactly \(16w^2/24\) K when \(w\) is measured in metres. With a 0.10 m footprint it is about 0.0067 K above the point value. Interpreting a cell mean as a point reading therefore adds another positive bias before the chord interpolation even begins. This distinction becomes important when comparing a temperature probe with simulation values stored as cell averages.

Distribute measurements according to the curvature they must resolve

An equally spaced grid spends the same sampling budget in every part of a record. Suppose instead that the trajectory is twice continuously differentiable on each of several known regions, with a certified bound \(M_i\) for \(|f''|\) on region \(i\). Over a panel of width \(h_i\) the largest linear interpolation error is at most \(M_i h_i^2/8\). Thus keeping every local bound below a specified tolerance \(\epsilon\) requires \(h_i\le\sqrt{8\epsilon/M_i}\) whenever \(M_i>0\). A region with four times the curvature bound needs twice as many panels per unit length.

For a fixed total number of panels the reverse question is also helpful. In a region of length \(L_i\) with \(n_i\) equal panels its bound is \(M_iL_i^2/(8n_i^2)\). To minimise the largest such bound over positive continuous allocations, equalise those dominant local bounds. Otherwise moving some resolution from a region with a smaller bound to the largest can improve the maximum. The resulting allocation satisfies

\[n_i\propto L_i\sqrt{M_i}.\]

Counts must then be rounded and their actual bounds checked. Known transitions in curvature should occur at grid nodes if each local bound is to apply to its entire panel.

Place nine panels across a changing acceleration

A displacement history lasts three seconds. In the first two seconds its acceleration magnitude is bounded by 2 m/s², and in the last second by 18 m/s². The relative panel allocations are

\[2\sqrt2:\sqrt{18}=2:3.\]

Nine panels cannot achieve exactly that ratio. Try four panels in the first interval and five in the second. Their widths are 0.5 and 0.2 s, giving error bounds \(2(0.5)^2/8=0.0625\) m and \(18(0.2)^2/8=0.0900\) m. Moving one panel to the late region instead gives bounds \(2(2/3)^2/8=0.1111\) m and \(18(1/6)^2/8=0.0625\) m. The four–five allocation has the smaller worst guarantee.

Nine equally spaced panels have width one third second throughout and include the transition at two seconds. Their late bound is 0.25 m, almost three times the nonuniform worst bound. This comparison is about a guaranteed maximum between observations, not only a discrepancy at selected test locations. Piecewise quadratic motions with constant accelerations attain the midpoint bound on each panel; slopes and positions can be matched at the transition without altering either local error.

The reasoning assumes acceleration bounds independent of the sampled readings. Estimating them from those same coarse readings can miss a short acceleration pulse entirely. If endpoint measurements also contain error bounded by 0.03 m, the convex interpolation weights add at most 0.03 m to each panel bound. The chosen allocation then certifies 0.12 m. Refining the grid further can reduce curvature error but cannot eliminate the measurement floor without better data.

If the allowable total error were 0.10 m, leaving 0.03 m for sensor uncertainty would allow at most 0.07 m for curvature. Four early panels already meet that condition. The late section would require at least six panels because \(18/(8\cdot6^2)=0.0625\), giving a ten-panel acquisition plan.

Where does a trustworthy interpolant cease to be accurate?

Interpolate the same smooth function on one interval with two and then three nodes. For the line the error changes with curvature, while for the quadratic the node product changes sign at the middle point. Inspect the signed error between observations.

Where does a trustworthy interpolant cease to be accurate?. Horizontal axis: Position in [0, 1]. Vertical axis: Approximation minus exp(x). Data follow the figure.
The line lies above the convex exponential between its endpoints. Adding a midpoint makes the quadratic exact there but creates error lobes of opposite sign in the two halves. Agreement at the nodes alone tells nothing about the interpolant between them.
Read values from the plot
Approximation minus exp(x) at selected values of Position in [0, 1].
Position in [0, 1]Linear through endpointsQuadratic through 0, 0.5, 1
004.4409e−16
0.250.14555−0.01227
0.50.210420
0.750.171710.013897
14.4409e−164.4409e−16

Download all 301 plotted samples (CSV)

Change parameters · Where does a trustworthy interpolant cease to be accurate?

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.