pub trait ODE<T = f64, Y = f64>{
// Required method
fn diff(&self, t: T, y: &Y, dydt: &mut Y);
// Provided method
fn jacobian(&self, t: T, y: &Y, j: &mut Matrix<T>) { ... }
}Expand description
ODE Trait for Differential Equations
ODE trait defines the differential equation dydt = f(t, y) for the solver. The differential equation is used to solve the ordinary differential equation. The trait also includes a solout function to interupt the solver when a condition is met or event occurs.
§Impl
diff- Differential Equation dydt = f(t, y) in form f(t, &y, &mut dydt).event- Event function to interupt solver when condition is met or event occurs.jacobian- Jacobian matrix J = df/dy for the system of equations.
Note that the event and jacobian functions are optional and can be left out when implementing.
Required Methods§
Sourcefn diff(&self, t: T, y: &Y, dydt: &mut Y)
fn diff(&self, t: T, y: &Y, dydt: &mut Y)
Differential Equation dydt = f(t, y)
An ordinary differential equation (ODE) takes a independent variable which in this case is ‘t’ as it is typically time and a dependent variable which is a vector of values ‘y’. The ODE returns the derivative of the dependent variable ‘y’ with respect to the independent variable ‘t’ as dydt = f(t, y).
For efficiency and ergonomics the derivative is calculated from an argument of a mutable reference to the derivative vector dydt. This allows for a derivatives to be calculated in place which is more efficient as iterative ODE solvers require the derivative to be calculated at each step without regard to the previous value.
§Arguments
t- Independent variable point.y- Dependent variable point.dydt- Derivative point.
Provided Methods§
Sourcefn jacobian(&self, t: T, y: &Y, j: &mut Matrix<T>)
fn jacobian(&self, t: T, y: &Y, j: &mut Matrix<T>)
jacobian matrix J = df/dy
The jacobian matrix is a matrix of partial derivatives of a vector-valued function. It describes the local behavior of the system of equations and can be used to improve the efficiency of certain solvers by providing information about the local behavior of the system of equations.
By default, this method uses a finite difference approximation. Users can override this with an analytical implementation for better efficiency.
§Arguments
t- Independent variable grid point.y- Dependent variable vector.j- jacobian matrix. This matrix should be pre-sized by the caller todim x dimwheredim = y.len().