newton_raphson

Function find_root

Source
pub fn find_root(
    f: fn(_: f64) -> f64,
    fd: fn(_: f64) -> f64,
    guess: f64,
    iterations: i32,
) -> f64
Expand description

Finds the root of the function f

ยงExamples

[Finding the square root of a number] (https://en.wikipedia.org/wiki/Newton%27s_method#Square_root_of_a_number)

use newton_raphson::find_root;
fn sqrt_of_612(x: f64) -> f64 {
    (x * x) - 612.0
}

fn sqrt_of_612_d(x: f64) -> f64 {
    2.0 * x
}

assert_eq!(24.738633753766084, find_root(sqrt_of_612, sqrt_of_612_d, 10.0, 5))