cmlabs.interpolate.gaussfd
- cmlabs.interpolate.gaussfd(xvals, x, yvals=None, coef=None, m=None)[source]
Gauss’s forward interpolation formula.
\[\begin{split}\begin{aligned} P_n(x_m + th) &= \Delta^0 f(x_m) + \\ &+ \frac{t}{1!} \Delta^1 f(x_m) + \\ &+ \frac{t(t-1)}{2!} \Delta^2 f(x_{m-1}) + \\ &+ \frac{(t+1)t(t-1)}{3!} \Delta^3 f(x_{m-1}) + \\ &+ \frac{(t+1)t(t-1)(t-2)}{4!} \Delta^4 f(x_{m-2}) + \\ &+ \frac{(t+2)(t+1)t(t-1)(t-2)}{5!} \Delta^5 f(x_{m-2}) + \\ &+ \frac{(t+2)(t+1)t(t-1)(t-2)(t-3)}{6!} \Delta^6 f(x_{m-3}) + \ldots \end{aligned}\end{split}\]where \(x_m\) is the midpoint of the data point (\(m = n // 2\)) and \(t = \frac{x-x_m}{h}\).
- 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 forward 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
Gauss’s forward interpolation formula is best applicable for determining the values near the middle of the table.
\[x = x_m + t h, \quad 0 < t < \frac{1}{2}\]Examples
>>> import numpy as np >>> from cmlabs.interpolate import gaussfd >>> xvals = np.array([0, 1, 2, 3]) >>> yvals = np.array([1, 3, 2, 5]) >>> x = np.float32(1.25) >>> gaussfd(xvals, x, yvals=yvals) 2.7578125