Class BisectionRoot

  • All Implemented Interfaces:
    Uniroot

    public class BisectionRoot
    extends Object
    implements Uniroot
    The bisection method repeatedly bisects an interval and then selects a subinterval in which a root must lie for further processing. It is a very simple and robust method, but it is also relatively slow.

    The method is guaranteed to converge to a root of f(x) if it is a continuous function on the interval [a, b] and f(a) and f(b) have opposite signs. The absolute error is halved at each step so the method converges linearly.

    See Also:
    Wikipedia: Bisection method
    • Constructor Detail

      • BisectionRoot

        public BisectionRoot​(double tol,
                             int maxIterations)
        Construct an instance with the tolerance for convergence and the maximum number of iterations.
        Parameters:
        tol - the 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