﻿ c05ay Method
c05ay locates a simple zero of a continuous function in a given interval using Brent's method, which is a combination of nonlinear interpolation, linear extrapolation and bisection.

# Syntax

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

#### Parameters

a
Type: System..::..Double
On entry: $a$, the lower bound of the interval.
b
Type: System..::..Double
On entry: $b$, the upper bound of the interval.
Constraint: ${\mathbf{b}}\ne {\mathbf{a}}$.
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..::..C05AY_F
f must evaluate the function $f$ whose zero is to be determined.

A delegate of type C05AY_F.

x
Type: System..::..Double%
On exit: if ${\mathbf{ifail}}={0}$ or ${2}$, 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.
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

c05ay attempts to obtain an approximation to a simple zero of the function $f\left(x\right)$ given an initial interval $\left[a,b\right]$ such that $f\left(a\right)×f\left(b\right)\le 0$. The same core algorithm is used by c05az whose specification should be consulted for details of the method 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{a}}=〈\mathit{\text{value}}〉$ and ${\mathbf{b}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{a}}\ne {\mathbf{b}}$.
On entry, ${\mathbf{eps}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{eps}}>0.0$.
On entry, ${\mathbf{f}}\left({\mathbf{a}}\right)$ and ${\mathbf{f}}\left({\mathbf{b}}\right)$ have the same sign with neither equalling $0.0$: ${\mathbf{f}}\left({\mathbf{a}}\right)=〈\mathit{\text{value}}〉$ and ${\mathbf{f}}\left({\mathbf{b}}\right)=〈\mathit{\text{value}}〉$.
${\mathbf{ifail}}=2$
No further improvement in the solution is possible. eps is too small: ${\mathbf{eps}}=〈\mathit{\text{value}}〉$. The final value of x returned is an accurate approximation to the zero.
${\mathbf{ifail}}=3$
The function values in the interval $\left[{\mathbf{a}},{\mathbf{b}}\right]$ might contain a pole rather than a zero. Reducing eps may help in distinguishing between a pole and a zero.
${\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}}={2}$, 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.

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 c05az is recommended. Use of c05az 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 c05az are more flexible than the direct communication of f required by c05ay.
This example calculates an approximation to the zero of ${e}^{-x}-x$ within the interval $\left[0,1\right]$ using a tolerance of ${\mathbf{eps}}=\text{1.0E−5}$.