[−][src]Function roots::find_root_newton_raphson
pub fn find_root_newton_raphson<F, Func, Deriv>(
start: F,
f: Func,
d: Deriv,
convergency: &mut dyn Convergency<F>
) -> Result<F, SearchError> where
F: FloatType,
Func: Fn(F) -> F,
Deriv: Fn(F) -> F,
Find a root of the function f(x) = 0 using the Newton-Raphson method.
Pro
- Simple
- Fast convergency for well-behaved functions
- No need for initial bracketing
Contra
- Needs derivative function
- Impossible to predict which root will be found when many roots exist
- Unstable convergency for non-trivial functions
- Cannot continue when derivative is zero
Failures
ZeroDerivative
The stationary point of the function is encountered. Algorithm cannot continue.
NoConvergency
Algorithm cannot find a root within the given number of iterations.
Examples
use roots::SimpleConvergency; use roots::find_root_newton_raphson; let f = |x| { 1f64*x*x - 1f64 }; let d = |x| { 2f64*x }; let mut convergency = SimpleConvergency { eps:1e-15f64, max_iter:30 }; let root1 = find_root_newton_raphson(10f64, &f, &d, &mut convergency); // Returns approximately Ok(1); let root2 = find_root_newton_raphson(-10f64, &f, &d, &mut 1e-15f64); // Returns approximately Ok(-1);