Package jsl.utilities.rootfinding
Class RootFinder
- java.lang.Object
-
- jsl.utilities.math.DBHIterativeProcess
-
- jsl.utilities.math.FunctionalIterator
-
- jsl.utilities.rootfinding.RootFinder
-
- Direct Known Subclasses:
BisectionRootFinder
public abstract class RootFinder extends FunctionalIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected double
fNeg
The value of the function at xNegprotected double
fPos
The value of the function at xPosprotected double
myInitialPt
The initial point for the searchprotected Interval
myInterval
The interval for the searchprotected static int
numIterations
Used in the static methods for finding intervalsprotected static double
searchFactor
used in the static methods for finding intervalsprotected double
xNeg
Value at which the function's value is negative.protected double
xPos
Value at which the function's value is positive.-
Fields inherited from class jsl.utilities.math.FunctionalIterator
f, result
-
-
Constructor Summary
Constructors Constructor Description RootFinder()
RootFinder(FunctionIfc func, double xLower, double xUpper)
RootFinder(FunctionIfc func, Interval interval)
-
Method Summary
All Methods Static Methods Instance 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
getLowerLimit()
The lower limit for the search intervaldouble
getUpperLimit()
The upper limit for the search intervalboolean
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 rootvoid
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.java.lang.String
toString()
Returns a String representation of the finder-
Methods inherited from class jsl.utilities.math.FunctionalIterator
getResult, relativePrecision, setFunction
-
Methods inherited from class jsl.utilities.math.DBHIterativeProcess
evaluate, evaluateIteration, finalizeIterations, getDesiredPrecision, getIterations, getMaximumIterations, getPrecision, hasConverged, initializeIterations, relativePrecision, setDesiredPrecision, setMaximumIterations
-
-
-
-
Field Detail
-
xNeg
protected double xNeg
Value at which the function's value is negative.
-
xPos
protected double xPos
Value at which the function's value is positive.
-
fNeg
protected double fNeg
The value of the function at xNeg
-
fPos
protected double fPos
The value of the function at xPos
-
myInterval
protected Interval myInterval
The interval for the search
-
myInitialPt
protected double myInitialPt
The initial point for the search
-
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
-
RootFinder
public RootFinder()
-
RootFinder
public RootFinder(FunctionIfc func, Interval interval)
-
RootFinder
public RootFinder(FunctionIfc func, double xLower, double xUpper)
-
-
Method Detail
-
toString
public java.lang.String toString()
Returns a String representation of the finder- Overrides:
toString
in classjava.lang.Object
- Returns:
- A String with basic results
-
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
-
-
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
-
-
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
-
-
-