From b451fdc8e47d231c7f29c74aa5b9f7a7d0e50c9e Mon Sep 17 00:00:00 2001 From: Gilles Sadowski Date: Thu, 26 Jul 2012 13:29:56 +0000 Subject: [PATCH] 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. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1365984 13f79535-47bb-0310-9956-ffa450edef68 --- .../analysis/solvers/BrentSolverTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/test/java/org/apache/commons/math3/analysis/solvers/BrentSolverTest.java b/src/test/java/org/apache/commons/math3/analysis/solvers/BrentSolverTest.java index cdc7da518..212ecb7a5 100644 --- a/src/test/java/org/apache/commons/math3/analysis/solvers/BrentSolverTest.java +++ b/src/test/java/org/apache/commons/math3/analysis/solvers/BrentSolverTest.java @@ -20,6 +20,11 @@ import org.apache.commons.math3.analysis.MonitoredFunction; 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); + } }