Function itp

Source
pub fn itp<N, F>(
    initial: (N, N),
    f: F,
    k_1: N,
    k_2: N,
    n_0: N,
    tol: N,
) -> Result<N, String>
where N: RealField + FromPrimitive + Copy, F: FnMut(N) -> N,
Expand description

Find the root of an equation using the ITP method.

The initial guess must bracket the root, that is the function evaluations must differ in sign between the two initial guesses. k_1 is a parameter in (0, infty). k_2 is a paramater in (1, 1 + golden_ratio). n_0 is a parameter in [0, infty). This method gives the worst case performance of the bisection method (which has the best worst case performance) with better average convergance.

ยงExamples

use bacon_sci::roots::itp;
fn cubic(x: f64) -> f64 {
    x.powi(3)
}
//...
fn example() {
  let solution = itp((0.1, -0.1), cubic, 0.1, 2.0, 0.99, 1e-5).unwrap();
}