Function roots::find_root_newton_raphson [] [src]

pub fn find_root_newton_raphson<F: FloatType>(start: F, f: &Fn(F) -> F, d: &Fn(F) -> F, convergency: &Convergency<F>) -> Result<F, SearchError>

Find a root of the function f(x) = 0 using the Newton-Raphson method.

Pro

  • Simple
  • Fast convergency for well-behaved functions
  • No need for initial bracketing

Contra

  • Needs derivative function
  • Impossible to predict which root will be found when many roots exist
  • Unstable convergency for non-trivial functions
  • Cannot continue when derivative is zero

Failures

ZeroDerivative

The stationary point of the function is encountered. Algorithm cannot continue.

NoConvergency

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

Examples

use roots::SimpleConvergency;
use roots::find_root_newton_raphson;

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

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

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