[][src]Function roots::find_root_inverse_quadratic

pub fn find_root_inverse_quadratic<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 inverse quadratic approximation.

Pro

  • Faster than linear approximation
  • No need for derivative function

Contra

  • sqrt is calculated on every step
  • only works for polynomial-like functions

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_inverse_quadratic;

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

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

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