Class SafeNewtonRaphsonSingleRootEstimator


public class SafeNewtonRaphsonSingleRootEstimator extends DerivativeSingleRootEstimator
Computes a root for a single dimension function inside a given bracket of values, in other words, root will only be searched within provided minimum and maximum evaluation points. This class searches for REAL roots only! This implementation is based on Numerical Recipes 3rd ed. Section 9.4, page 456.
  • Field Details

    • MAXIT

      public static final int MAXIT
      Maximum number of iterations.
      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

    • SafeNewtonRaphsonSingleRootEstimator

      public SafeNewtonRaphsonSingleRootEstimator()
      Empty constructor.
    • SafeNewtonRaphsonSingleRootEstimator

      public SafeNewtonRaphsonSingleRootEstimator(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.
    • SafeNewtonRaphsonSingleRootEstimator

      public SafeNewtonRaphsonSingleRootEstimator(SingleDimensionFunctionEvaluatorListener listener, SingleDimensionFunctionEvaluatorListener derivativeListener, double minEvalPoint, double maxEvalPoint, double tolerance) throws InvalidBracketRangeException
      Constructor.
      Parameters:
      listener - Listener to evaluate a single dimension function f(x) to find its roots.
      derivativeListener - Listener to evaluate the function's derivative
      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).