UnivariateSolverUtils { public static double solve(UnivariateFunction function, double x0, double x1) throws NullArgumentException, NoBracketingException { if (function == null) { throw new NullArgumentException(LocalizedFormats.FUNCTION); } final UnivariateSolver solver = new BrentSolver(); return solver.solve(Integer.MAX_VALUE, function, x0, x1); } private  UnivariateSolverUtils(); static double solve(UnivariateFunction function, double x0, double x1); static double solve(UnivariateFunction function,
                               double x0, double x1,
                               double absoluteAccuracy); static double forceSide(final int maxEval, final UnivariateFunction f,
                                   final BracketedUnivariateSolver<UnivariateFunction> bracketing,
                                   final double baseRoot, final double min, final double max,
                                   final AllowedSolution allowedSolution); static double[] bracket(UnivariateFunction function,
                                   double initial,
                                   double lowerBound, double upperBound); static double[] bracket(UnivariateFunction function,
                                   double initial,
                                   double lowerBound, double upperBound,
                                   int maximumIterations); static double[] bracket(final UnivariateFunction function, final double initial,
                                   final double lowerBound, final double upperBound,
                                   final double q, final double r, final int maximumIterations); static double midpoint(double a, double b); static boolean isBracketing(UnivariateFunction function,
                                       final double lower,
                                       final double upper); static boolean isSequence(final double start,
                                     final double mid,
                                     final double end); static void verifyInterval(final double lower,
                                      final double upper); static void verifySequence(final double lower,
                                      final double initial,
                                      final double upper); static void verifyBracketing(UnivariateFunction function,
                                        final double lower,
                                        final double upper);  }
@Test(expected=MathIllegalArgumentException.class) public void testSolveNull() { UnivariateSolverUtils.solve(null, 0.0, 4.0); }
@Test(expected=MathIllegalArgumentException.class) public void testSolveBadEndpoints() { double root = UnivariateSolverUtils.solve(sin, 4.0, -0.1, 1e-6); System.out.println("root=" + root); }
@Test public void testSolveBadAccuracy() { try { UnivariateSolverUtils.solve(sin, 0.0, 4.0, 0.0); } catch (MathIllegalArgumentException ex) { } }
@Test public void testSolveSin() { double x = UnivariateSolverUtils.solve(sin, 1.0, 4.0); Assert.assertEquals(FastMath.PI, x, 1.0e-4); }
@Test(expected=MathIllegalArgumentException.class) public void testSolveAccuracyNull() { double accuracy = 1.0e-6; UnivariateSolverUtils.solve(null, 0.0, 4.0, accuracy); }
@Test public void testSolveAccuracySin() { double accuracy = 1.0e-6; double x = UnivariateSolverUtils.solve(sin, 1.0, 4.0, accuracy); Assert.assertEquals(FastMath.PI, x, accuracy); }
@Test(expected=MathIllegalArgumentException.class) public void testSolveNoRoot() { UnivariateSolverUtils.solve(sin, 1.0, 1.5); }
@Test public void testMisc() { UnivariateFunction f = new QuinticFunction(); double result; result = UnivariateSolverUtils.solve(f, -0.2, 0.2); Assert.assertEquals(result, 0, 1E-8); result = UnivariateSolverUtils.solve(f, -0.1, 0.3); Assert.assertEquals(result, 0, 1E-8); result = UnivariateSolverUtils.solve(f, -0.3, 0.45); Assert.assertEquals(result, 0, 1E-6); result = UnivariateSolverUtils.solve(f, 0.3, 0.7); Assert.assertEquals(result, 0.5, 1E-6); result = UnivariateSolverUtils.solve(f, 0.2, 0.6); Assert.assertEquals(result, 0.5, 1E-6); result = UnivariateSolverUtils.solve(f, 0.05, 0.95); Assert.assertEquals(result, 0.5, 1E-6); result = UnivariateSolverUtils.solve(f, 0.85, 1.25); Assert.assertEquals(result, 1.0, 1E-6); result = UnivariateSolverUtils.solve(f, 0.8, 1.2); Assert.assertEquals(result, 1.0, 1E-6); result = UnivariateSolverUtils.solve(f, 0.85, 1.75); Assert.assertEquals(result, 1.0, 1E-6); result = UnivariateSolverUtils.solve(f, 0.55, 1.45); Assert.assertEquals(result, 1.0, 1E-6); result = UnivariateSolverUtils.solve(f, 0.85, 5); Assert.assertEquals(result, 1.0, 1E-6); }