Package com.irurueta.numerical.roots
Class FalsePositionSingleRootEstimator
java.lang.Object
com.irurueta.numerical.roots.RootEstimator
com.irurueta.numerical.roots.SingleRootEstimator
com.irurueta.numerical.roots.BracketedSingleRootEstimator
com.irurueta.numerical.roots.FalsePositionSingleRootEstimator
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 is based on the false position algorithm.
This implementation is based on Numerical Recipes 3rd ed. Section 9.2
page 451.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final double
Constant defining default tolerance to find a root.static final int
Maximum allowed number of iterations.static final double
Minimum allowed tolerance that can be set.private double
Tolerance to find a root.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.FalsePositionSingleRootEstimator
(SingleDimensionFunctionEvaluatorListener listener, double minEvalPoint, double maxEvalPoint, double tolerance) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
estimate()
Estimates a single root of the provided single dimension function contained within a given bracket of values.double
Returns tolerance to find a root.private void
internalSetTolerance
(double tolerance) Internal method to set tolerance to find a root.boolean
isReady()
Returns boolean indicating whether this instance is ready to compute a root.void
setTolerance
(double tolerance) Sets tolerance to find a root.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 allowed number of iterations.- See Also:
-
DEFAULT_TOLERANCE
public static final double DEFAULT_TOLERANCEConstant defining default tolerance to find a root.- See Also:
-
MIN_TOLERANCE
public static final double MIN_TOLERANCEMinimum allowed tolerance that can be set.- See Also:
-
tolerance
private double toleranceTolerance to find a root. Whenever the variation of the estimated root is smaller than the provided tolerance, then the algorithm is assumed to be converged.
-
-
Constructor Details
-
FalsePositionSingleRootEstimator
public FalsePositionSingleRootEstimator()Empty constructor. -
FalsePositionSingleRootEstimator
public FalsePositionSingleRootEstimator(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 find a root. During the estimation of a root, if the variation of the estimated root is smaller than the provided tolerance, then the algorithm is assumed to be converged, and the root is ensured to have an accuracy that equals tolerance.- Throws:
InvalidBracketRangeException
- Raised if minEvalPoint < maxEvalPoint.IllegalArgumentException
- Raised if provided tolerance is negative.
-
-
Method Details
-
getTolerance
public double getTolerance()Returns tolerance to find a root. Whenever the variation of the estimated root is smaller than returned tolerance, then the algorithm is assumed to be converged, and the estimated root is ensured to have an accuracy that equals the returned tolerance.- Returns:
- Tolerance to find a root.
-
setTolerance
Sets tolerance to find a root. Whenever the variation of the estimated root is smaller than provided tolerance, then the algorithm is assumed to be converged, and the estimated root is ensured to have an accuracy that equals provided tolerance.- Parameters:
tolerance
- Tolerance to find a root.- Throws:
LockedException
- Raised if this instance is locked while doing some computations.IllegalArgumentException
- Raised if provided tolerance is negative.
-
estimate
Estimates a single root of the provided single dimension function contained within a given bracket of values.- Overrides:
estimate
in classRootEstimator
- Throws:
LockedException
- Exception raised if this instance is already locked.NotReadyException
- Exception raised if not enough parameters have been provided in order to start the estimation.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 compute a root. This instance is ready as soon as a listener is provided and a bracket is provided or computed.- Overrides:
isReady
in classSingleRootEstimator
- Returns:
- True if instance is ready, false otherwise
-
internalSetTolerance
private void internalSetTolerance(double tolerance) Internal method to set tolerance to find a root. This method does not check whether this instance is locked. Whenever the variation of the estimated root is smaller than provided tolerance, then the algorithm is assumed to be converged, and the estimated root is ensured to have an accuracy that equals provided tolerance.- Parameters:
tolerance
- Tolerance to find a root.- Throws:
IllegalArgumentException
- Raised if provided tolerance is negative.
-