BracketingNthOrderBrentSolver extends AbstractUnivariateSolver implements BracketedUnivariateSolver<UnivariateFunction> { public double solve(int maxEval, UnivariateFunction f, double min, double max, AllowedSolution allowedSolution) throws TooManyEvaluationsException, NumberIsTooLargeException, NoBracketingException { this.allowed = allowedSolution; return super.solve(maxEval, f, min, max); } BracketingNthOrderBrentSolver();  BracketingNthOrderBrentSolver(final double absoluteAccuracy,
                                         final int maximalOrder);  BracketingNthOrderBrentSolver(final double relativeAccuracy,
                                         final double absoluteAccuracy,
                                         final int maximalOrder);  BracketingNthOrderBrentSolver(final double relativeAccuracy,
                                         final double absoluteAccuracy,
                                         final double functionValueAccuracy,
                                         final int maximalOrder); int getMaximalOrder(); double solve(int maxEval, UnivariateFunction f, double min,
                        double max, AllowedSolution allowedSolution); double solve(int maxEval, UnivariateFunction f, double min,
                        double max, double startValue,
                        AllowedSolution allowedSolution);  }
@Test public void testConvergenceOnFunctionAccuracy() { BracketingNthOrderBrentSolver solver = new BracketingNthOrderBrentSolver(1.0e-12, 1.0e-10, 0.001, 3); QuinticFunction f = new QuinticFunction(); double result = solver.solve(20, f, 0.2, 0.9, 0.4, AllowedSolution.BELOW_SIDE); Assert.assertEquals(0, f.value(result), solver.getFunctionValueAccuracy()); Assert.assertTrue(f.value(result) <= 0); Assert.assertTrue(result - 0.5 > solver.getAbsoluteAccuracy()); result = solver.solve(20, f, -0.9, -0.2, -0.4, AllowedSolution.ABOVE_SIDE); Assert.assertEquals(0, f.value(result), solver.getFunctionValueAccuracy()); Assert.assertTrue(f.value(result) >= 0); Assert.assertTrue(result + 0.5 < -solver.getAbsoluteAccuracy()); }
@Test public void testIssue716() { BracketingNthOrderBrentSolver solver = new BracketingNthOrderBrentSolver(1.0e-12, 1.0e-10, 1.0e-22, 5); UnivariateFunction sharpTurn = new UnivariateFunction() { public double value(double x) { return (2 * x + 1) / (1.0e9 * (x + 1)); } }; double result = solver.solve(100, sharpTurn, -0.9999999, 30, 15, AllowedSolution.RIGHT_SIDE); Assert.assertEquals(0, sharpTurn.value(result), solver.getFunctionValueAccuracy()); Assert.assertTrue(sharpTurn.value(result) >= 0); Assert.assertEquals(-0.5, result, 1.0e-10); }