Skip to main content

Module interp

Module interp 

Source
Expand description

One-dimensional lookup tables with an explicit extrapolation policy.

A Table1D holds knots (x_i, y_i) with strictly increasing x_i and interpolates between them either piecewise linearly or with a natural cubic spline. Outside [x_0, x_{n-1}] it follows its Extrapolation policy, and every Table1D::lookup reports whether it extrapolated, so callers can warn instead of silently trusting a clamped value.

Natural cubic spline. Each interval is a cubic Hermite polynomial in the knot values y_i and knot slopes s_i. The slopes solve the tridiagonal system that makes the second derivative continuous at the interior knots (the slope form of cubic spline interpolation; see C. de Boor, A Practical Guide to Splines, rev. ed., Springer, 2001, ch. IV):

h_i s_{i-1} + 2 (h_{i-1} + h_i) s_i + h_{i-1} s_{i+1} = 3 (h_i δ_{i-1} + h_{i-1} δ_i),  0 < i < n-1

with h_i = x_{i+1} - x_i and δ_i = (y_{i+1} - y_i) / h_i, closed by the natural (“free end”) conditions y''(x_0) = y''(x_{n-1}) = 0:

2 s_0 + s_1 = 3 δ_0,        s_{n-2} + 2 s_{n-1} = 3 δ_{n-2}

The system is strictly diagonally dominant, so the Thomas algorithm solves it stably without pivoting. docs/physics/interpolation.md has the derivation and the tests that pin it.

Structs§

Lookup
The result of a table lookup.
Table1D
A one-dimensional lookup table y(x).

Enums§

Extrapolation
What a lookup outside [x_0, x_{n-1}] does.
Interpolation
How a table fills in between its knots.
Side
Which end of a table a lookup fell beyond.