Package jsl.utilities.rootfinding
Class IPRootFinder
- java.lang.Object
-
- jsl.simulation.IterativeProcess<RootFinderStep>
-
- jsl.utilities.rootfinding.IPRootFinder
-
- All Implemented Interfaces:
ObservableIfc
,IterativeProcessIfc
,GetNameIfc
- Direct Known Subclasses:
IPBisectionRootFinder
,StochasticApproximationRootFinder
public abstract class IPRootFinder extends IterativeProcess<RootFinderStep>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jsl.simulation.IterativeProcess
IterativeProcess.Created, IterativeProcess.Ended, IterativeProcess.Initialized, IterativeProcess.IterativeState, IterativeProcess.ShowElapsedTimeTask, IterativeProcess.StepCompleted
-
-
Field Summary
Fields Modifier and Type Field Description protected FunctionIfc
f
Function for which the zero should be found.protected double
myInitialPt
The initial point for the searchprotected Interval
myInterval
The interval for the searchprotected int
myMaxIterations
The maximum number of iterations permitted to find the root The default is 100protected static int
numIterations
Used in the static methods for finding intervalsprotected static double
searchFactor
used in the static methods for finding intervals-
Fields inherited from class jsl.simulation.IterativeProcess
COMPLETED_ALL_STEPS, COMPLETED_ALL_STEPS_MSG, EXCEEDED_EXECUTION_TIME, EXCEEDED_EXECUTION_TIME_MSG, MET_STOPPING_CONDITION, MET_STOPPING_CONDITION_MSG, myBeginExecutionTime, myCreatedState, myCurrentStep, myDoneFlag, myEndedState, myEndExecutionTime, myEndingStateIndicator, myId, myInitFlag, myInitializedState, myIPLogReport, myMaxAllowedExecutionTime, myName, myObservableComponent, myRunningFlag, myRunningStepFlag, mySaveStepOption, myState, myStepCompletedState, myStepCounter, mySteps, myTBConsoleUpdates, myTimer, myTimerTask, NO_STEPS_EXECUTED, NO_STEPS_EXECUTED_MSG, UNFINISHED, UNFINISHED_MSG
-
-
Constructor Summary
Constructors Constructor Description IPRootFinder(FunctionIfc func, double xLower, double xUpper)
Defines a function and an interval for searching for a rootIPRootFinder(FunctionIfc func, Interval interval)
Defines a function and an interval for searching for a root
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
contains(double x)
Checks to see if the the supplied point is within the search intervalstatic boolean
findInterval(FunctionIfc func, Interval interval)
Using the supplied function and the initial interval provided, try to find a bracketing interval by expanding the interval outwardstatic java.util.List<Interval>
findInterval(FunctionIfc func, Interval interval, int n, int nmax)
Given a function and a starting interval, subdivide the interval into n subintervals and attempt to find nmax bracketing intervals that contain rootsdouble
getFunctionAtRoot()
Returns the value of the function at the last considered possible root of the functiondouble
getInitialPoint()
Returns the initial point used for the searchdouble
getLowerLimit()
The lower limit for the search intervalint
getMaxIterations()
double
getRoot()
Returns the last evaluated value that was considered for the root of the functiondouble
getUpperLimit()
The upper limit for the search intervalabstract boolean
hasConverged()
Check to see if the result has been attained.boolean
hasIterations()
Returns true if the number of iterations is < max iterationsboolean
hasRoot(double xLower, double xUpper)
Returns true if the supplied interval contains a rootboolean
hasRoot(Interval interval)
Returns true if the supplied interval contains a rootstatic boolean
hasRoot(FunctionIfc func, double xLower, double xUpper)
Returns true if the supplied interval contains a rootdouble
recommendInitialPoint()
Enumerates equally spaced points in the interval and returns the point that has the function value closest to zerodouble
recommendInitialPoint(int nmax)
Enumerates nmax equally spaced points in the interval and returns the point that has the function value closest to zerodouble
relativePrecision(double epsilon)
double
relativePrecision(double epsilon, double x)
protected void
setFunction(FunctionIfc func)
void
setInitialPoint(double initialPt)
Sets the initial starting point for the search.void
setInterval(double xLower, double xUpper)
Sets the bracketing interval within which the root should be found.void
setInterval(Interval interval)
Sets the search interval for the searchvoid
setInterval(FunctionIfc func, double xLower, double xUpper)
Sets the bracketing interval within which the root should be found.void
setInterval(FunctionIfc func, Interval interval)
Sets the bracketing interval within which the root should be found.void
setMaxIterations(int maxIterations)
protected void
setRoot(double x)
java.lang.String
toString()
Returns a String representation of the finder-
Methods inherited from class jsl.simulation.IterativeProcess
addObserver, allStepsCompleted, checkStoppingCondition, checkStoppingCondition_, consoleOutput, contains, countObservers, deleteObserver, deleteObservers, end, end, endIterations, executionTimeExceeded, getBeginExecutionTime, getCurrentStateAsString, getCurrentStep, getElapsedExecutionTime, getEndExecutionTime, getEndingStateIndicator, getEndingStateIndicatorAsString, getId, getLogReport, getMaximumAllowedExecutionTime, getName, getNumberStepsCompleted, getSaveStepOption, getStepIterator, getStepList, getStoppingFlag, getStoppingMessage, hasNext, initialize, initializeIterations, isCreated, isDone, isEnded, isExecutionTimeExceeded, isInitialized, isRunning, isRunningStep, isStepCompleted, isUnfinished, next, noStepsExecuted, run, runAll_, runNext, runNext_, runStep, setId, setMaximumExecutionTime, setName, setSaveStepOption, setState, stop, stop, stoppedByCondition, turnOffLogReport, turnOnLogReport, turnOnTimer
-
-
-
-
Field Detail
-
f
protected FunctionIfc f
Function for which the zero should be found.
-
myInterval
protected Interval myInterval
The interval for the search
-
myInitialPt
protected double myInitialPt
The initial point for the search
-
myMaxIterations
protected int myMaxIterations
The maximum number of iterations permitted to find the root The default is 100
-
numIterations
protected static int numIterations
Used in the static methods for finding intervals
-
searchFactor
protected static double searchFactor
used in the static methods for finding intervals
-
-
Constructor Detail
-
IPRootFinder
public IPRootFinder(FunctionIfc func, Interval interval)
Defines a function and an interval for searching for a root- Parameters:
func
- must not be null, must have a root in the intervalinterval
-
-
IPRootFinder
public IPRootFinder(FunctionIfc func, double xLower, double xUpper)
Defines a function and an interval for searching for a root- Parameters:
func
- must not be null, must have a root in the intervalxLower
- must be less than xUpperxUpper
- must be greater than xLower
-
-
Method Detail
-
getRoot
public double getRoot()
Returns the last evaluated value that was considered for the root of the function
-
getFunctionAtRoot
public double getFunctionAtRoot()
Returns the value of the function at the last considered possible root of the function- Returns:
-
relativePrecision
public double relativePrecision(double epsilon)
- Parameters:
epsilon
- double- Returns:
- double
-
relativePrecision
public double relativePrecision(double epsilon, double x)
- Parameters:
epsilon
- doublex
- double- Returns:
- double
-
getMaxIterations
public int getMaxIterations()
- Returns:
- the maximum number of iterations
-
setMaxIterations
public void setMaxIterations(int maxIterations)
- Parameters:
maxIterations
- the maximum number of iterations
-
hasIterations
public boolean hasIterations()
Returns true if the number of iterations is < max iterations- Returns:
-
hasRoot
public final boolean hasRoot(Interval interval)
Returns true if the supplied interval contains a root- Parameters:
interval
-- Returns:
-
hasRoot
public boolean hasRoot(double xLower, double xUpper)
Returns true if the supplied interval contains a root- Parameters:
xLower
-xUpper
-- Returns:
-
hasRoot
public static boolean hasRoot(FunctionIfc func, double xLower, double xUpper)
Returns true if the supplied interval contains a root- Parameters:
func
-xLower
-xUpper
-- Returns:
-
findInterval
public static boolean findInterval(FunctionIfc func, Interval interval)
Using the supplied function and the initial interval provided, try to find a bracketing interval by expanding the interval outward- Parameters:
func
-interval
-- Returns:
-
findInterval
public static java.util.List<Interval> findInterval(FunctionIfc func, Interval interval, int n, int nmax)
Given a function and a starting interval, subdivide the interval into n subintervals and attempt to find nmax bracketing intervals that contain roots- Parameters:
func
-interval
-n
-nmax
-- Returns:
- The list of bracketing intervals
-
setInterval
public final void setInterval(Interval interval)
Sets the search interval for the search- Parameters:
interval
-
-
setInterval
public void setInterval(double xLower, double xUpper)
Sets the bracketing interval within which the root should be found. Throws IllegalArgumentExceptons if the lower limit is > upper limit and if the function does not cross the axis within the provided interval.- Parameters:
xLower
-xUpper
-
-
getInitialPoint
public double getInitialPoint()
Returns the initial point used for the search- Returns:
-
setInitialPoint
public void setInitialPoint(double initialPt)
Sets the initial starting point for the search. The starting point must be in the interval defined for the search or an IllegalArgumentException will be thrown.- Parameters:
initialPt
-
-
recommendInitialPoint
public double recommendInitialPoint()
Enumerates equally spaced points in the interval and returns the point that has the function value closest to zero- Returns:
-
recommendInitialPoint
public double recommendInitialPoint(int nmax)
Enumerates nmax equally spaced points in the interval and returns the point that has the function value closest to zero- Parameters:
nmax
-- Returns:
-
contains
public final boolean contains(double x)
Checks to see if the the supplied point is within the search interval- Parameters:
x
-- Returns:
-
getLowerLimit
public final double getLowerLimit()
The lower limit for the search interval- Returns:
-
getUpperLimit
public final double getUpperLimit()
The upper limit for the search interval- Returns:
-
setInterval
public final void setInterval(FunctionIfc func, Interval interval)
Sets the bracketing interval within which the root should be found. Throws IllegalArgumentExceptons if the lower limit is > upper limit and if the function does not cross the axis within the provided interval.- Parameters:
func
-interval
-
-
setInterval
public final void setInterval(FunctionIfc func, double xLower, double xUpper)
Sets the bracketing interval within which the root should be found. Throws IllegalArgumentExceptons if the lower limit is > upper limit and if the function does not cross the axis within the provided interval.- Parameters:
func
- Sets the function to be evaluated, must not be nullxLower
-xUpper
-
-
toString
public java.lang.String toString()
Returns a String representation of the finder- Overrides:
toString
in classIterativeProcess<RootFinderStep>
- Returns:
- A String with basic results
-
setFunction
protected void setFunction(FunctionIfc func)
- Parameters:
func
- OneVariableFunction
-
setRoot
protected void setRoot(double x)
-
hasConverged
public abstract boolean hasConverged()
Check to see if the result has been attained.- Returns:
- boolean
-
-