commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1365963 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/univariate/BrentOptimizerTest.java
Date Thu, 26 Jul 2012 12:25:06 GMT
Author: erans
Date: Thu Jul 26 12:25:06 2012
New Revision: 1365963

URL: http://svn.apache.org/viewvc?rev=1365963&view=rev
Log:
MATH-832
Unit test (showing that the report is invalid).

Modified:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/univariate/BrentOptimizerTest.java

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/univariate/BrentOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/univariate/BrentOptimizerTest.java?rev=1365963&r1=1365962&r2=1365963&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/univariate/BrentOptimizerTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/optimization/univariate/BrentOptimizerTest.java
Thu Jul 26 12:25:06 2012
@@ -26,6 +26,7 @@ import org.apache.commons.math3.analysis
 import org.apache.commons.math3.optimization.GoalType;
 import org.apache.commons.math3.optimization.ConvergenceChecker;
 import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
+import org.apache.commons.math3.util.FastMath;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -157,4 +158,27 @@ public final class BrentOptimizerTest {
         result = optimizer.optimize(50, f, GoalType.MINIMIZE, 4, 3 * Math.PI / 2).getPoint();
         Assert.assertEquals(3 * Math.PI / 2, result, 1e-6);
     }
+
+    @Test
+    public void testMath832() {
+        final UnivariateFunction f = new UnivariateFunction() {
+                public double value(double x) {
+                    final double sqrtX = FastMath.sqrt(x);
+                    final double a = 1e2 * sqrtX;
+                    final double b = 1e6 / x;
+                    final double c = 1e4 / sqrtX;
+
+                    return a + b + c;
+                }
+            };
+
+        UnivariateOptimizer optimizer = new BrentOptimizer(1e-10, 1e-8);
+        final double result = optimizer.optimize(1483,
+                                                 f,
+                                                 GoalType.MINIMIZE,
+                                                 Double.MIN_VALUE,
+                                                 Double.MAX_VALUE).getPoint();
+
+        Assert.assertEquals(804.9355825, result, 1e-6);
+    }
 }



Mime
View raw message