Class BrentSingleRootEstimator


public class BrentSingleRootEstimator extends BracketedSingleRootEstimator
This class estimates the root of a single dimension continuous function using Brent's method. The implementation of this class is based on Numerical Recipes 3rd ed. Section 9.3. Page 454.
  • Field Details

    • ITMAX

      public static final int ITMAX
      Constant defining maximum number of iterations.
      See Also:
    • EPS

      public static final double EPS
      Constant defining a small value which is considered as machine precision.
      See Also:
    • DEFAULT_TOLERANCE

      public static final double DEFAULT_TOLERANCE
      Constant defining default accuracy of the estimated root.
      See Also:
    • MIN_TOLERANCE

      public static final double MIN_TOLERANCE
      Constant defining minimum allowed tolerance.
      See Also:
    • tolerance

      private double tolerance
      Tolerance value. The algorithm will iterate until the result converges below this value of accuracy or until the maximum number of iterations is achieved (and in such case, convergence will be assumed to have failed).
  • Constructor Details

    • BrentSingleRootEstimator

      public BrentSingleRootEstimator()
      Empty constructor.
    • BrentSingleRootEstimator

      public BrentSingleRootEstimator(SingleDimensionFunctionEvaluatorListener listener, double minEvalPoint, double maxEvalPoint, double tolerance) throws InvalidBracketRangeException
      Constructor.
      Parameters:
      listener - Listener to evaluate a single dimension function f(x) to find its roots.
      minEvalPoint - Smallest value inside the bracket of values where the root will be searched.
      maxEvalPoint - Largest value inside the bracket of values where the root will be searched.
      tolerance - Tolerance to be achieved in the estimated root.
      Throws:
      InvalidBracketRangeException - Raised if minEvalPoint < maxEvalPoint.
      IllegalArgumentException - Raised if tolerance is negative.
  • Method Details

    • getTolerance

      public double getTolerance()
      Returns tolerance value. Tolerance is the accuracy to be achieved when estimating a root. If a root is found by this class, it is ensured to have an accuracy below the tolerance value.
      Returns:
      Tolerance value.
    • internalSetTolerance

      private void internalSetTolerance(double tolerance)
      Internal method to set tolerance value. Tolerance is the accuracy to be achieved when estimating a root. If a root is found by this class, it is ensured to have an accuracy below provided tolerance value. This method does not check whether this instance is locked or not.
      Parameters:
      tolerance - Tolerance value.
      Throws:
      IllegalArgumentException - Raised if provided tolerance value is negative.
    • setTolerance

      public void setTolerance(double tolerance) throws LockedException
      Sets tolerance value. Tolerance is the accuracy to be achieved when estimating a root. If a root is found by this class, it is ensured to have an accuracy below provided tolerance value.
      Parameters:
      tolerance - Tolerance value.
      Throws:
      LockedException - Raised if this instance is locked.
      IllegalArgumentException - Raised if provided tolerance value is negative.
    • estimate

      Estimates a local root for a given single dimension function being evaluated by provided listener.
      Overrides:
      estimate in class RootEstimator
      Throws:
      LockedException - Exception raised if this instance is already locked.
      NotReadyException - Exception raised if either a listener has not yet been provided or a bracket has not been provided or computed.
      RootEstimationException - Raised if the root estimation failed for some other reason (usually inability to evaluate the function, numerical instability or convergence problems, or no roots are found).
    • isReady

      public boolean isReady()
      Returns boolean indicating whether this instance is ready to start estimating a root. This class will be ready once a listener is provided and a bracket is either provided or computed.
      Overrides:
      isReady in class SingleRootEstimator
      Returns:
      True if this instance is ready, false otherwise.