NAG Library Routine Document
C05AUF 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.
||X, H, EPS, ETA, F, A, B, RUSER(*)
C05AUF attempts to locate an interval
containing a simple zero of the function
by a binary search starting from the initial point
and using repeated calls to C05AVF
. If this search succeeds, then the zero is determined to a user-specified accuracy by a call to C05AYF
. The specifications of routines C05AVF
should be consulted for details of the methods used.
to the zero
is determined so that at least one of the following criteria is satisfied:
Brent R P (1973) Algorithms for Minimization Without Derivatives Prentice–Hall
- 1: X – REAL (KIND=nag_wp)Input/Output
On entry: an initial approximation to the zero.
is the final approximation to the zero.
is likely to be a pole of
contains no useful information.
- 2: H – REAL (KIND=nag_wp)Input
On entry: a step length for use in the binary search for an interval containing the zero. The maximum interval searched is .
must be sufficiently large that on the computer.
- 3: EPS – REAL (KIND=nag_wp)Input
: the termination tolerance on
(see Section 3
- 4: ETA – REAL (KIND=nag_wp)Input
: a value such that if
is accepted as the zero. ETA
may be specified as
(see Section 7
- 5: F – REAL (KIND=nag_wp) FUNCTION, supplied by the user.External Procedure
must evaluate the function
whose zero is to be determined.
The specification of F
- 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
is called with the parameters IUSER
as supplied to C05AUF. You are free to use the arrays IUSER
to supply information to F
as an alternative to using COMMON global variables.
must either be a module subprogram USEd by, or declared as EXTERNAL in, the (sub)program from which C05AUF is called. Parameters denoted as Input
be changed by this procedure.
- 6: A – REAL (KIND=nag_wp)Output
- 7: B – REAL (KIND=nag_wp)Output
On exit: the lower and upper bounds respectively of the interval resulting from the binary search. If the zero is determined exactly such that or is determined so that at any stage in the calculation, then on exit .
- 8: IUSER() – INTEGER arrayUser Workspace
- 9: RUSER() – REAL (KIND=nag_wp) arrayUser Workspace
are not used by C05AUF, but are passed directly to F
and may be used to pass information to this routine as an alternative to using COMMON global variables.
- 10: IFAIL – INTEGERInput/Output
must be set to
. 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
is recommended. If the output of error messages is undesirable, then the value
is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is
. When the value is used it is essential to test the value of IFAIL on exit.
unless the routine detects an error or a warning has been flagged (see Section 6
6 Error Indicators and Warnings
If on entry
, explanatory error messages are output on the current error message unit (as defined by X04AAF
Errors or warnings detected by the routine:
On entry, either , or to machine accuracy (meaning that the search for an interval containing the zero cannot commence).
An interval containing the zero could not be found. Increasing H
and calling C05AUF again will increase the range searched for the zero. Decreasing H
and calling C05AUF again will refine the mesh used in the search for the zero.
A change in sign of
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
Too much accuracy has been requested in the computation; that is, the zero has been located to relative accuracy at least
is the machine precision
, but the exit conditions described in Section 3
are not satisfied. It is unsafe for C05AUF 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
. If full machine accuracy is required, they may be set very small, resulting in an exit with
, although this may involve many more iterations than a lesser accuracy. You are recommended to set
and to use EPS
to control the accuracy, unless you have considerable knowledge of the size of
for values of
near the zero.
The time taken by C05AUF depends primarily on the time spent evaluating F
(see Section 5
). 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
containing the zero, or if F
is expensive to evaluate and the number of calls to F
is to be restricted, then use of C05AVF
followed by C05AZF
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 routines are more flexible than the direct communication of F
required by C05AUF.
If the iteration terminates with successful exit and
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
at the point X
, preferably analytically, or, if this is not possible, numerically, perhaps by using a central difference estimate. If
, then X
must correspond to a multiple zero of
rather than a simple zero.
This example calculates an approximation to the zero of using a tolerance of starting from and using an initial search step .
9.1 Program Text
Program Text (c05aufe.f90)
9.2 Program Data
9.3 Program Results
Program Results (c05aufe.r)