Skip to content

Commit

Permalink
fixed files form Math #97
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Mar 7, 2017
1 parent dcdbb53 commit d04802c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions projects/Math/97/org/apache/commons/math/analysis/BrentSolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,31 @@ public double solve(double min, double max) throws MaxIterationsExceededExceptio

// Verify bracketing
double sign = yMin * yMax;
if (sign >= 0) {
if (sign > 0) {
// check if either value is close to a zero
if (Math.abs(yMin) <= functionValueAccuracy) {
setResult(min, 0);
ret = min;
} else if (Math.abs(yMax) <= functionValueAccuracy) {
setResult(max, 0);
ret = max;
} else {
// neither value is close to zero and min and max do not bracket root.
throw new IllegalArgumentException
("Function values at endpoints do not have different signs." +
" Endpoints: [" + min + "," + max + "]" +
" Values: [" + yMin + "," + yMax + "]");
} else {
}
} else if (sign < 0){
// solve using only the first endpoint as initial guess
ret = solve(min, yMin, max, yMax, min, yMin);
} else {
// either min or max is a root
if (yMin == 0.0) {
ret = min;
} else {
ret = max;
}
}

return ret;
Expand Down

0 comments on commit d04802c

Please sign in to comment.