Class HalleyRoot

  • All Implemented Interfaces:
    Uniroot

    public class HalleyRoot
    extends Object
    implements Uniroot
    Halley's method is an iterative root finding method for a univariate function with a continuous second derivative, i.e., a C2 function. It has the following properties.
    • The function to be solved is assumed to be continuous and smooth (1st derivative exists).
    • The 1st derivative is assumed to be continuous and smooth (2nd derivative exists).
    • The rate of convergence for solution is cubic.
    See Also:
    Wikipedia: Halley's method
    • Constructor Detail

      • HalleyRoot

        public HalleyRoot​(double tol,
                          int maxIterations)
        Construct an instance of Halley'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)
                     throws NoRootFoundException
        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
        Throws:
        NoRootFoundException - when the search fails to find a root
      • solve

        public double solve​(UnivariateRealFunction f,
                            double guess)
                     throws NoRootFoundException
        Search for a root, x, in the interval [lower, upper] such that f(x) = 0.
        Parameters:
        f - a univariate function
        guess - an initial guess of the root within [lower, upper]
        Returns:
        an approximate root
        Throws:
        NoRootFoundException - when the search fails to find a root