cmlabs.interpolate.stirling
- cmlabs.interpolate.stirling(xvals, x, yvals=None, coef=None, m=None)[source]
Stirling’s interpolation formula.
\[\begin{split}\begin{aligned} P_n(x_m + th) &= \Delta^0 f(x_m) + \\ &+ \frac{t}{1!} \left[\frac{\Delta^1 f(x_{m-1}) + \Delta^1 f(x_m)}{2}\right] + \\ &+ \frac{t^2}{2!} \Delta^2 f(x_{m-1}) + \\ &+ \frac{t(t^2-1)}{3!} \left[\frac{\Delta^3 f(x_{m-2}) + \Delta^3 f(x_{m-1})}{2}\right] + \\ &+ \frac{t^2(t^2-1)}{4!} \Delta^4 f(x_{m-2}) + \\ &+ \frac{t(t^2-1)(t^2-2^2)}{5!} \left[\frac{\Delta^5 f(x_{m-3}) + \Delta^5 f(x_{m-2})}{2}\right] + \\ &+ \frac{t^2(t^2-1)(t^2-2^2)}{6!} \Delta^6 f(x_{m-3}) + \\ &+ \ldots + \\ &+ \frac{t(t^2-1)(t^2-2^2)(t^2-3^2)\ldots\left[t^2-(n-1)^2\right]}{(2n-1)!} \left[\frac{\Delta^{2n-1} f(x_0) + \Delta^{2n-1} f(x_1)}{2}\right] + \\ &+ \frac{t^2(t^2-1)(t^2-2^2)\ldots\left[t^2-(n-1)^2\right]}{(2n)!} \Delta^{2n} f(x_0) \end{aligned}\end{split}\]where \(t = x - x_0\) and \(n = len(xvals) - 1\).
- Parameters:
xvals (array_like, 1-D) – The sorted x-coordinates of the data points.
x (float) – The x-coordinate at which to evaluate the polynomial.
yvals (array_like, 1-D, optional, default: None) – The y-coordinates of the data points, i.e., \(f(x)\).
coef (array_like, 2-D, optional, default: None) – The backward differences table. If not provided, the function will compute the finite differences table using the finite_differences(yvals) function.
m (int, optional, default: None) – The index of the midpoint of the data points.
- Returns:
res – The value of the polynomial at \(x\).
- Return type:
float
See also
Notes
After taking the arithmetic mean of Gauss forward and backward interpolation we will obtain Stirling’s Interpolation formula. This formula is used for an odd number of equally spaced values.
\[x = x_m + t h, \quad -\frac{1}{4} < t < \frac{1}{4}\]Examples
>>> import numpy as np >>> from cmlabs.interpolate import stirling >>> xvals = np.array([0, 1, 2, 3, 4]) >>> yvals = np.array([1, 3, 2, 5, 3]) >>> x = np.float32(2.15) >>> stirling(xvals, x, yvals=yvals) >>> 2.2488649999999994