commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r1144887 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
Date Sun, 10 Jul 2011 16:04:51 GMT
Author: luc
Date: Sun Jul 10 16:04:51 2011
New Revision: 1144887

URL: http://svn.apache.org/viewvc?rev=1144887&view=rev
Log:
prevent root bracketing to be attempted outside of search interval

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java?rev=1144887&r1=1144886&r2=1144887&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
Sun Jul 10 16:04:51 2011
@@ -104,14 +104,14 @@ public class UnivariateRealSolverUtils {
         // find a very small interval bracketing the root
         final double step = FastMath.max(bracketing.getAbsoluteAccuracy(),
                                          FastMath.abs(baseRoot * bracketing.getRelativeAccuracy()));
-        double xLo        = baseRoot - step;
+        double xLo        = FastMath.max(min, baseRoot - step);
         double fLo        = f.value(xLo);
-        double xHi        = baseRoot + step;
+        double xHi        = FastMath.min(max, baseRoot + step);
         double fHi        = f.value(xHi);
         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
                 return bracketing.solve(remainingEval, f, xLo, xHi, baseRoot, allowedSolutions);
             }
@@ -141,14 +141,14 @@ public class UnivariateRealSolverUtils {
 
             // update the lower bound
             if (changeLo) {
-                xLo -= step;
+                xLo = FastMath.max(min, xLo - step);
                 fLo  = f.value(xLo);
                 remainingEval--;
             }
 
             // update the higher bound
             if (changeHi) {
-                xHi += step;
+                xHi = FastMath.min(max, xHi + step);
                 fHi  = f.value(xHi);
                 remainingEval--;
             }



Mime
View raw message