#root #newton-raphson #numeric #calculus #square-root

nrfind

A set of useful mathematical functions for floating point numbers based on the Newton-Raphson method for finding roots

8 releases (4 stable)

Uses old Rust 2015

1.0.3 Sep 27, 2019
1.0.2 Jan 28, 2018
1.0.0 Sep 3, 2017
0.2.1 Jan 12, 2017
0.1.1 Jan 11, 2017

#703 in Math

Download history 917/week @ 2024-03-14 1005/week @ 2024-03-21 519/week @ 2024-03-28 711/week @ 2024-04-04 1217/week @ 2024-04-11 1103/week @ 2024-04-18 613/week @ 2024-04-25 899/week @ 2024-05-02 801/week @ 2024-05-09 911/week @ 2024-05-16 1085/week @ 2024-05-23 756/week @ 2024-05-30 878/week @ 2024-06-06 786/week @ 2024-06-13 981/week @ 2024-06-20 701/week @ 2024-06-27

3,507 downloads per month
Used in 6 crates (2 directly)

MIT license

8KB

nrfind

Crates.io version badge Build Status Passively Maintained

nrfind provides a Newton-Raphson root finder for arbitrary differentiable functions, as well as convenient wrappers for common use cases like square roots.

Documentation is available on docs.rs

A simple example of usage to find the roots of x^3 + x^2 + 1 in 18 iterations:

extern crate nrfind;

// The function for whose roots find_root will solve
fn f(x: f64) -> f64 {
    x.powi(3) + x.powi(2) + 1.0
}

// That function's derivative
fn fd(x: f64) -> f64 {
    (3.0 * x.powi(2)) + (2.0 * x)
}

fn main() {
    let initial_guess = 100.0;
    let precision = 0.1;
    let iterations = 18;

    println!("x^3 + x^2 + 1 = 0 when x ~= {}",
             nrfind::find_root(&f, &fd, 
                               initial_guess, 
                               precision, 
                               iterations).unwrap());
}

This will print: x^3 + x^2 + 1 = 0 when x ~= -1.4675327346575013.

Note that while this method is guaranteed to approximate a root, it may not be the root you care about! Changing the given x0 guess can have an impact on which root is approximated.

Dependencies

~475KB