[][src]Function roots::find_root_brent

pub fn find_root_brent<F, Func>(
    a: F,
    b: F,
    f: Func,
    convergency: &mut dyn Convergency<F>
) -> Result<F, SearchError> where
    F: FloatType,
    Func: Fn(F) -> F, 

Find a root of the function f(x) = 0 using the Brent method.

Pro

  • Fast
  • Robust
  • No need for derivative function

Contra

  • Complicated
  • Needs initial bracketing

Failures

NoBracketing

Initial values do not bracket the root.

NoConvergency

Algorithm cannot find a root within the given number of iterations.

Examples

use roots::SimpleConvergency;
use roots::find_root_brent;

let f = |x| { 1f64*x*x - 1f64 };
let mut convergency = SimpleConvergency { eps:1e-15f64, max_iter:30 };

let root1 = find_root_brent(10f64, 0f64, &f, &mut convergency);
// Returns approximately Ok(1);

let root2 = find_root_brent(-10f64, 0f64, &f, &mut 1e-15f64);
// Returns approximately Ok(-1);