Package com.irurueta.numerical.roots
Class SafeNewtonRaphsonSingleRootEstimator
java.lang.Object
com.irurueta.numerical.roots.RootEstimator
com.irurueta.numerical.roots.SingleRootEstimator
com.irurueta.numerical.roots.BracketedSingleRootEstimator
com.irurueta.numerical.roots.DerivativeSingleRootEstimator
com.irurueta.numerical.roots.SafeNewtonRaphsonSingleRootEstimator
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final double
Constant defining default accuracy of the estimated root.static final int
Maximum number of iterations.static final double
Constant defining minimum allowed tolerance.private double
Tolerance value.Fields inherited from class com.irurueta.numerical.roots.DerivativeSingleRootEstimator
derivativeListener
Fields inherited from class com.irurueta.numerical.roots.BracketedSingleRootEstimator
BRACKET_EPS, bracketAvailable, DEFAULT_MAX_EVAL_POINT, DEFAULT_MIN_EVAL_POINT, FACTOR, maxEvalPoint, minEvalPoint, NTRY
Fields inherited from class com.irurueta.numerical.roots.SingleRootEstimator
listener, root, rootAvailable
Fields inherited from class com.irurueta.numerical.roots.RootEstimator
locked
-
Constructor Summary
ConstructorsConstructorDescriptionEmpty constructor.SafeNewtonRaphsonSingleRootEstimator
(SingleDimensionFunctionEvaluatorListener listener, double minEvalPoint, double maxEvalPoint, double tolerance) Constructor.SafeNewtonRaphsonSingleRootEstimator
(SingleDimensionFunctionEvaluatorListener listener, SingleDimensionFunctionEvaluatorListener derivativeListener, double minEvalPoint, double maxEvalPoint, double tolerance) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
estimate()
Estimates a local root for a given single dimension function being evaluated by provided listener.double
Returns tolerance value.private void
internalSetTolerance
(double tolerance) Internal method to set tolerance value.void
setTolerance
(double tolerance) Sets tolerance value.Methods inherited from class com.irurueta.numerical.roots.DerivativeSingleRootEstimator
getDerivativeListener, isDerivativeListenerAvailable, isReady, setDerivativeListener
Methods inherited from class com.irurueta.numerical.roots.BracketedSingleRootEstimator
computeBracket, computeBracket, computeBracket, getMaxEvaluationPoint, getMinEvaluationPoint, isBracketAvailable, setBracket, sign, swap
Methods inherited from class com.irurueta.numerical.roots.SingleRootEstimator
getListener, getRoot, isListenerAvailable, isRootAvailable, setListener
Methods inherited from class com.irurueta.numerical.roots.RootEstimator
isLocked
-
Field Details
-
MAXIT
public static final int MAXITMaximum number of iterations.- See Also:
-
DEFAULT_TOLERANCE
public static final double DEFAULT_TOLERANCEConstant defining default accuracy of the estimated root.- See Also:
-
MIN_TOLERANCE
public static final double MIN_TOLERANCEConstant defining minimum allowed tolerance.- See Also:
-
tolerance
private double toleranceTolerance 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 derivativeminEvalPoint
- 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
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 classRootEstimator
- 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).
-