NAG Library Routine Document
C05AVF
1 Purpose
C05AVF attempts to locate an interval containing a simple zero of a continuous function using a binary search. It uses reverse communication for evaluating the function.
2 Specification
INTEGER |
IND, IFAIL |
REAL (KIND=nag_wp) |
X, FX, H, BOUNDL, BOUNDU, Y, C(11) |
|
3 Description
You must supply an initial point
X and a step
H. C05AVF attempts to locate a short interval
containing a simple zero of
.
(On exit we may have
;
X is determined as the first point encountered in a binary search where the sign of
differs from the sign of
at the initial input point
X.) The routine attempts to locate a zero of
using
H,
,
and
in turn as its basic step before quitting with an error exit if unsuccessful.
C05AVF returns to the calling program for each evaluation of . On each return you should set and call C05AVF again.
4 References
None.
5 Parameters
Note: this routine uses
reverse communication. Its use involves an initial entry, intermediate exits and re-entries, and a final exit, as indicated by the parameter
IND. Between intermediate exits and re-entries,
all parameters other than FX must remain unchanged.
- 1: X – REAL (KIND=nag_wp)Input/Output
On initial entry: the best available approximation to the zero.
Constraint:
X must lie in the closed interval
(see below).
On intermediate exit:
contains the point at which must be evaluated before re-entry to the routine.
On final exit: contains one end of an interval containing the zero, the other end being in
Y, unless an error has occurred. If
,
X and
Y are the end points of the largest interval searched. If a zero is located exactly, its value is returned in
X (and in
Y).
- 2: FX – REAL (KIND=nag_wp)Input
On initial entry: if
,
FX need not be set.
If
,
FX must contain
for the initial value of
X.
On intermediate re-entry: must contain
for the current value of
X.
- 3: H – REAL (KIND=nag_wp)Input/Output
On initial entry: a basic step size which is used in the binary search for an interval containing a zero. The basic step sizes , and are used in turn when searching for the zero.
Constraint:
either
or
must lie inside the closed interval
.
H must be sufficiently large that
on the computer.
On final exit: is undefined.
- 4: BOUNDL – REAL (KIND=nag_wp)Input
- 5: BOUNDU – REAL (KIND=nag_wp)Input
On initial entry:
BOUNDL and
BOUNDU must contain respectively lower and upper bounds for the interval of search for the zero.
Constraint:
.
- 6: Y – REAL (KIND=nag_wp)Input/Output
On initial entry: need not be set.
On final exit: contains the closest point found to the final value of
X, such that
. If a value
X is found such that
, then
. On final exit with
,
X and
Y are the end points of the largest interval searched.
- 7: C() – REAL (KIND=nag_wp) arrayCommunication Array
On initial entry: need not be set.
On final exit: if or , contains .
- 8: IND – INTEGERInput/Output
On initial entry: must be set to
or
.
- FX need not be set.
- FX must contain .
On intermediate exit:
contains
or
. The calling program must evaluate
at
X, storing the result in
FX, and re-enter C05AVF with all other parameters unchanged.
On final exit: contains .
Constraint:
on entry , , or .
- 9: IFAIL – INTEGERInput/Output
On initial entry:
IFAIL 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, because for this routine the values of the output parameters may be useful even if
on exit, the recommended value is
.
When the value is used it is essential to test the value of IFAIL on exit.
On final exit:
unless the routine detects an error or a warning has been flagged (see
Section 6).
6 Error Indicators and Warnings
If on entry
or
, explanatory error messages are output on the current error message unit (as defined by
X04AAF).
Errors or warnings detected by the routine:
On entry, | , |
or | , |
or | both and . |
On initial entry,
H is too small to be used to perturb the initial value of
X in the search.
The parameter
IND is incorrectly set on initial or intermediate entry.
C05AVF has been unable to determine an interval containing a simple zero starting from the initial value of
X and using the step
H. If you have prior knowledge that a simple zero lies in the interval
, you should vary
X and
H in an attempt to find it. (See also
Section 8.)
7 Accuracy
C05AVF is not intended to be used to obtain accurate approximations to the zero of
but rather to locate an interval containing a zero. This interval can then be used as input to an accurate rootfinder such as
C05AYF or
C05AZF. The size of the interval determined depends somewhat unpredictably on the choice of
X and
H. The closer
X is to the root and the
smaller the initial value of
H, then, in general, the smaller (more accurate) the interval determined; however, the accuracy of this statement depends to some extent on the behaviour of
near
and on the size of
H.
For most problems, the time taken on each call to C05AVF will be negligible compared with the time spent evaluating
between calls to C05AVF. However, the initial value of
X and
H will clearly affect the timing. The closer
X is to the root, and the
larger the initial value of
H then the less time taken. (However taking a large
H can affect the accuracy and reliability of the routine, see below.)
You are expected to choose
BOUNDL and
BOUNDU as physically (or mathematically) realistic limits on the interval of search. For example, it may be known, from physical arguments, that no zero of
of interest will lie outside
. Alternatively,
may be more expensive to evaluate for some values of
X than for others and such expensive evaluations can sometimes be avoided by careful choice of
BOUNDL and
BOUNDU.
The choice of
BOUNDL and
BOUNDU affects the search only in that these values provide physical limitations on the search values and that the search is terminated if it seems, from the available information about
, that the zero lies outside
. In this case (
on exit), only one of
and
may have been evaluated and a zero close to the other end of the interval could be missed. The actual interval searched is returned in the parameters
X and
Y and you can call C05AVF again to search the remainder of the original interval.
Though C05AVF is intended primarily for determining an interval containing a zero of
, it may be used to shorten a known interval. This could be useful if, for example, a large interval containing the zero is known and it is also known that the root lies close to one end of the interval; by setting
X to this end of the interval and
H small, a short interval will usually be determined. However, it is worth noting that once any interval containing a zero has been determined, a call to
C05AZF will usually be the most efficient way to calculate an interval of specified length containing the zero. To assist in this determination, the information in
FX and in
X,
Y and
on successful exit from C05AVF is in the correct form for a call to routine
C05AZF with
.
If the calculation terminates because
, then on return
Y is set to
X. (In fact,
on return only in this case.) In this case, there is no guarantee that the value 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.
9 Example
This example finds a sub-interval of containing a simple zero of . The zero nearest to is required and so we set initially.
9.1 Program Text
Program Text (c05avfe.f90)
9.2 Program Data
None.
9.3 Program Results
Program Results (c05avfe.r)