Class BrentRoot

  • All Implemented Interfaces:
    Uniroot

    public class BrentRoot
    extends Object
    implements Uniroot
    Brent's root-finding algorithm combines super-linear convergence with reliability of bisection. It uses the secant method or inverse quadratic interpolation whenever possible because they converge faster, but falls back to the more robust bisection method if necessary. Unlike NewtonRoot and HalleyRoot, it does not need the derivatives of the function. Brent's algorithm is the preferred method of choice for root-finding.
    See Also:
    Wikipedia: Brent's method
    • Constructor Detail

      • BrentRoot

        public BrentRoot​(double tol,
                         int maxIterations)
        Construct an instance of Brent's root finding algorithm.
        Parameters:
        tol - the convergence tolerance
        maxIterations - the maximum number of iterations
    • Method Detail

      • solve

        public double solve​(UnivariateRealFunction f,
                            double lower,
                            double upper,
                            double... guess)
        Description copied from interface: Uniroot
        Search for a root, x, in the interval [lower, upper] such that f(x) = 0.
        Specified by:
        solve in interface Uniroot
        Parameters:
        f - a univariate function
        lower - the lower bound of the bracketing interval
        upper - the upper bound of the bracketing interval
        guess - an initial guess of the root within [lower, upper]. Note that guess is a double[]. This signature allows multiple initial guesses for certain types of uniroot algorithms, e.g., Brent's algorithm.
        Returns:
        an approximate root