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

nag_roots_withdraw_contfn_brent_start (c05ag) locates a simple zero of a continuous function from a given starting value, using a binary search to locate an interval containing a zero of the function, then a combination of the methods of nonlinear interpolation, linear extrapolation and bisection to locate the zero precisely.

nag_roots_withdraw_contfn_brent_start (c05ag) attempts to locate an interval
[a,b]
$[a,b]$ containing a simple zero of the function
f(x)
$f\left(x\right)$ by a binary search starting from the initial point
x = x
$x={\mathbf{x}}$ and using repeated calls to nag_roots_contfn_interval_rcomm (c05av). If this search succeeds, then the zero is determined to a user-specified accuracy by a call to nag_roots_contfn_brent (c05ay). The specifications of functions nag_roots_contfn_interval_rcomm (c05av) and nag_roots_contfn_brent (c05ay) should be consulted for details of the methods 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 $\left|f\left(x\right)\right|\le {\mathbf{eta}}$. |

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

- 1: x – double scalar
- An initial approximation to the zero.
- 2: h – double scalar
- 3: eps – double scalar
- 4: eta – double scalar
- A value such that if |f(x)| ≤ eta $\left|f\left(x\right)\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

None.

None.

- 1: x – double scalar
- 2: a – double scalar
- 3: b – double scalar
- The lower and upper bounds respectively of the interval resulting from the binary search. If the zero is determined exactly such that f(x) = 0.0 $f\left(x\right)=0.0$ or is determined so that |f(x)| ≤ eta $\left|f\left(x\right)\right|\le {\mathbf{eta}}$ at any stage in the calculation, then on exit a = b = x ${\mathbf{a}}={\mathbf{b}}=x$.
- 4: ifail – int64int32nag_int scalar
- ifail = 0${\mathrm{ifail}}={\mathbf{0}}$ unless the function detects an error (see [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.

- An interval containing the zero could not be found. Increasing h and calling nag_roots_withdraw_contfn_brent_start (c05ag) again will increase the range searched for the zero. Decreasing h and calling nag_roots_withdraw_contfn_brent_start (c05ag) again will refine the mesh used in the search for 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)$.

`W`ifail = 4${\mathbf{ifail}}=4$- 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_start (c05ag) to continue beyond this point, but the final value of x returned is an accurate approximation to the zero.

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 ifail = 4${\mathbf{ifail}}={\mathbf{4}}$, 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_start (c05ag) depends primarily on the time spent evaluating f (see Section [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 × eps$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 nag_roots_contfn_interval_rcomm (c05av) followed by nag_roots_contfn_brent_rcomm (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 functions are more flexible than the direct communication of f required by nag_roots_withdraw_contfn_brent_start (c05ag).

If the iteration terminates with successful exit and
a = b = x
${\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$f$ at the point x, preferably analytically, or, if this is not possible, numerically, perhaps by using a central difference estimate. If
f^{′}(x) = 0.0
${f}^{\prime}\left({\mathbf{x}}\right)=0.0$, then x must correspond to a multiple zero of f$f$ rather than a simple zero.

Open in the MATLAB editor: nag_roots_withdraw_contfn_brent_start_example

function nag_roots_withdraw_contfn_brent_start_examplex = 1; h = 0.1; epsilon = 1e-05; eta = 0; f = @(x) exp(-x)-x; [xOut, a, b, ifail] = nag_roots_withdraw_contfn_brent_start(x, h, epsilon, eta, f)

xOut = 0.5671 a = 0.5000 b = 0.9000 ifail = 0

Open in the MATLAB editor: c05ag_example

function c05ag_examplex = 1; h = 0.1; epsilon = 1e-05; eta = 0; f = @(x) exp(-x)-x; [xOut, a, b, ifail] = c05ag(x, h, epsilon, eta, f)

xOut = 0.5671 a = 0.5000 b = 0.9000 ifail = 0

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013