Function qcd_sme::utils::find_root

source ·
pub fn find_root<T: Num, F: Fn(T) -> T>(
    f: F,
    guesses: (T, T),
    tol: R,
    max_iter: usize
) -> Option<(T, T)>
Expand description

Finds (at most) one zero of a real or complex function using the secant method.

f is the (real or complex) function whose zero is to be searched, guesses contains two distinct initial guesses, tol is the tolerance requested for the absolute value of the function at its candidate zero, max_iter is the maximum number of iterations. After max_iter iterations the algorithm is forced to fail and the function returns None.

When the algorithm doesn’t fail, find_root returns Some((z0, f0)), where z0 is the candidate zero and f0 = f(z0), with abs(f0) guaranteed to be smaller than tol.

§Panics

This function panics if guesses.0 == guesses.1 or if tol <= 0..