@Test public void testConvergenceOnFunctionAccuracy() { BracketingNthOrderBrentSolverDFP solver = new BracketingNthOrderBrentSolverDFP( relativeAccuracy, absoluteAccuracy, field.newDfp(1.0e-20), 20); UnivariateDfpFunction f = new UnivariateDfpFunction() { public Dfp value(Dfp x) { Dfp one = field.getOne(); Dfp oneHalf = one.divide(2); Dfp xMo = x.subtract(one); Dfp xMh = x.subtract(oneHalf); Dfp xPh = x.add(oneHalf); Dfp xPo = x.add(one); return xMo.multiply(xMh).multiply(x).multiply(xPh).multiply(xPo); } }; Dfp result = solver.solve( 20, f, field.newDfp(0.2), field.newDfp(0.9), field.newDfp(0.4), AllowedSolution.BELOW_SIDE); Assert.assertTrue(f.value(result).abs().lessThan(solver.getFunctionValueAccuracy())); Assert.assertTrue(f.value(result).negativeOrNull()); Assert.assertTrue( result.subtract(field.newDfp(0.5)).subtract(solver.getAbsoluteAccuracy()).positiveOrNull()); result = solver.solve( 20, f, field.newDfp(-0.9), field.newDfp(-0.2), field.newDfp(-0.4), AllowedSolution.ABOVE_SIDE); Assert.assertTrue(f.value(result).abs().lessThan(solver.getFunctionValueAccuracy())); Assert.assertTrue(f.value(result).positiveOrNull()); Assert.assertTrue( result.add(field.newDfp(0.5)).subtract(solver.getAbsoluteAccuracy()).negativeOrNull()); }