All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jnt.nonlinear.ZeroFinder

java.lang.Object
   |
   +----jnt.nonlinear.ZeroFinder

public class ZeroFinder
extends Object
Class built to house the function search which finds a zero of a nonlinear function of one variable in a given interval.
Example of use:
Find zero of sin(x3-1) on the interval (8,11).

{ int status;
double x = -5.0, y = 11.0; 
myFunction f = new myFunction(); ZeroFinder zeroin = new ZeroFinder(f);
Tuple interval = new Tuple(x,y);
status = zeroin.search( interval );
System.out.println( "Return code = " + status); System.out.println( "Final interval is " + interval ); System.out.println(" Best estimate of solution is " + interval.x ); System.out.println(" Residual = " + f.eval(interval.x) ); }
class myFunction implements UnivariateFunction { public double eval( double x) { return x*x*x - 1.0; } }

Relevant Quantities:
The following parameters are used in the public method search() which locates zeros of the given function.

interval (jnt.Tuple)
On input: Defines the interval [b, c] in which the zero is to be found.
On output: [b, c] is reduced so that the zero lies in the interval and the stopping criterion holds. The left value usually is a better approximation to the zero than the right value.
Note that it is not necessary for left < right.

relativeErrorTol (double)
Relative error tolerance used in the stopping criterion (see search method). If the requested value is less than machine precision, then relativeErrorTol is reset to approximately machine precision.

absoluteErrorTol (double)
Absolute error tolerance used in the stopping criterion (see search method). If search intervals will contain the origin, then a nonzero value should be chosen.

maxIterations (int)
The maximum number of iterations to be used in the search procedure.

return value (int)
a status code indicating which of the following conditions hold. Let [b,c] == [interval.x,interval.y].

A - |b-c| <= 2.*(relativeErrorTol*|b|+absoluteErrorTol) 
B - f(b) * f(c) < 0. 
C - |f(b)| <= |f(c)| 
D - |f(bout)| <= max(|(f(bin)|,|f(cin)|)
E - number of evaluations of f(x) <= maxIterations 
Return
Value
Interpretation
1 indicates normal case. All conditions above hold.
2 indicates f(b) = 0. Condition A may not hold.
3 indicates conditions A, B, C, and E hold but D does not. [b,c] probably contains a singular point of f.
4 indicates conditions A and E hold but B does not. A local minimum of f(x) in [b,c] may have been found.
5 indicates search was aborted when condition E failed.
References:
  1. L.F. Shampine and H.A. Watts, ZEROIN, a root-solving code, SC-TM-70-631, Sandia Laboratories, Sept 1970.
  2. T.J. Dekker, Finding a zero by means of successive linear interpolation, in Constructive Aspects of the Fundamental Theorem of Algebra, edited by B. Dejon and P. Henrici, 1969.

This class is based on the Fortran subroutine ZEROIN, originally developed by

Sandia Mathematical Program Library
Mathematical Computing Services Division 5422
Sandia Laboratories
P. O. Box 5800
Albuquerque, New Mexico 87115
Control Data 6600 Version 4.5, 1 November 1971

Version:
22 October 1997
Author:
Ronald F. Boisvert, NIST


Constructor Index

 o ZeroFinder(UnivariateFunction)
Creates a ZeroFinder for a given nonlinear function.

Method Index

 o search(Tuple)
Searches for a zero of the function on the given interval.
 o search(Tuple, double)
Searches for a zero of the function on the given interval with a given relativeErrorTol.
 o search(Tuple, double, double)
Searches for a zero of the function on the given interval with given relativeErrorTol and absoluteErrorTol.
 o search(Tuple, double, double, int)
Searches for a zero of the function on the given interval with given relativeErrorTol, absoluteErrorTol and maxIterations.

Constructors

 o ZeroFinder
 public ZeroFinder(UnivariateFunction f)
Creates a ZeroFinder for a given nonlinear function.

Parameters:
f - (jnt.Functions.UnivariateFunction)
The function whose zero is to be found. This is passed as an instance of an object that implements the UnivariateFunction interface. The eval method of this class is used to evaluate f(x). For example,
class myFunction implements UnivariateFunction {
public double eval( double x) {
return x*x*x - 1.0;
}
}
See Also:
UnivariateFunction

Methods

 o search
 public int search(Tuple interval)
Searches for a zero of the function on the given interval.

The search concludes when the width of the given interval [b,c] has collapsed to within a tolerance specified by the stopping criterion, |b-c| <= 2.*(relativeErrorTol*|b| + absoluteErrorTol). The following defaults are used: relativeErrorTol = 1.0e-8, absoluteErrorTol = 1.0e-8, maxIterations = 500.

Returns:
a status code as described above.
See Also:
Tuple
 o search
 public int search(Tuple interval,
                   double relativeErrorTol)
Searches for a zero of the function on the given interval with a given relativeErrorTol.

The search concludes when the width of the given interval [b,c] has collapsed to within a tolerance specified by the stopping criterion, |b-c| <= 2.*(relativeErrorTol*|b| + absoluteErrorTol). The following defaults are used: absoluteErrorTol = relativeErrorTol, maxIterations = 500.

Returns:
a status code as described above.
See Also:
Tuple
 o search
 public int search(Tuple interval,
                   double relativeErrorTol,
                   double absoluteErrorTol)
Searches for a zero of the function on the given interval with given relativeErrorTol and absoluteErrorTol.

The search concludes when the width of the given interval [b,c] has collapsed to within a tolerance specified by the stopping criterion, |b-c| <= 2.*(relativeErrorTol*|b| + absoluteErrorTol). The following defaults are used: maxIterations = 500.

Returns:
a status code as described above.
See Also:
Tuple
 o search
 public int search(Tuple interval,
                   double relativeErrorTol,
                   double absoluteErrorTol,
                   int maxIterations)
Searches for a zero of the function on the given interval with given relativeErrorTol, absoluteErrorTol and maxIterations.

The search concludes when the width of the given interval [b,c] has collapsed to within a tolerance specified by the stopping criterion, |b-c| <= 2.*(relativeErrorTol*|b| + absoluteErrorTol).

Returns:
a status code as described above.
See Also:
Tuple

All Packages  Class Hierarchy  This Package  Previous  Next  Index