NAG Library Routine Document
C05AUF
1 Purpose
C05AUF locates a simple zero of a continuous function from a given starting value. It uses a binary search to locate an interval containing a zero of the function, then Brent's method, which is a combination of nonlinear interpolation, linear extrapolation and bisection, to locate the zero precisely.
2 Specification
INTEGER 
IUSER(*), IFAIL 
REAL (KIND=nag_wp) 
X, H, EPS, ETA, F, A, B, RUSER(*) 
EXTERNAL 
F 

3 Description
C05AUF attempts to locate an interval
$\left[a,b\right]$ containing a simple zero of the function
$f\left(x\right)$ by a binary search starting from the initial point
$x={\mathbf{X}}$ and using repeated calls to
C05AVF. If this search succeeds, then the zero is determined to a userspecified accuracy by a call to
C05AYF. The specifications of routines
C05AVF and
C05AYF should be consulted for details of the methods used.
The approximation
$x$ to the zero
$\alpha $ is determined so that at least one of the following criteria is satisfied:
(i) 
$\leftx\alpha \right\le {\mathbf{EPS}}$, 
(ii) 
$\leftf\left(x\right)\right\le {\mathbf{ETA}}$. 
4 References
Brent R P (1973) Algorithms for Minimization Without Derivatives Prentice–Hall
5 Arguments
 1: $\mathrm{X}$ – REAL (KIND=nag_wp)Input/Output

On entry: an initial approximation to the zero.
On exit: if
${\mathbf{IFAIL}}={\mathbf{0}}$ or
${\mathbf{4}}$,
X is the final approximation to the zero.
If
${\mathbf{IFAIL}}={\mathbf{3}}$,
X is likely to be a pole of
$f\left(x\right)$.
Otherwise,
X contains no useful information.
 2: $\mathrm{H}$ – REAL (KIND=nag_wp)Input

On entry: a step length for use in the binary search for an interval containing the zero. The maximum interval searched is $\left[{\mathbf{X}}256.0\times {\mathbf{H}},{\mathbf{X}}+256.0\times {\mathbf{H}}\right]$.
Constraint:
${\mathbf{H}}$ must be sufficiently large that ${\mathbf{X}}+{\mathbf{H}}\ne {\mathbf{X}}$ on the computer.
 3: $\mathrm{EPS}$ – REAL (KIND=nag_wp)Input

On entry: the termination tolerance on
$x$ (see
Section 3).
Constraint:
${\mathbf{EPS}}>0.0$.
 4: $\mathrm{ETA}$ – REAL (KIND=nag_wp)Input

On entry: a value such that if
$\leftf\left(x\right)\right\le {\mathbf{ETA}}$,
$x$ is accepted as the zero.
ETA may be specified as
$0.0$ (see
Section 7).
 5: $\mathrm{F}$ – REAL (KIND=nag_wp) FUNCTION, supplied by the user.External Procedure

F must evaluate the function
$f$ whose zero is to be determined.
The specification of
F is:
INTEGER 
IUSER(*) 
REAL (KIND=nag_wp) 
X, RUSER(*) 

 1: $\mathrm{X}$ – REAL (KIND=nag_wp)Input

On entry: the point at which the function must be evaluated.
 2: $\mathrm{IUSER}\left(*\right)$ – INTEGER arrayUser Workspace
 3: $\mathrm{RUSER}\left(*\right)$ – REAL (KIND=nag_wp) arrayUser Workspace

F is called with the arguments
IUSER and
RUSER as supplied to C05AUF. You should use the arrays
IUSER and
RUSER to supply information to
F.
F must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which C05AUF is called. Arguments denoted as
Input must
not be changed by this procedure.
 6: $\mathrm{A}$ – REAL (KIND=nag_wp)Output
 7: $\mathrm{B}$ – REAL (KIND=nag_wp)Output

On exit: the lower and upper bounds respectively of the interval resulting from the binary search. If the zero is determined exactly such that $f\left(x\right)=0.0$ or is determined so that $\leftf\left(x\right)\right\le {\mathbf{ETA}}$ at any stage in the calculation, then on exit ${\mathbf{A}}={\mathbf{B}}=x$.
 8: $\mathrm{IUSER}\left(*\right)$ – INTEGER arrayUser Workspace
 9: $\mathrm{RUSER}\left(*\right)$ – REAL (KIND=nag_wp) arrayUser Workspace

IUSER and
RUSER are not used by C05AUF, but are passed directly to
F and should be used to pass information to this routine.
 10: $\mathrm{IFAIL}$ – INTEGERInput/Output

On entry:
IFAIL must be set to
$0$,
$1\text{ or}1$. If you are unfamiliar with this argument you should refer to
Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value
$1\text{ or}1$ is recommended. If the output of error messages is undesirable, then the value
$1$ is recommended. Otherwise, if you are not familiar with this argument, the recommended value is
$0$.
When the value $\mathbf{1}\text{ or}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit:
${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
${\mathbf{IFAIL}}=0$ or
$1$, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
 ${\mathbf{IFAIL}}=1$

On entry, ${\mathbf{EPS}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{EPS}}>0.0$.
On entry, ${\mathbf{X}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{H}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{X}}+{\mathbf{H}}\ne {\mathbf{X}}$ (to machine accuracy).
 ${\mathbf{IFAIL}}=2$

An interval containing the zero could not be found. Increasing
H and calling C05AUF again will increase the range searched for the zero. Decreasing
H and calling C05AUF again will refine the mesh used in the search for the zero.
 ${\mathbf{IFAIL}}=3$

Solution may be a pole rather than a zero.
 ${\mathbf{IFAIL}}=4$

The tolerance
EPS has been set too small for the problem being solved. However, the value
X returned is a good approximation to the zero.
${\mathbf{EPS}}=\u2329\mathit{\text{value}}\u232a$.
 ${\mathbf{IFAIL}}=99$
An unexpected error has been triggered by this routine. Please
contact
NAG.
See
Section 3.9 in How to Use the NAG Library and its Documentation for further information.
 ${\mathbf{IFAIL}}=399$
Your licence key may have expired or may not have been installed correctly.
See
Section 3.8 in How to Use the NAG Library and its Documentation for further information.
 ${\mathbf{IFAIL}}=999$
Dynamic memory allocation failed.
See
Section 3.7 in How to Use the NAG Library and its Documentation for further information.
7 Accuracy
The levels of accuracy depend on the values of
EPS and
ETA. If full machine accuracy is required, they may be set very small, resulting in an exit with
${\mathbf{IFAIL}}={\mathbf{4}}$, although this may involve many more iterations than a lesser accuracy. You are recommended to set
${\mathbf{ETA}}=0.0$ and to use
EPS to control the accuracy, unless you have considerable knowledge of the size of
$f\left(x\right)$ for values of
$x$ near the zero.
8 Parallelism and Performance
C05AUF is not threaded in any implementation.
The time taken by C05AUF depends primarily on the time spent evaluating
F (see
Section 5). The accuracy of the initial approximation
X and the value of
H will have a somewhat unpredictable effect on the timing.
If it is important to determine an interval of relative length less than
$2\times {\mathbf{EPS}}$ containing the zero, or if
F is expensive to evaluate and the number of calls to
F is to be restricted, then use of
C05AVF followed by
C05AZF is recommended. Use of this combination is also recommended when the structure of the problem to be solved does not permit a simple
F to be written: the reverse communication facilities of these routines are more flexible than the direct communication of
F required by C05AUF.
If the iteration terminates with successful exit and
${\mathbf{A}}={\mathbf{B}}={\mathbf{X}}$ there is no guarantee that the value returned in
X corresponds to a simple zero and you should check whether it does.
One way to check this is to compute the derivative of
$f$ at the point
X, preferably analytically, or, if this is not possible, numerically, perhaps by using a central difference estimate. If
${f}^{\prime}\left({\mathbf{X}}\right)=0.0$, then
X must correspond to a multiple zero of
$f$ rather than a simple zero.
10 Example
This example calculates an approximation to the zero of $x{e}^{x}$ using a tolerance of ${\mathbf{EPS}}=\text{1.0E\u22125}$ starting from ${\mathbf{X}}=1.0$ and using an initial search step ${\mathbf{H}}=0.1$.
10.1 Program Text
Program Text (c05aufe.f90)
10.2 Program Data
None.
10.3 Program Results
Program Results (c05aufe.r)