[][src]Function bacon_sci::ivp::solve_ivp

pub fn solve_ivp<N: ComplexField, S: DimName, T: Clone, F: FnMut(N::RealField, &[N], &mut T) -> Result<VectorN<N, S>, String>>(
    (start, end): (N::RealField, N::RealField),
    (dt_max, dt_min): (N::RealField, N::RealField),
    y_0: &[N],
    f: F,
    tol: N::RealField,
    params: &mut T
) -> Result<Vec<(N::RealField, VectorN<N, S>)>, String> where
    DefaultAllocator: Allocator<N, S>,
    DefaultAllocator: Allocator<N, U6>,
    DefaultAllocator: Allocator<N, S, U6>,
    DefaultAllocator: Allocator<N, U6, U6>,
    DefaultAllocator: Allocator<N::RealField, U6>,
    DefaultAllocator: Allocator<N::RealField, U6, U6>, 

Solve an initial value problem of y'(t) = f(t, y) numerically.

Tries to solve an initial value problem with an Adams predictor-corrector, the Runge-Kutta-Fehlberg method, and finally a backwards differentiation formula. This is probably what you want to use.

Params

(start, end) The start and end times for the IVP

(dt_max, dt_min) The maximum and minimum time step for solving

y_0 The initial conditions at start

f the derivative function

tol acceptable error between steps.

params parameters to pass to the derivative function

Examples

use nalgebra::{VectorN, U1};
use bacon_sci::ivp::solve_ivp;
fn derivatives(_: f64, y: &[f64], _: &mut ()) -> Result<VectorN<f64, U1>, String> {
    Ok(-VectorN::<f64, U1>::from_column_slice(y))
}

fn example() -> Result<(), String> {
    let path = solve_ivp((0.0, 10.0), (0.1, 0.001), &[1.0], derivatives, 0.00001, &mut ())?;

    for step in path {
        assert!(((-step.0).exp() - step.1.column(0)[0]).abs() < 0.001);
    }

    Ok(())
}