Function root_bisection_fast

Source
pub fn root_bisection_fast(f: &impl Fn(f64) -> f64, ab: Interval) -> f64
Expand description

Bisection method for finding the root of a univariate, scalar-valued function (fast version).

This implementation is a faster version of root_bisection, with the following changes:

  • It does not allow the specification of solver settings.
  • It does not check that the initial interval brackets a sign change in $f(x)$.
  • It does not store convergence data.
  • The iterative solver terminates when the bracketing interval is within two times the machine epsilon (f64::EPSILON).

§Arguments

  • f - Univariate, scalar-valued function, $f(x)$ ($f:\mathbb{R}\to\mathbb{R}$).
  • ab - Initial bracketing interval containing a sign change in $f(x)$.

§Returns

Root of $f(x)$.

§Note

This function uses a bracket tolerance of two times the machine epsilon (f64::EPSILON).

§Example

Finding the root of $f(x)=x^{2}-1$ in the interval $[0,\infty)$.

use numtest::*;

use rootfinder::{root_bisection_fast, Interval};

// Define the function.
let f = |x: f64| x.powi(2) - 1.0;

// We want the root in the interval [0,∞). Therefore, we use an initial interval of
// [a,b] = [0,9999999]. Finding this root using the bisection method,
let root = root_bisection_fast(&f, Interval::new(0.0, 9999999.0));
assert_equal_to_decimal!(root, 1.0, 16);