You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2012/07/26 15:29:56 UTC

svn commit: r1365984 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/solvers/BrentSolverTest.java

Author: erans
Date: Thu Jul 26 13:29:56 2012
New Revision: 1365984

URL: http://svn.apache.org/viewvc?rev=1365984&view=rev
Log:
MATH-832
Unit test showing that the issue is invalid: For the function referred to in
the JIRA ticket, "BrentSolver" and "BrentOptimizer" agree: the same value is
found to be the minimum of the function and the root of the function's
derivative.

Modified:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/solvers/BrentSolverTest.java

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/solvers/BrentSolverTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/solvers/BrentSolverTest.java?rev=1365984&r1=1365983&r2=1365984&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/solvers/BrentSolverTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/solvers/BrentSolverTest.java Thu Jul 26 13:29:56 2012
@@ -20,6 +20,11 @@ import org.apache.commons.math3.analysis
 import org.apache.commons.math3.analysis.QuinticFunction;
 import org.apache.commons.math3.analysis.SinFunction;
 import org.apache.commons.math3.analysis.UnivariateFunction;
+import org.apache.commons.math3.analysis.DifferentiableUnivariateFunction;
+import org.apache.commons.math3.analysis.FunctionUtils;
+import org.apache.commons.math3.analysis.function.Sqrt;
+import org.apache.commons.math3.analysis.function.Inverse;
+import org.apache.commons.math3.analysis.function.Constant;
 import org.apache.commons.math3.util.FastMath;
 import org.apache.commons.math3.exception.NumberIsTooLargeException;
 import org.apache.commons.math3.exception.NoBracketingException;
@@ -237,4 +242,31 @@ public final class BrentSolverTest {
         Assert.assertEquals(1, solver.getEvaluations());
         Assert.assertEquals(1, f.getCallsCount());
     }
+
+    @Test
+    public void testMath832() {
+        final DifferentiableUnivariateFunction f = new DifferentiableUnivariateFunction() {
+                private final DifferentiableUnivariateFunction sqrt = new Sqrt();
+                private final DifferentiableUnivariateFunction inv = new Inverse();
+                private final DifferentiableUnivariateFunction func
+                    = FunctionUtils.add(FunctionUtils.multiply(new Constant(1e2), sqrt),
+                                        FunctionUtils.multiply(new Constant(1e6), inv),
+                                        FunctionUtils.multiply(new Constant(1e4),
+                                                               FunctionUtils.compose(inv, sqrt)));
+
+                public double value(double x) {
+                    return func.value(x);
+                }
+
+                public UnivariateFunction derivative() {
+                    return func.derivative();
+                }
+            };
+
+        BrentSolver solver = new BrentSolver();
+        final double result = solver.solve(99,
+                                           f.derivative(),
+                                           1, 1e30, 1 + 1e-10);
+        Assert.assertEquals(804.93558250, result, 1e-8);
+    }
 }