prevent root bracketing to be attempted outside of search interval
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1144887 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fef1366f09
commit
f31af98c0d
|
@ -104,14 +104,14 @@ public class UnivariateRealSolverUtils {
|
||||||
// find a very small interval bracketing the root
|
// find a very small interval bracketing the root
|
||||||
final double step = FastMath.max(bracketing.getAbsoluteAccuracy(),
|
final double step = FastMath.max(bracketing.getAbsoluteAccuracy(),
|
||||||
FastMath.abs(baseRoot * bracketing.getRelativeAccuracy()));
|
FastMath.abs(baseRoot * bracketing.getRelativeAccuracy()));
|
||||||
double xLo = baseRoot - step;
|
double xLo = FastMath.max(min, baseRoot - step);
|
||||||
double fLo = f.value(xLo);
|
double fLo = f.value(xLo);
|
||||||
double xHi = baseRoot + step;
|
double xHi = FastMath.min(max, baseRoot + step);
|
||||||
double fHi = f.value(xHi);
|
double fHi = f.value(xHi);
|
||||||
int remainingEval = maxEval - 2;
|
int remainingEval = maxEval - 2;
|
||||||
while ((remainingEval > 0) && (xLo >= min) && (xHi <= max)) {
|
while (remainingEval > 0) {
|
||||||
|
|
||||||
if ((fLo > 0 && fHi < 0) || (fLo < 0 && fHi > 0)) {
|
if ((fLo >= 0 && fHi <= 0) || (fLo <= 0 && fHi >= 0)) {
|
||||||
// compute the root on the selected side
|
// compute the root on the selected side
|
||||||
return bracketing.solve(remainingEval, f, xLo, xHi, baseRoot, allowedSolutions);
|
return bracketing.solve(remainingEval, f, xLo, xHi, baseRoot, allowedSolutions);
|
||||||
}
|
}
|
||||||
|
@ -141,14 +141,14 @@ public class UnivariateRealSolverUtils {
|
||||||
|
|
||||||
// update the lower bound
|
// update the lower bound
|
||||||
if (changeLo) {
|
if (changeLo) {
|
||||||
xLo -= step;
|
xLo = FastMath.max(min, xLo - step);
|
||||||
fLo = f.value(xLo);
|
fLo = f.value(xLo);
|
||||||
remainingEval--;
|
remainingEval--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the higher bound
|
// update the higher bound
|
||||||
if (changeHi) {
|
if (changeHi) {
|
||||||
xHi += step;
|
xHi = FastMath.min(max, xHi + step);
|
||||||
fHi = f.value(xHi);
|
fHi = f.value(xHi);
|
||||||
remainingEval--;
|
remainingEval--;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue