Skip to main content

bisection

Function bisection 

Source
pub fn bisection<F>(
    f: F,
    a: f64,
    b: f64,
    tol: f64,
    max_iter: usize,
) -> Result<f64>
where F: Fn(f64) -> f64,
Expand description

Find a root of f(x) = 0 using the bisection method.

§Arguments

  • f - The function to find the root of
  • a - Left bound of the interval
  • b - Right bound of the interval
  • tol - Tolerance for convergence
  • max_iter - Maximum number of iterations

§Returns

The approximate root x such that f(x) ≈ 0

§Errors

Returns an error if f(a) and f(b) have the same sign or max iterations exceeded