Package com.irurueta.numerical.roots
Class BrentSingleRootEstimator
java.lang.Object
com.irurueta.numerical.roots.RootEstimator
com.irurueta.numerical.roots.SingleRootEstimator
com.irurueta.numerical.roots.BracketedSingleRootEstimator
com.irurueta.numerical.roots.BrentSingleRootEstimator
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final double
Constant defining default accuracy of the estimated root.static final double
Constant defining a small value which is considered as machine precision.static final int
Constant defining maximum number of iterations.static final double
Constant defining minimum allowed tolerance.private double
Tolerance value.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.BrentSingleRootEstimator
(SingleDimensionFunctionEvaluatorListener listener, 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.boolean
isReady()
Returns boolean indicating whether this instance is ready to start estimating a root.void
setTolerance
(double tolerance) Sets tolerance value.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
-
ITMAX
public static final int ITMAXConstant defining maximum number of iterations.- See Also:
-
EPS
public static final double EPSConstant defining a small value which is considered as machine precision.- 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
-
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
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).
-
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 classSingleRootEstimator
- Returns:
- True if this instance is ready, false otherwise.
-