Function peroxide::numerical::root::false_position
source · pub fn false_position<F: Fn(AD) -> AD>(
f: F,
interval: (f64, f64),
times: usize,
tol: f64
) -> Result<f64, RootError>
Expand description
False position method to find root
Usage
extern crate peroxide;
use peroxide::fuga::*;
fn main() -> Result<(), RootError> {
let x = false_position(f, (0f64, 4f64), 1000, 1e-15)?;
assert!((x - 3f64).abs() < 1e-15);
Ok(())
}
fn f(x: AD) -> AD {
x.powi(2) - x * 2f64 - 3f64
}