finite_difference
This module implements some common finite difference schemes. This is handy for this module https://web.media.mit.edu/~crtaylor/calculator.html
- pynumdiff.finite_difference.finitediff(x, dt, num_iterations=1, order=2, axis=0)
Perform iterated finite difference of a given order. This serves as the common backing function for all other methods in this module.
- Parameters:
x (np.array[float]) – data to differentiate. May be multidimensional; see
axis.dt (float) – step size
num_iterations (int) – number of iterations. If >1, the derivative is integrated with trapezoidal rule, that result is finite-differenced again, and the cycle is repeated num_iterations-1 times
order (int) – 1, 2, or 4, controls which finite differencing scheme to employ
axis (int) – data dimension along which differentiation is performed
- Returns:
x_hat (np.array) – original x if
num_iterations=1, else smoothed x that yielded dxdt_hatdxdt_hat (np.array) – estimated derivative of x
- pynumdiff.finite_difference.first_order(x, dt, params=None, options={}, num_iterations=1)
First-order difference method
Deprecated, prefer
finitediffwith order 1 instead.- Parameters:
x (np.array[float]) – data to differentiate
dt (float) – step size
params (list[float] or float) – (deprecated, prefer
num_iterations)options (dict) – (deprecated, prefer
num_iterations) a dictionary consisting of {‘iterate’: (bool)}num_iterations (int) – number of iterations. If >1, the derivative is integrated with trapezoidal rule, that result is finite-differenced again, and the cycle is repeated num_iterations-1 times
- Returns:
x_hat (np.array) – original x if
num_iterations=1, else smoothed x that yielded dxdt_hatdxdt_hat (np.array) – estimated derivative of x
- pynumdiff.finite_difference.second_order(x, dt, num_iterations=1)
Second-order centered difference method, with special endpoint formulas.
Deprecated, prefer
finitediffwith order 2 instead.- Parameters:
x (np.array[float]) – data to differentiate
dt (float) – step size
num_iterations (int) – number of iterations. If >1, the derivative is integrated with trapezoidal rule, that result is finite-differenced again, and the cycle is repeated num_iterations-1 times
- Returns:
x_hat (np.array) – original x if
num_iterations=1, else smoothed x that yielded dxdt_hatdxdt_hat (np.array) – estimated derivative of x
- pynumdiff.finite_difference.fourth_order(x, dt, num_iterations=1)
Fourth-order centered difference method, with special endpoint formulas.
Deprecated, prefer
finitediffwith order 4 instead.- Parameters:
x (np.array[float]) – data to differentiate
dt (float) – step size
num_iterations (int) – number of iterations. If >1, the derivative is integrated with trapezoidal rule, that result is finite-differenced again, and the cycle is repeated num_iterations-1 times
- Returns:
x_hat (np.array) – original x if
num_iterations=1, else smoothed x that yielded dxdt_hatdxdt_hat (np.array) – estimated derivative of x