pysindy.differentiation.FiniteDifference
- class pysindy.differentiation.FiniteDifference(order: int = 2, d: int = 1, axis: int = 0, is_uniform: bool = False, drop_endpoints: bool = False, periodic: bool = False)[source]
Finite difference derivatives.
Only centered differences are implemented, for even order and left-off-centered differences for odd order. See wikipedia for the coefficient formula used.
- Parameters:
order (int, optional (default 2)) – The accuracy big-O exponent of the finite difference method to be used.
d (int, optional (default 1)) – The order of derivative to take. Must be positive integer.
axis (int, optional (default 0)) – The axis to differentiate along.
is_uniform (boolean, optional (default False)) – Parameter to tell the differentiation that, although a N-dim grid is passed, it is uniform so can use dx instead of the full grid array.
drop_endpoints (boolean, optional (default False)) – Whether or not derivatives are computed for endpoints. If False, endpoints will be set to np.nan. Note that which points are endpoints depends on the method being used.
periodic (boolean, optional (default False)) – Whether to use periodic boundary conditions for endpoints. Use forward differences for periodic=False and periodic boundaries with centered differences for periodic=True on the boundaries. No effect if drop_endpoints=True
Attributes – n_stencil: the number of coefficients in the finite difference expression.
Examples
>>> import numpy as np >>> from pysindy.differentiation import FiniteDifference >>> t = np.linspace(0, 1, 5) >>> X = np.vstack((np.sin(t), np.cos(t))).T >>> fd = FiniteDifference() >>> fd._differentiate(X, t) array([[ 1.00114596, 0.00370551], [ 0.95885108, -0.24483488], [ 0.8684696 , -0.47444711], [ 0.72409089, -0.67456051], [ 0.53780339, -0.84443737]])
Methods