Function roots::find_root_brent [] [src]

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

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 convergency = SimpleConvergency { eps:1e-15f64, max_iter:30 };

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

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