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
This commit is contained in:
Gilles Sadowski 2012-07-26 13:29:56 +00:00
parent 0062503cf9
commit b451fdc8e4
1 changed files with 32 additions and 0 deletions

View File

@ -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);
}
}