NewtonRaphsonSolver extends AbstractUnivariateDifferentiableSolver { @Override public double solve(int maxEval, final UnivariateDifferentiableFunction f, final double min, final double max) throws TooManyEvaluationsException { return super.solve(maxEval, f, UnivariateSolverUtils.midpoint(min, max)); } NewtonRaphsonSolver();  NewtonRaphsonSolver(double absoluteAccuracy); @Override double solve(int maxEval, final UnivariateDifferentiableFunction f,
                        final double min, final double max);  }
@Test public void testSinZero() { UnivariateDifferentiableFunction f = new Sin(); double result; NewtonRaphsonSolver solver = new NewtonRaphsonSolver(); result = solver.solve(100, f, 3, 4); Assert.assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy()); result = solver.solve(100, f, 1, 4); Assert.assertEquals(result, FastMath.PI, solver.getAbsoluteAccuracy()); Assert.assertTrue(solver.getEvaluations() > 0); }
@Test public void testQuinticZero() { final UnivariateDifferentiableFunction f = new QuinticFunction(); double result; NewtonRaphsonSolver solver = new NewtonRaphsonSolver(); result = solver.solve(100, f, -0.2, 0.2); Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy()); result = solver.solve(100, f, -0.1, 0.3); Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy()); result = solver.solve(100, f, -0.3, 0.45); Assert.assertEquals(result, 0, solver.getAbsoluteAccuracy()); result = solver.solve(100, f, 0.3, 0.7); Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy()); result = solver.solve(100, f, 0.2, 0.6); Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy()); result = solver.solve(100, f, 0.05, 0.95); Assert.assertEquals(result, 0.5, solver.getAbsoluteAccuracy()); result = solver.solve(100, f, 0.85, 1.25); Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy()); result = solver.solve(100, f, 0.8, 1.2); Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy()); result = solver.solve(100, f, 0.85, 1.75); Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy()); result = solver.solve(100, f, 0.55, 1.45); Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy()); result = solver.solve(100, f, 0.85, 5); Assert.assertEquals(result, 1.0, solver.getAbsoluteAccuracy()); }