Function roots::find_root_regula_falsi [] [src]

pub fn find_root_regula_falsi<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 Illinois modification of the regula falsi method.

Pro

  • Simple
  • Robust
  • No need for derivative function

Contra

  • Slow
  • 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_regula_falsi;

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

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

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