[][src]Crate nrfind

nrfind is a crate for finding the roots of arbitrary functions whose derivatives are known by the Newton-Rahpson method.


Here, find_sqrt is used to approximate the square root of 25.1 to within 0.01, with a starting guess of 5, using at most 100 iterations of the NR method.

use nrfind::find_sqrt;

match find_sqrt(25.1, 5.0, 0.01, 100) {
    Ok(v) => println!("sqrt(25.1) ~= {} within 0.01", v),
    Err(v) => println!("Could not find sqrt(25.1) within 0.01; closest guess was {}.", v),



Uses the Newton-Raphson method to find roots for function given that derivative is the first derivative of function. If max_iterations is reached without the error falling below the given acceptable_err, nrfind will return None.


Find the square root of a given radicand to within a given acceptable_err by the Newton-Rahpson method, using the initial guess x0. If, after max_iterations, the error is not less than the give acceptable_err, None is returned.

Type Definitions


A NumericSolutionResult is returned from the various nrfind functions. An Ok value signifies a result that is within the given precision while an Err result signifies a result that is not known to be sufficiently precise.