Skip to main content

bdf2

Function bdf2 

Source
pub fn bdf2<T, F>(
    f: F,
    t_span: [T; 2],
    y0: &[T],
    options: &OdeOptions<T>,
) -> Result<OdeResult<T>>
where T: Float, F: Fn(T, &[T]) -> Vec<T>,
Expand description

Solve a stiff ODE system using the BDF-2 method.

f(t, y) -> dy/dt defines the system. y0 is the initial state vector. Uses BDF-1 (backward Euler) for the first step, then BDF-2 for subsequent steps.

§Examples

// dy/dt = -50*y (stiff equation), y(0) = 1
let result = bdf2(
    |_t: f64, y: &[f64]| vec![-50.0 * y[0]],
    [0.0, 1.0],
    &[1.0],
    &OdeOptions::default(),
).unwrap();
assert!(result.success);