25package umontreal.ssj.util;
27import umontreal.ssj.functions.MathFunction;
34public class RootFinder {
35 private static final double MINVAL = 5.0e-308;
37 private RootFinder() {
53 final double EPS = 0.5E-15;
54 final int MAXITER = 120;
57 final boolean DEBUG =
false;
68 if (Math.abs(fa) <= MINVAL)
72 if (Math.abs(fb) <= MINVAL)
80 if (Math.abs(fc) < Math.abs(fb)) {
90 for (i = 0; i < MAXITER; i++) {
93 double xm = 0.5 * (c - b);
95 double err = Math.abs(fa - fb);
96 System.out.printf(
"[a, b] = [%g, %g] fa = %g, fb = %g |fa - fb| = %.2g%n", a, b, fa, fb, err);
99 if (Math.abs(fb) <= MINVAL) {
102 if (Math.abs(xm) <= tol1) {
103 if (Math.abs(b) > MINVAL)
109 if ((Math.abs(e) >= tol1) && (Math.abs(fa) > Math.abs(fb))) {
115 p = s * (2.0 * xm * q * (q - r) - (b - a) * (r - 1.0));
116 q = (q - 1.0) * (r - 1.0) * (s - 1.0);
130 if (((2.0 * p) >= (3.0 * xm * q - Math.abs(tol1 * q))) || (p >= Math.abs(0.5 * e * q))) {
145 if (Math.abs(d) > tol1)
152 if (fb * (Math.signum(fc)) > 0.0) {
167 System.err.println(
" WARNING: root finding does not converge");
194 if (Math.abs(yb) <= MINVAL)
197 if (Math.abs(ya) <= MINVAL)
201 final int MAXITER = 1200;
202 final boolean DEBUG =
false;
206 System.out.println(
"\niter xa xb f(x)");
208 boolean fini =
false;
213 if ((Math.abs(y) <= MINVAL) || (Math.abs(xb - xa) <= tol * Math.abs(x)) || (Math.abs(xb - xa) <= MINVAL)) {
214 if (Math.abs(x) > MINVAL)
225 System.out.printf(
"%3d %18.12g %18.12g %14.4g%n", i, xa, xb, y);
227 System.out.println(
"***** bisection: SEARCH DOES NOT CONVERGE");
This class provides various constants and methods to compute numerical quantities such as factorials,...
static final double DBL_EPSILON
Difference between 1.0 and the smallest double greater than 1.0.
static double brentDekker(double a, double b, MathFunction f, double tol)
Computes a root of the function in f using the Brent-Dekker method.
static double bisection(double a, double b, MathFunction f, double tol)
Computes a root of the function in f using the bisection method.
This interface should be implemented by classes which represent univariate mathematical functions.
double evaluate(double x)
Returns the value of the function evaluated at .