Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

## Purpose

nag_roots_withdraw_contfn_brent_int (c05ad) locates a zero of a continuous function in a given interval by a combination of the methods of nonlinear interpolation, linear extrapolation and bisection.
Note: this function is scheduled to be withdrawn, please see c05ad in Advice on Replacement Calls for Withdrawn/Superseded Routines..

## Syntax

[x, ifail] = c05ad(a, b, eps, eta, f)
[x, ifail] = nag_roots_withdraw_contfn_brent_int(a, b, eps, eta, f)

## Description

nag_roots_withdraw_contfn_brent_int (c05ad) attempts to obtain an approximation to a simple zero of the function f(x) $f\left(x\right)$ given an initial interval [a,b] $\left[a,b\right]$ such that f(a) × f(b) 0 $f\left(a\right)×f\left(b\right)\le 0$. The same core algorithm is used by nag_roots_contfn_brent_rcomm (c05az) whose specification should be consulted for details of the method used.
The approximation x$x$ to the zero α$\alpha$ is determined so that at least one of the following criteria is satisfied:
 (i) |x − α| ≤ eps $|x-\alpha |\le {\mathbf{eps}}$, (ii) |f(x)| ≤ eta $|f\left(x\right)|\le {\mathbf{eta}}$.

## References

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

## Parameters

### Compulsory Input Parameters

1:     a – double scalar
a$a$, the lower bound of the interval.
2:     b – double scalar
b$b$, the upper bound of the interval.
Constraint: ba ${\mathbf{b}}\ne {\mathbf{a}}$.
3:     eps – double scalar
The termination tolerance on x$x$ (see Section [Description]).
Constraint: eps > 0.0 ${\mathbf{eps}}>0.0$.
4:     eta – double scalar
A value such that if |f(x)|eta $|f\left(x\right)|\le {\mathbf{eta}}$, x$x$ is accepted as the zero. eta may be specified as 0.0$0.0$ (see Section [Accuracy]).
5:     f – function handle or string containing name of m-file
f must evaluate the function f$f$ whose zero is to be determined.
[result] = f(xx)

Input Parameters

1:     xx – double scalar
The point at which the function must be evaluated.

Output Parameters

1:     result – double scalar
The result of the function.

None.

None.

### Output Parameters

1:     x – double scalar
The approximation to the zero.
2:     ifail – int64int32nag_int scalar
${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [Error Indicators and Warnings]).

## Error Indicators and Warnings

Errors or warnings detected by the function:

Cases prefixed with W are classified as warnings and do not generate an error of type NAG:error_n. See nag_issue_warnings.

ifail = 1${\mathbf{ifail}}=1$
 On entry, eps ≤ 0.0 ${\mathbf{eps}}\le 0.0$, or a = b ${\mathbf{a}}={\mathbf{b}}$, or f(a) × f(b) > 0.0 ${\mathbf{f}}\left({\mathbf{a}}\right)×{\mathbf{f}}\left({\mathbf{b}}\right)>0.0$.
W ifail = 2${\mathbf{ifail}}=2$
Too much accuracy has been requested in the computation; that is, the zero has been located to relative accuracy at least ε$\epsilon$, where ε$\epsilon$ is the machine precision, but the exit conditions described in Section [Description] are not satisfied. It is unsafe for nag_roots_withdraw_contfn_brent_int (c05ad) to continue beyond this point, but the final value of x returned is an accurate approximation to the zero.
W ifail = 3${\mathbf{ifail}}=3$
A change in sign of f(x) $f\left(x\right)$ has been determined as occurring near the point defined by the final value of x. However, there is some evidence that this sign-change corresponds to a pole of f(x) $f\left(x\right)$.

## 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{2}}$, although this may involve many more iterations than a lesser accuracy. You are recommended to set eta = 0.0 ${\mathbf{eta}}=0.0$ and to use eps to control the accuracy, unless you have considerable knowledge of the size of f(x) $f\left(x\right)$ for values of x$x$ near the zero.

The time taken by nag_roots_withdraw_contfn_brent_int (c05ad) depends primarily on the time spent evaluating f (see Section [Parameters]).
If it is important to determine an interval of relative length less than 2 × eps$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 nag_roots_contfn_brent_rcomm (c05az) is recommended. Use of nag_roots_contfn_brent_rcomm (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 nag_roots_contfn_brent_rcomm (c05az) are more flexible than the direct communication of f required by nag_roots_withdraw_contfn_brent_int (c05ad).

## Example

```function nag_roots_withdraw_contfn_brent_int_example
a = 0;
b = 1;
epsilon = 1e-05;
eta = 0;
f = @(x) exp(-x)-x;
[x, ifail] = nag_roots_withdraw_contfn_brent_int(a, b, epsilon, eta, f)
```
```

x =

0.5671

ifail =

0

```
```function c05ad_example
a = 0;
b = 1;
epsilon = 1e-05;
eta = 0;
f = @(x) exp(-x)-x;
[x, ifail] = c05ad(a, b, epsilon, eta, f)
```
```

x =

0.5671

ifail =

0

```