[][src]Function peroxide::numerical::root::secant

pub fn secant<F: Fn(AD1) -> AD1>(
    f: F,
    initial_guess: (f64, f64),
    times: usize,
    tol: f64
) -> Result<f64, RootError>

Secant method to find root

Usage

extern crate peroxide;
use peroxide::fuga::*;

fn main() -> Result<(), RootError> {
    let x = secant(f, (2f64, 2.1f64), 100, 1e-15)?;
    assert!((x - 3f64).abs() < 1e-15);
    Ok(())
}

fn f<T: AD>(x: T) -> T {
    x.powi(2) - x * 2f64 - 3f64
}