public class UnivariateRealSolverUtils
extends java.lang.Object
UnivariateRealSolver
objects.Modifier and Type | Method and Description |
---|---|
static double[] |
bracket(UnivariateRealFunction 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(UnivariateRealFunction 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 |
midpoint(double a,
double b)
Compute the midpoint of two values.
|
static double |
solve(UnivariateRealFunction f,
double x0,
double x1)
Convenience method to find a zero of a univariate real function.
|
static double |
solve(UnivariateRealFunction f,
double x0,
double x1,
double absoluteAccuracy)
Convenience method to find a zero of a univariate real function.
|
public static double solve(UnivariateRealFunction f, double x0, double x1) throws ConvergenceException, FunctionEvaluationException
f
- the function.x0
- the lower bound for the interval.x1
- the upper bound for the interval.ConvergenceException
- if the iteration count was exceededFunctionEvaluationException
- if an error occurs evaluating the functionjava.lang.IllegalArgumentException
- if f is null or the endpoints do not
specify a valid intervalpublic static double solve(UnivariateRealFunction f, double x0, double x1, double absoluteAccuracy) throws ConvergenceException, FunctionEvaluationException
f
- the functionx0
- the lower bound for the intervalx1
- the upper bound for the intervalabsoluteAccuracy
- the accuracy to be used by the solverConvergenceException
- if the iteration count is exceededFunctionEvaluationException
- if an error occurs evaluating the functionjava.lang.IllegalArgumentException
- if f is null, the endpoints do not
specify a valid interval, or the absoluteAccuracy is not valid for the
default solverpublic static double[] bracket(UnivariateRealFunction function, double initial, double lowerBound, double upperBound) throws ConvergenceException, FunctionEvaluationException
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
-- ConvergenceException Integer.MAX_VALUE
iterations elapse
-- ConvergenceException
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(UnivariateRealFunction, double, double, double, int)
,
explicitly specifying the maximum number of iterations.
function
- the functioninitial
- initial midpoint of interval being expanded to
bracket a rootlowerBound
- lower bound (a is never lower than this value)upperBound
- upper bound (b never is greater than this
value)ConvergenceException
- if a root can not be brackettedFunctionEvaluationException
- if an error occurs evaluating the functionjava.lang.IllegalArgumentException
- if function is null, maximumIterations
is not positive, or initial is not between lowerBound and upperBoundpublic static double[] bracket(UnivariateRealFunction function, double initial, double lowerBound, double upperBound, int maximumIterations) throws ConvergenceException, FunctionEvaluationException
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
-- ConvergenceException maximumIterations
iterations elapse
-- ConvergenceException function
- the functioninitial
- initial midpoint of interval being expanded to
bracket a rootlowerBound
- 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 performConvergenceException
- if the algorithm fails to find a and b
satisfying the desired conditionsFunctionEvaluationException
- if an error occurs evaluating the functionjava.lang.IllegalArgumentException
- if function is null, maximumIterations
is not positive, or initial is not between lowerBound and upperBoundpublic static double midpoint(double a, double b)
a
- first value.b
- second value."Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"