pub fn ternary_search_min(
    f: fn(f32) -> f32,
    mut start: f32,
    mut end: f32,
    absolute_precision: f32,
) -> f32 {
    while (start - end).abs() >= absolute_precision {
        let mid1 = start + (end - start) / 3.0;
        let mid2 = end - (end - start) / 3.0;

        let r1 = f(mid1);
        let r2 = f(mid2);

        if r1 < r2 {
            end = mid2;
        } else if r1 > r2 {
            start = mid1;
        } else {
            start = mid1;
            end = mid2;
        }
    }
    f(start)
}
/// Ternary search algorithm for finding minimum of unimodal function
Ternary search algorithm for finding minimum of unimodal function
Ternary search algorithm for finding minimum of unimodal function
pub fn ternary_search_min(
    f: fn(f32) -> f32,
    mut start: f32,
    mut end: f32,
    absolute_precision: f32,
) -> f32 {
    while (start - end).abs() >= absolute_precision {
        let mid1 = start + (end - start) / 3.0;
        let mid2 = end - (end - start) / 3.0;
        let r1 = f(mid1);
        let r2 = f(mid2);
        if r1 < r2 {
            end = mid2;
        } else if r1 > r2 {
            start = mid1;
        } else {
            start = mid1;
            end = mid2;
        }
    }
    f(start)
}
pub fn ternary_search_min ( f : fn ( f32 ) -> f32 , mut start : f32 , mut end : f32 , absolute_precision : f32 , ) -> f32 { while ( start - end ) . abs ( ) >= absolute_precision { let mid1 = start + ( end - start ) / 3.0 ; let mid2 = end - ( end - start ) / 3.0 ; let r1 = f ( mid1 ) ; let r2 = f ( mid2 ) ; if r1 < r2 { end = mid2 ; } else if r1 > r2 { start = mid1 ; } else { start = mid1 ; end = mid2 ; } } f ( start ) }
Ternary search algorithm for finding minimum of unimodal function
Ternary search algorithm for finding minimum of unimodal function
f
fn(f32) -> f32
start
f32
end
f32
absolute_precision
f32
f
fn(f32) -> f32
start
f32
end
f32
absolute_precision
f32