Crate newton_raphson

Source
Expand description

A minimal module for calculating roots using the Newton-Raphson method, as described by Wikipedia

§Examples

[Solution of cos(c) = x^3^] (https://en.wikipedia.org/wiki/Newton%27s_method#Solution_of_cos.28x.29_.3D_x3)

use std::f64;
use newton_raphson::find_root;
fn cosx(x: f64) -> f64 {
    x.cos() - (x * x * x)
}

fn cosx_d(x: f64) -> f64 {
    -x.sin() - 3.0 * (x * x)
}

assert_eq!(0.8654740331016144, find_root(cosx, cosx_d, 0.5, 6));

Functions§

  • Finds the root of the function f
  • Runs through one iteration of the Newton-Raphson method