public class UnivariateSolverUtils extends Object
UnivariateSolver objects.| Modifier and Type | Method and Description |
|---|---|
static double[] |
bracket(UnivariateFunction function,
double initial,
double lowerBound,
double upperBound)
This method attempts to find two values a and b satisfying
lowerBound <= a < initial < b <= upperBound
f(a) * f(b) < 0
If f is continuous on [a,b], this means that a
and b bracket a root of f. |
static double[] |
bracket(UnivariateFunction function,
double initial,
double lowerBound,
double upperBound,
int maximumIterations)
This method attempts to find two values a and b satisfying
lowerBound <= a < initial < b <= upperBound
f(a) * f(b) <= 0
If f is continuous on [a,b], this means that a
and b bracket a root of f. |
static double |
forceSide(int maxEval,
UnivariateFunction f,
BracketedUnivariateSolver<UnivariateFunction> bracketing,
double baseRoot,
double min,
double max,
AllowedSolution allowedSolution)
Force a root found by a non-bracketing solver to lie on a specified side,
as if the solver was a bracketing one.
|
static boolean |
isBracketing(UnivariateFunction function,
double lower,
double upper)
Check whether the interval bounds bracket a root.
|
static boolean |
isSequence(double start,
double mid,
double end)
Check whether the arguments form a (strictly) increasing sequence.
|
static double |
midpoint(double a,
double b)
Compute the midpoint of two values.
|
static double |
solve(UnivariateFunction function,
double x0,
double x1)
Convenience method to find a zero of a univariate real function.
|
static double |
solve(UnivariateFunction function,
double x0,
double x1,
double absoluteAccuracy)
Convenience method to find a zero of a univariate real function.
|
static void |
verifyBracketing(UnivariateFunction function,
double lower,
double upper)
Check that the endpoints specify an interval and the end points
bracket a root.
|
static void |
verifyInterval(double lower,
double upper)
Check that the endpoints specify an interval.
|
static void |
verifySequence(double lower,
double initial,
double upper)
Check that
lower < initial < upper. |
public static double solve(UnivariateFunction function, double x0, double x1)
function - Function.x0 - Lower bound for the interval.x1 - Upper bound for the interval.IllegalArgumentException - if f is null or the endpoints do not
specify a valid interval.public static double solve(UnivariateFunction function, double x0, double x1, double absoluteAccuracy)
function - Function.x0 - Lower bound for the interval.x1 - Upper bound for the interval.absoluteAccuracy - Accuracy to be used by the solver.IllegalArgumentException - if function is null,
the endpoints do not specify a valid interval, or the absolute accuracy
is not valid for the default solver.public static double forceSide(int maxEval,
UnivariateFunction f,
BracketedUnivariateSolver<UnivariateFunction> bracketing,
double baseRoot,
double min,
double max,
AllowedSolution allowedSolution)
maxEval - maximal number of new evaluations of the function
(evaluations already done for finding the root should have already been subtracted
from this number)f - function to solvebracketing - bracketing solver to use for shifting the rootbaseRoot - original root found by a previous non-bracketing solvermin - minimal bound of the search intervalmax - maximal bound of the search intervalallowedSolution - the kind of solutions that the root-finding algorithm may
accept as solutions.public static double[] bracket(UnivariateFunction function, double initial, double lowerBound, double upperBound)
lowerBound <= a < initial < b <= upperBound f(a) * f(b) < 0 [a,b], this means that a
and b bracket a root of f.
The algorithm starts by setting
a := initial -1; b := initial +1, examines the value of the
function at a and b and keeps moving
the endpoints out by one unit each time through a loop that terminates
when one of the following happens:
f(a) * f(b) < 0 -- success! a = lower and b = upper
-- NoBracketingException Integer.MAX_VALUE iterations elapse
-- NoBracketingException
Note: this method can take
Integer.MAX_VALUE iterations to throw a
ConvergenceException. Unless you are confident that there
is a root between lowerBound and upperBound
near initial, it is better to use
bracket(UnivariateFunction, double, double, double, int),
explicitly specifying the maximum number of iterations.
function - Function.initial - Initial midpoint of interval being expanded to
bracket a root.lowerBound - Lower bound (a is never lower than this value)upperBound - Upper bound (b never is greater than this
value).NoBracketingException - if a root cannot be bracketted.IllegalArgumentException - if function is null, maximumIterations
is not positive, or initial is not between lowerBound and upperBound.public static double[] bracket(UnivariateFunction function, double initial, double lowerBound, double upperBound, int maximumIterations)
lowerBound <= a < initial < b <= upperBound f(a) * f(b) <= 0 [a,b], this means that a
and b bracket a root of f.
The algorithm starts by setting
a := initial -1; b := initial +1, examines the value of the
function at a and b and keeps moving
the endpoints out by one unit each time through a loop that terminates
when one of the following happens:
f(a) * f(b) <= 0 -- success! a = lower and b = upper
-- NoBracketingException maximumIterations iterations elapse
-- NoBracketingException function - Function.initial - Initial midpoint of interval being expanded to
bracket a root.lowerBound - Lower bound (a is never lower than this value).upperBound - Upper bound (b never is greater than this
value).maximumIterations - Maximum number of iterations to performNoBracketingException - if the algorithm fails to find a and b
satisfying the desired conditions.IllegalArgumentException - if function is null, maximumIterations
is not positive, or initial is not between lowerBound and upperBound.public static double midpoint(double a,
double b)
a - first value.b - second value.public static boolean isBracketing(UnivariateFunction function, double lower, double upper)
function - Function.lower - Lower endpoint.upper - Upper endpoint.true if the function values have opposite signs at the
given points.public static boolean isSequence(double start,
double mid,
double end)
start - First number.mid - Second number.end - Third number.true if the arguments form an increasing sequence.public static void verifyInterval(double lower,
double upper)
lower - Lower endpoint.upper - Upper endpoint.NumberIsTooLargeException - if lower >= upper.public static void verifySequence(double lower,
double initial,
double upper)
lower < initial < upper.lower - Lower endpoint.initial - Initial value.upper - Upper endpoint.NumberIsTooLargeException - if lower >= initial or
initial >= upper.public static void verifyBracketing(UnivariateFunction function, double lower, double upper)
function - Function.lower - Lower endpoint.upper - Upper endpoint.NoBracketingException - if function has the same sign at the
endpoints.Copyright © 2003-2012 The Apache Software Foundation. All Rights Reserved.