public class BrentZeroFinder
extends java.lang.Object
This algorithm uses a combination of bisection and inverse linear and/or quadratic interpolation. Convergence is never much slower than that for bisection. If f(x) has a continuous second derivative near a simple zero, then the algorithm will tend towards superlinear convergence of order at least 1.618.
Let xzero be the argument x that results from a search for the zero. That search is terminated when the difference between xzero and the true zeroing argument x is less than tol+4*EPS*abs(xzero), where tol is a specified tolerance and EPS is DBL_EPSILON (approximately 1.0e-16), machine epsilon for IEEE double precision arithmetic.
This implementation is adapted from the Fortran subroutine ZEROIN, by Forsythe, G.E., Malcolm, M.A., and Moler, C.B. 1977, Computer Methods for Mathematical Computations, Prentice Hall. That Fortran function is, in turn, a translation of the Algol 60 program by Brent, R., 1973, Algorithms for Minimization Without Derivatives, Prentice Hall.
Modifier and Type | Class and Description |
---|---|
static interface |
BrentZeroFinder.Function
A function f(x) of one variable x.
|
Constructor and Description |
---|
BrentZeroFinder(BrentZeroFinder.Function f)
Constructs a zero finder for the specified function.
|
Modifier and Type | Method and Description |
---|---|
double |
f(double x)
Returns the function value f(x) for the specified argument x.
|
double |
findZero(double a,
double b,
double tol)
Finds a zero within the specified search interval [a,b].
|
double |
findZero(double a,
double fa,
double b,
double fb,
double tol)
Finds a zero within the specified search interval [a,b], beginning
with specified function values f(a) and f(b), which must not have
the same sign.
|
public BrentZeroFinder(BrentZeroFinder.Function f)
f
- the function.public double f(double x)
x
- the argument at which to evaluate f(x).public double findZero(double a, double b, double tol)
a
- the lower limit of the search interval.b
- the upper limit of the search interval.tol
- the accuracy with which to find the zero.public double findZero(double a, double fa, double b, double fb, double tol)
a
- the lower limit of the search interval.fa
- the function f(x) evaluated at x = a.b
- the upper limit of the search interval.fb
- the function f(x) evaluated at x = b.tol
- the accuracy with which to find the zero.