pysdic.numeric.compute_finite_difference_coefficients#
- compute_finite_difference_coefficients(offsets, order)[source]#
Compute the finite difference coefficients of a derivative for any set of sampling points.
The coefficients \(c_j\) approximate the derivative of order \(n\) at a point \(t\) from the values at the points \(t + \delta_j\):
\[\frac{d^n f}{dt^n}(t) \approx \sum_{j} c_j \, f(t + \delta_j)\]They are exact for the polynomials of degree \(L - 1\) (\(L\) points), so the error is \(O(h^{L - n})\) with \(h\) the largest offset (one more order for a symmetric stencil). They are computed with the algorithm of Fornberg, stable for any distinct offsets.
- Parameters:
offsets (ArrayLike) – The distinct finite offsets \(\delta_j\) of the sampling points from the evaluation point, of shape \((L,)\) with \(L > n\), in time units.
order (Integral) – The order \(n \geq 1\) of the derivative.
- Returns:
The coefficients \(c_j\), of shape \((L,)\), in the order of
offsets(they include the spacing: no division by \(h^n\) is needed).- Return type:
- Raises:
ValueError – If the offsets are not distinct, or there are not more offsets than the order.
Examples
First derivative at \(t = 1\) from the samples at \(t = 0, 1, 3\):
from pysdic.numeric import compute_finite_difference_coefficients compute_finite_difference_coefficients([-1.0, 0.0, 2.0], 1) # array([-0.66666667, 0.5 , 0.16666667])