Skip to main content

newton_bracketed

Function newton_bracketed 

pub(crate) fn newton_bracketed(
    g: impl FnMut(f64) -> (f64, f64),
    lo: f64,
    hi: f64,
    x0: f64,
    target: f64,
    tol: SolveTolerance,
    cap: usize,
) -> Result<Solved, SolveFailure>
Expand description

Newton for f(x) = target from x0, safeguarded by the bracket [lo, hi].

g returns (f(x), f′(x)) — the pair a forward-mode evaluation hands back for free. A Newton step that leaves the bracket, or a zero slope, falls back to the bracket midpoint; the bracket itself tightens at every iterate, so the fallback is always a bisection step and convergence is never worse than bisection’s. The endpoints are evaluated once to confirm the bracket; each iteration evaluates g exactly once.