C05AYF (PDF version)
C05 Chapter Contents
C05 Chapter Introduction
NAG Library Manual

NAG Library Routine Document

C05AYF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

 Contents

    1  Purpose
    7  Accuracy

1  Purpose

C05AYF 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.

2  Specification

SUBROUTINE C05AYF ( A, B, EPS, ETA, F, X, IUSER, RUSER, IFAIL)
INTEGER  IUSER(*), IFAIL
REAL (KIND=nag_wp)  A, B, EPS, ETA, F, X, RUSER(*)
EXTERNAL  F

3  Description

C05AYF attempts to obtain an approximation to a simple zero of the function fx  given an initial interval a,b  such that fa × fb 0 . The same core algorithm is used by C05AZF whose specification should be consulted for details of the method used.
The approximation x to the zero α is determined so that at least one of the following criteria is satisfied:
(i) x-α EPS ,
(ii) fxETA .

4  References

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

5  Parameters

1:     A – REAL (KIND=nag_wp)Input
On entry: a, the lower bound of the interval.
2:     B – REAL (KIND=nag_wp)Input
On entry: b, the upper bound of the interval.
Constraint: BA .
3:     EPS – REAL (KIND=nag_wp)Input
On entry: the termination tolerance on x (see Section 3).
Constraint: EPS>0.0 .
4:     ETA – REAL (KIND=nag_wp)Input
On entry: a value such that if fxETA , x is accepted as the zero. ETA may be specified as 0.0 (see Section 7).
5:     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:
FUNCTION F ( X, IUSER, RUSER)
REAL (KIND=nag_wp) F
INTEGER  IUSER(*)
REAL (KIND=nag_wp)  X, RUSER(*)
1:     X – REAL (KIND=nag_wp)Input
On entry: the point at which the function must be evaluated.
2:     IUSER* – INTEGER arrayUser Workspace
3:     RUSER* – REAL (KIND=nag_wp) arrayUser Workspace
F is called with the parameters IUSER and RUSER as supplied to C05AYF. You are free to use the arrays IUSER and RUSER to supply information to F as an alternative to using COMMON global variables.
F must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which C05AYF is called. Parameters denoted as Input must not be changed by this procedure.
6:     X – REAL (KIND=nag_wp)Output
On exit: if IFAIL=0 or 2, X is the final approximation to the zero. If IFAIL=3, X is likely to be a pole of fx. Otherwise, X contains no useful information.
7:     IUSER* – INTEGER arrayUser Workspace
8:     RUSER* – REAL (KIND=nag_wp) arrayUser Workspace
IUSER and RUSER are not used by C05AYF, but are passed directly to F and may be used to pass information to this routine as an alternative to using COMMON global variables.
9:     IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to 0, -1​ or ​1. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ 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 parameter, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On exit: IFAIL=0 unless the routine detects an error or a warning has been flagged (see Section 6).

6  Error Indicators and Warnings

If on entry 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:
IFAIL=1
On entry, A=value and B=value.
Constraint: AB.
On entry, EPS=value.
Constraint: EPS>0.0.
On entry, FA and FB have the same sign with neither equalling 0.0: FA=value and FB=value.
IFAIL=2
No further improvement in the solution is possible. EPS is too small: EPS=value . The final value of X returned is an accurate approximation to the zero.
IFAIL=3
The function values in the interval A,B  might contain a pole rather than a zero. Reducing EPS may help in distinguishing between a pole and a zero.
IFAIL=-99
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.8 in the Essential Introduction for further information.
IFAIL=-399
Your licence key may have expired or may not have been installed correctly.
See Section 3.7 in the Essential Introduction for further information.
IFAIL=-999
Dynamic memory allocation failed.
See Section 3.6 in the Essential Introduction 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 IFAIL=2, although this may involve many more iterations than a lesser accuracy. You are recommended to set ETA=0.0  and to use EPS to control the accuracy, unless you have considerable knowledge of the size of fx  for values of x near the zero.

8  Parallelism and Performance

Not applicable.

9  Further Comments

The time taken by C05AYF depends primarily on the time spent evaluating F (see Section 5).
If it is important to determine an interval of relative length less than 2×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 C05AZF is recommended. Use of C05AZF 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 C05AZF are more flexible than the direct communication of F required by C05AYF.

10  Example

This example calculates an approximation to the zero of e-x - x  within the interval 0,1  using a tolerance of EPS=1.0E−5.

10.1  Program Text

Program Text (c05ayfe.f90)

10.2  Program Data

None.

10.3  Program Results

Program Results (c05ayfe.r)


C05AYF (PDF version)
C05 Chapter Contents
C05 Chapter Introduction
NAG Library Manual

© The Numerical Algorithms Group Ltd, Oxford, UK. 2015