newton_raphson

Function iteration

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

Runs through one iteration of the Newton-Raphson method

ยงExamples

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

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

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

assert_eq!(35.6, iteration(sqrt_of_612, sqrt_of_612_d, 10.0));