Skip to main content

brent

Function brent 

Source
pub fn brent<T: FloatScalar>(
    f: impl FnMut(T) -> T,
    a: T,
    b: T,
    settings: &RootSettings<T>,
) -> Result<RootResult<T>, OptimError>
Expand description

Brent’s method for bracketed root finding.

Combines bisection, secant, and inverse quadratic interpolation for superlinear convergence while guaranteeing the bracket shrinks every step.

§Arguments

  • f — function whose root is sought
  • a, b — bracket endpoints; must satisfy f(a) * f(b) < 0
  • settings — convergence tolerances and iteration limit

§Errors

Returns OptimError::BracketInvalid if f(a) and f(b) have the same sign. Returns OptimError::MaxIterations if convergence is not achieved.

§Example

use numeris::optim::{brent, RootSettings};

// Find √2 as root of x² - 2
let r = brent(|x| x * x - 2.0, 0.0, 2.0, &RootSettings::default()).unwrap();
assert!((r.x - core::f64::consts::SQRT_2).abs() < 1e-12);