﻿ c05au Method
c05au 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.

Syntax

C#
```public static void c05au(
ref double x,
double h,
double eps,
double eta,
C05..::..C05AU_F f,
out double a,
out double b,
out int ifail
)```
Visual Basic
```Public Shared Sub c05au ( _
ByRef x As Double, _
h As Double, _
eps As Double, _
eta As Double, _
f As C05..::..C05AU_F, _
<OutAttribute> ByRef a As Double, _
<OutAttribute> ByRef b As Double, _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void c05au(
double% x,
double h,
double eps,
double eta,
C05..::..C05AU_F^ f,
[OutAttribute] double% a,
[OutAttribute] double% b,
[OutAttribute] int% ifail
)```
F#
```static member c05au :
x : float byref *
h : float *
eps : float *
eta : float *
f : C05..::..C05AU_F *
a : float byref *
b : float byref *
ifail : int byref -> unit
```

Parameters

x
Type: System..::..Double%
On entry: an initial approximation to the zero.
On exit: if ${\mathbf{ifail}}={0}$ or ${4}$, x is the final approximation to the zero.
If ${\mathbf{ifail}}={3}$, x is likely to be a pole of $f\left(x\right)$.
Otherwise, x contains no useful information.
h
Type: System..::..Double
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×{\mathbf{h}},{\mathbf{x}}+256.0×{\mathbf{h}}\right]$.
Constraint: ${\mathbf{h}}$ must be sufficiently large that ${\mathbf{x}}+{\mathbf{h}}\ne {\mathbf{x}}$ on the computer.
eps
Type: System..::..Double
On entry: the termination tolerance on $x$ (see [Description]).
Constraint: ${\mathbf{eps}}>0.0$.
eta
Type: System..::..Double
On entry: a value such that if $\left|f\left(x\right)\right|\le {\mathbf{eta}}$, $x$ is accepted as the zero. eta may be specified as $0.0$ (see [Accuracy]).
f
Type: NagLibrary..::..C05..::..C05AU_F
f must evaluate the function $f$ whose zero is to be determined.

A delegate of type C05AU_F.

a
Type: System..::..Double%
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 $\left|f\left(x\right)\right|\le {\mathbf{eta}}$ at any stage in the calculation, then on exit ${\mathbf{a}}={\mathbf{b}}=x$.
b
Type: System..::..Double%
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 $\left|f\left(x\right)\right|\le {\mathbf{eta}}$ at any stage in the calculation, then on exit ${\mathbf{a}}={\mathbf{b}}=x$.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

Description

c05au 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 c05av. If this search succeeds, then the zero is determined to a user-specified accuracy by a call to c05ay. The specifications of methods c05av and c05ay 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) $\left|x-\alpha \right|\le {\mathbf{eps}}$, (ii) $\left|f\left(x\right)\right|\le {\mathbf{eta}}$.

References

Brent R P (1973) Algorithms for Minimization Without Derivatives Prentice–Hall

Error Indicators and Warnings

Errors or warnings detected by the method:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{eps}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{eps}}>0.0$.
On entry, ${\mathbf{x}}=〈\mathit{\text{value}}〉$ and ${\mathbf{h}}=〈\mathit{\text{value}}〉$.
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 c05au again will increase the range searched for the zero. Decreasing h and calling c05au 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}}=〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

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}}={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.

Parallelism and Performance

None.

The time taken by c05au depends primarily on the time spent evaluating f (see [Parameters]). 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×{\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 c05av followed by c05az 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 methods are more flexible than the direct communication of f required by c05au.
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.

Example

This example calculates an approximation to the zero of $x-{e}^{-x}$ using a tolerance of ${\mathbf{eps}}=\text{1.0E−5}$ starting from ${\mathbf{x}}=1.0$ and using an initial search step ${\mathbf{h}}=0.1$.

Example program (C#): c05aue.cs

Example program results: c05aue.r