cmlabs.interpolate.backward_differences

cmlabs.interpolate.backward_differences(yvals)[source]

Return the backward differences list for \(f(x_n)\).

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

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

Returns:

res – The backward differences list.

Return type:

array_like, 1-D

Notes

The output is the list with following structure:

\[[\nabla^0 f_n, \nabla^1 f_n, \nabla^2 f_n, \ldots, \nabla^n f_n]\]

where n = len(yvals) - 1.

The backward differences list is used to compute the coefficients of the Newton Backward-Difference Formula

Examples

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