pysdic.numeric.compute_central_finite_difference_coefficients#
- compute_central_finite_difference_coefficients(order, spacing=1.0, accuracy=2)[source]#
Compute the coefficients of the central finite difference approximation of a derivative on a uniform sampling.
\[\frac{d^n f}{dt^n}(t) = \sum_{j=-M}^{M} c_j \, f(t + j h) + O(h^p), \qquad M = \left\lfloor \frac{n + p - 1}{2} \right\rfloor\]- Parameters:
order (Integral) – The order \(n \geq 1\) of the derivative.
spacing (Real, optional (default:
1.0)) – The sampling step \(h > 0\).accuracy (Integral, optional (default:
2)) – The order \(p\) of the error, a positive even integer.
- Returns:
The coefficients
[c_{-M}, ..., c_M]of shape \((2 M + 1,)\).- Return type:
Examples
compute_central_finite_difference_coefficients(1) # [-0.5, 0.0, 0.5] compute_central_finite_difference_coefficients(2, accuracy=4) # [-1/12, 4/3, -5/2, 4/3, -1/12]