cmlabs.interpolate.bessel
- cmlabs.interpolate.bessel(xvals, x, yvals=None, coef=None, m=None)[source]
Bessel’s interpolation formula.
\[\begin{split}\begin{aligned} P_n(x_m + th) &= \frac{f(x_m) + f(x_{m+1})}{2} + \\ &+ (t - \frac{1}{2}) \Delta^1 f(x_m) + \\ &+ \frac{t(t-1)}{2!} \left[\frac{\Delta^2 f(x_{m-1}) + \Delta^2 f(x_m)}{2}\right] + \\ &+ \ldots + \\ &+ \frac{t(t^2-1)\ldots\left[t^2-(n-1)^2\right](t-n)}{(2n)!} \left[\frac{\Delta^{2n} f(x_0) + \Delta^{2n} f(x_1)}{2}\right] + \\ &+ \frac{t(t^2-1)\ldots\left[t^2-(n-1)^2\right](t-n) (t-\frac{1}{2})}{(2n+1)!} \Delta^{2n+1} f(x_0) \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 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
This central difference formula is acquiredafter taking the arithmetic mean of Gauss’s forward and backward interpolation formula with some modifications.
\[x = x_m + t h, \quad \frac{1}{4} < t < \frac{3}{4}\]Use often when the interpolating point lies near the middle of the table and the number of arguments in the problem is even.
Examples
>>> import numpy as np >>> from cmlabs.interpolate import bessel >>> xvals = np.array([0, 1, 2, 3]) >>> yvals = np.array([1, 3, 2, 5]) >>> x = np.float32(1.15) >>> bessel(xvals, x, yvals=yvals) >>> 2.8701875