cmlabs.interpolate.finite_differences

cmlabs.interpolate.finite_differences(yvals)[source]

Return the finite differences table.

\[\begin{split}\begin{gather} \Delta^k f(x_i) = \Delta^{k-1} f(x_{i+1}) - \Delta^{k-1} f(x_i), \\ \nabla^k f(x_i) = \nabla^{k-1} f(x_i) - \nabla^{k-1} f(x_{i-1}) \end{gather}\end{split}\]
Parameters:

yvals (array_like, 1-D) – The y-coordinates of the data points.

Returns:

res – The finite differences table.

Return type:

array_like, 2-D

Notes

The output is the table with following structure:

\[\begin{split}\left[\begin{gather} [\Delta^0 f(x_0) \quad \Delta^0 f(x_1) \quad \ldots \quad \Delta^0 f(x_n)] \\ [\Delta^1 f(x_0) \quad \Delta^1 f(x_1) \quad \ldots \quad \Delta^1 f(x_{n-1})]\\ [\Delta^2 f(x_0) \quad \Delta^2 f(x_1) \quad \ldots \quad \Delta^2 f(x_{n-2})]\\ \vdots \\ [\Delta^n f(x_0)] \end{gather}\right]\end{split}\]

Or it can be treated as…

\[\begin{split}\left[\begin{gather} [\nabla^0 f(x_0) \quad \nabla^0 f(x_1) \quad \ldots \quad \nabla^0 f(x_n)] \\ [\nabla^1 f(x_1) \quad \nabla^1 f(x_1) \quad \ldots \quad \nabla^1 f(x_n)]\\ [\nabla^2 f(x_2) \quad \nabla^2 f(x_1) \quad \ldots \quad \nabla^2 f(x_n)]\\ \vdots \\ [\nabla^n f(x_n)] \end{gather}\right]\end{split}\]

Or…

where \(n = len(yvals) - 1\).

Examples

>>> import numpy as np
>>> from cmlabs.interpolate import finite_differences
>>> yvals = np.array([1, 3, 2, 5])
>>> finite_differences(yvals)
>>> [[1, 3, 2, 5], [2, -1, 3], [-3, 4], [7]]