[−][src]Function lsode::solve_ode
pub fn solve_ode<F>(
rhs: F,
y0: &[f64],
t_dense: Vec<f64>,
atol: f64,
rtol: f64
) -> Vec<Vec<f64>> where
F: Fn(&[f64], &f64) -> Vec<f64>,
Solves system of ODEs for times in t_dense
.
First time in t_dense
has to be the initial time.
Each equation in the system of ODEs has the form:
dy/dt = f(y, t)
The function expects the function f as the first argument rhs
.
Initial state is given in y0
.
Example
let y0 = [1.0]; let ts = vec![0.0, 1.0]; let f = |y: &[f64], t: &f64| { let mut dy = vec![0.0]; dy[0] = *t * y[0]; dy }; let sol = lsode::solve_ode(f, &y0, ts, 1e-6, 1e-6); assert!((sol[1][0] - y0[0]*0.5_f64.exp()).abs() < 1e-3, "error too large");