cmlabs.interpolate.forward_differences
- cmlabs.interpolate.forward_differences(yvals)[source]
Return the forward differences list for \(f(x_0)\).
\[\begin{gather} \Delta^k f(x_i) = \Delta^{k-1} f(x_{i+1}) - \Delta^{k-1} f(x_i) \end{gather}\]- Parameters:
yvals (array_like, 1-D) – The y-coordinates of the data points.
- Returns:
res – The forward differences list.
- Return type:
array_like, 1-D
Notes
The output is the list with following structure:
\[[\Delta^0 f(x_0), \Delta^1 f(x_0), \Delta^2 f(x_0), \ldots, \Delta^n f(x_0)]\]where n = len(yvals) - 1.
The forward differences list is used to compute the coefficients of the Newton Forward-Difference Formula
Examples
>>> import numpy as np >>> from cmlabs.interpolate import forward_differences >>> yvals = np.array([1, 3, 2, 5]) >>> forward_differences(yvals) >>> [1, 2, -3, 7]