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

NAG Library Routine Document

C05AVF

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

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

SUBROUTINE C05AVF ( X, FX, H, BOUNDL, BOUNDU, Y, C, IND, IFAIL)
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 X,Y BOUNDL,BOUNDU  containing a simple zero of fx .
(On exit we may have X>Y ; X is determined as the first point encountered in a binary search where the sign of fx  differs from the sign of fx  at the initial input point X.) The routine attempts to locate a zero of fx  using H, 0.1×H , 0.01×H  and 0.001×H  in turn as its basic step before quitting with an error exit if unsuccessful.
C05AVF returns to the calling program for each evaluation of fx . On each return you should set FX=fX  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 BOUNDL,BOUNDU  (see below).
On intermediate exit: contains the point at which f 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 IFAIL=4, 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 IND=1, FX need not be set.
If IND=-1, FX must contain fX  for the initial value of X.
On intermediate re-entry: must contain fX  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 H,0.1×H , 0.01×H  and 0.001×H  are used in turn when searching for the zero.
Constraint: either X+H  or X-H  must lie inside the closed interval BOUNDL,BOUNDU .
H must be sufficiently large that X+HX  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: BOUNDL<BOUNDU .
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 fX × fY0.0 . If a value X is found such that fX=0 , then Y=X . On final exit with IFAIL=4, X and Y are the end points of the largest interval searched.
7:     C11 – REAL (KIND=nag_wp) arrayCommunication Array
On initial entry: need not be set.
On final exit: if IFAIL=0 or 4, C1  contains fY .
8:     IND – INTEGERInput/Output
On initial entry: must be set to 1 or -1 .
IND=1
FX need not be set.
IND=-1
FX must contain fX .
On intermediate exit: contains 2 or 3. The calling program must evaluate f at X, storing the result in FX, and re-enter C05AVF with all other parameters unchanged.
On final exit: contains 0.
Constraint: on entry IND=-1, 1, 2 or 3.
9:     IFAIL – INTEGERInput/Output
On initial 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, because for this routine the values of the output parameters may be useful even if IFAIL0 on exit, the recommended value is -1. When the value -1​ or ​1 is used it is essential to test the value of IFAIL on exit.
On final 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, BOUNDUBOUNDL ,
or X BOUNDL,BOUNDU ,
orboth X+H  and X-H BOUNDL,BOUNDU .
IFAIL=2
On initial entry, H is too small to be used to perturb the initial value of X in the search.
IFAIL=3
The parameter IND is incorrectly set on initial or intermediate entry.
IFAIL=4
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 BOUNDL,BOUNDU , you should vary X and H in an attempt to find it. (See also Section 9.)
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

C05AVF is not intended to be used to obtain accurate approximations to the zero of fx  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 fx  near x=X  and on the size of H.

8  Parallelism and Performance

Not applicable.

9  Further Comments

For most problems, the time taken on each call to C05AVF will be negligible compared with the time spent evaluating fx  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 fx  of interest will lie outside BOUNDL,BOUNDU . Alternatively, fx  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 fx , that the zero lies outside BOUNDL,BOUNDU . In this case (IFAIL=4 on exit), only one of fBOUNDL  and fBOUNDU  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 fx , 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 C1  on successful exit from C05AVF is in the correct form for a call to routine C05AZF with IND=-1 .
If the calculation terminates because fX=0.0 , then on return Y is set to X. (In fact, Y=X  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 f at the point X, preferably analytically, or, if this is not possible, numerically, perhaps by using a central difference estimate. If fX=0.0 , then X must correspond to a multiple zero of f rather than a simple zero.

10  Example

This example finds a sub-interval of 0.0,4.0  containing a simple zero of x2 - 3x+2 . The zero nearest to 3.0 is required and so we set X=3.0  initially.

10.1  Program Text

Program Text (c05avfe.f90)

10.2  Program Data

None.

10.3  Program Results

Program Results (c05avfe.r)


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

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