fn select_initial_step<F>(
    fun: &mut F,
    t0: f64,
    y0: ArrayView1<'_, f64>,
    f0: ArrayView1<'_, f64>,
    direction: f64,
    order: usize,
    rtol: ArrayView1<'_, f64>,
    atol: ArrayView1<'_, f64>,
) -> f64
where
    F: FnMut(f64, ArrayView1<'_, f64>, ArrayViewMut1<'_, f64>),
{
    if y0.is_empty() {
        return ::std::f64::INFINITY;
    }

    let scale = y0.mapv(f64::abs) * rtol + atol;
    let d0 = norm(y0, scale.view());
    let d1 = norm(f0, scale.view());
    let h0 = if d0 < 1e-5 || d1 < 1e-5 {
        1e-6
    } else {
        0.01 * d0 / d1
    };

    let y1 = h0 * direction * &f0 + y0;
    let mut f1 = Array1::zeros(y0.len());
    fun(t0 + h0 * direction, y1.view(), f1.view_mut());
    let d2 = norm((f1 - f0).view(), scale.view()) / h0;

    let h1 = if d1 <= 1e-15 && d2 <= 1e-15 {
        (h0 * 1e-3).max(1e-6)
    } else {
        (0.01 / d1.max(d2)).powf(1. / (order as f64 + 1.))
    };

    return (100. * h0).min(h1);
}
/// Empirically select a good initial step.
///
/// The algorithm is described in (ref 1).
///
/// # Parameters
///
/// * fun: Right-hand side of the system.
/// * t0: Initial value of the independent variable.
/// * y0: Initial value of the dependent variable.
/// * f0: Initial value of the derivative, i.e. the result of calling `fun`
///   with `t0` and `y0`.
/// * direction: Integration direction.
/// * order: Method order.
/// * rtol: Desired relative tolerance.
/// * atol: Desired absolute tolerance.
///
/// # Returns
///
/// Absolute value of the suggested initial step.
///
/// # References
///
/// 1. E. Hairer, S. P. Norsett G. Wanner, "Solving Ordinary Differential
///    Equations I: Nonstiff Problems", Sec. II.4.
Empirically select a good initial step.
The algorithm is described in (ref 1).
Empirically select a good initial step . The algorithm is described in ( ref 1 ) .
fn select_initial_step<F>(
    fun: &mut F,
    t0: f64,
    y0: ArrayView1<'_, f64>,
    f0: ArrayView1<'_, f64>,
    direction: f64,
    order: usize,
    rtol: ArrayView1<'_, f64>,
    atol: ArrayView1<'_, f64>,
) -> f64
where
    F: FnMut(f64, ArrayView1<'_, f64>, ArrayViewMut1<'_, f64>),
{
    if y0.is_empty() {
        return ::std::f64::INFINITY;
    }
    let scale = y0.mapv(f64::abs) * rtol + atol;
    let d0 = norm(y0, scale.view());
    let d1 = norm(f0, scale.view());
    let h0 = if d0 < 1e-5 || d1 < 1e-5 {
        1e-6
    } else {
        0.01 * d0 / d1
    };
    let y1 = h0 * direction * &f0 + y0;
    let mut f1 = Array1::zeros(y0.len());
    fun(t0 + h0 * direction, y1.view(), f1.view_mut());
    let d2 = norm((f1 - f0).view(), scale.view()) / h0;
    let h1 = if d1 <= 1e-15 && d2 <= 1e-15 {
        (h0 * 1e-3).max(1e-6)
    } else {
        (0.01 / d1.max(d2)).powf(1. / (order as f64 + 1.))
    };
    return (100. * h0).min(h1);
}
fn select_initial_step < F > ( fun : & mut F , t0 : f64 , y0 : ArrayView1 < ' _ , f64 > , f0 : ArrayView1 < ' _ , f64 > , direction : f64 , order : usize , rtol : ArrayView1 < ' _ , f64 > , atol : ArrayView1 < ' _ , f64 > , ) -> f64 where F : FnMut ( f64 , ArrayView1 < ' _ , f64 > , ArrayViewMut1 < ' _ , f64 > ) , { if y0 . is_empty ( ) { return :: std :: f64 :: INFINITY ; } let scale = y0 . mapv ( f64 :: abs ) * rtol + atol ; let d0 = norm ( y0 , scale . view ( ) ) ; let d1 = norm ( f0 , scale . view ( ) ) ; let h0 = if d0 < 1e-5 || d1 < 1e-5 { 1e-6 } else { 0.01 * d0 / d1 } ; let y1 = h0 * direction * & f0 + y0 ; let mut f1 = Array1 :: zeros ( y0 . len ( ) ) ; fun ( t0 + h0 * direction , y1 . view ( ) , f1 . view_mut ( ) ) ; let d2 = norm ( ( f1 - f0 ) . view ( ) , scale . view ( ) ) / h0 ; let h1 = if d1 <= 1e-15 && d2 <= 1e-15 { ( h0 * 1e-3 ) . max ( 1e-6 ) } else { ( 0.01 / d1 . max ( d2 ) ) . powf ( 1. / ( order as f64 + 1. ) ) } ; return ( 100. * h0 ) . min ( h1 ) ; }
Empirically select a good initial step.
Empirically select a good initial step .
fun
&mut F
t0
f64
y0
ArrayView1<'_, f64>
f0
ArrayView1<'_, f64>
direction
f64
order
usize
rtol
ArrayView1<'_, f64>
atol
ArrayView1<'_, f64>
Absolute value of the suggested initial step.
Absolute value of the suggested initial step .
fun
&mut F
t0
f64
y0
ArrayView1<'_, f64>
f0
ArrayView1<'_, f64>
direction
f64
order
usize
rtol
ArrayView1<'_, f64>
atol
ArrayView1<'_, f64>
references
1. E. Hairer, S. P. Norsett G. Wanner, "Solving Ordinary Differential
Equations I: Nonstiff Problems", Sec. II.4.
1 . E . Hairer S . P . Norsett G . Wanner " Solving Ordinary Differential Equations I : Nonstiff Problems " Sec . II . 4 .