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

NAG Library Routine Document

C05AXF

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

C05AXF attempts to locate a zero of a continuous function using a continuation method based on a secant iteration. It uses reverse communication for evaluating the function.

2  Specification

SUBROUTINE C05AXF ( X, FX, TOL, IR, SCAL, C, IND, IFAIL)
INTEGER  IR, IND, IFAIL
REAL (KIND=nag_wp)  X, FX, TOL, SCAL, C(26)

3  Description

C05AXF uses a modified version of an algorithm given in Swift and Lindfield (1978) to compute a zero α of a continuous function fx . The algorithm used is based on a continuation method in which a sequence of problems
fx-θrfx0,  r=0,1,,m  
are solved, where 1 = θ0 > θ1 > > θm = 0  (the value of m is determined as the algorithm proceeds) and where x0  is your initial estimate for the zero of fx . For each θr  the current problem is solved by a robust secant iteration using the solution from earlier problems to compute an initial estimate.
You must supply an error tolerance TOL. TOL is used directly to control the accuracy of solution of the final problem ( θm=0 ) in the continuation method, and TOL  is used to control the accuracy in the intermediate problems ( θ1 , θ2 , , θm-1 ).

4  References

Swift A and Lindfield G R (1978) Comparison of a continuation method for the numerical solution of a single nonlinear equation Comput. J. 21 359–362

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: an initial approximation to the zero.
On intermediate exit: the point at which f must be evaluated before re-entry to the routine.
On final exit: the final approximation to the zero.
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:     TOL – REAL (KIND=nag_wp)Input
On initial entry: a value that controls the accuracy to which the zero is determined. TOL is used in determining the convergence of the secant iteration used at each stage of the continuation process. It is used directly when solving the last problem ( θm=0  in Section 3), and TOL  is used for the problem defined by θr , r<m . Convergence to the accuracy specified by TOL is not guaranteed, and so you are recommended to find the zero using at least two values for TOL to check the accuracy obtained.
Constraint: TOL>0.0 .
4:     IR – INTEGERInput
On initial entry: indicates the type of error test required, as follows. Solving the problem defined by θr , 1rm , involves computing a sequence of secant iterates xr0,xr1, . This sequence will be considered to have converged only if:
for IR=0,
xr i+1 -xri eps×max1.0,xri ,  
for IR=1,
xr i+1 -xri eps,  
for IR=2,
xr i+1 -xri eps×xri ,  
for some i>1 ; here eps  is either TOL or TOL  as discussed above. Note that there are other subsidiary conditions (not given here) which must also be satisfied before the secant iteration is considered to have converged.
Constraint: IR=0, 1 or 2.
5:     SCAL – REAL (KIND=nag_wp)Input
On initial entry: a factor for use in determining a significant approximation to the derivative of fx  at x=x0 , the initial value. A number of difference approximations to fx0  are calculated using
fx0fx0+h-fx0/h  
where h<SCAL  and h has the same sign as SCAL. A significance (cancellation) check is made on each difference approximation and the approximation is rejected if insignificant.
Suggested value: ε, where ε is the machine precision returned by X02AJF.
Constraint: SCAL  must be sufficiently large that X+SCALX  on the computer.
6:     C26 – REAL (KIND=nag_wp) arrayCommunication Array
( C5  contains the current θr , this value may be useful in the event of an error exit.)
7:     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, 3 or 4. The calling program must evaluate f at X, storing the result in FX, and re-enter C05AXF with all other parameters unchanged.
On final exit: contains 0.
Constraint: on entry IND=-1, 1, 2, 3 or 4.
8:     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, TOL0.0 ,
orIR0, 1 or 2.
IFAIL=2
The parameter IND is incorrectly set on initial or intermediate entry.
IFAIL=3
SCAL is too small, or significant derivatives of f cannot be computed (this can happen when f is almost constant and nonzero, for any value of SCAL).
IFAIL=4
The current problem in the continuation sequence cannot be solved, see C5  for the value of θr . The most likely explanation is that the current problem has no solution, either because the original problem had no solution or because the continuation path passes through a set of insoluble problems. This latter reason for failure should occur rarely, and not at all if the initial approximation to the zero is sufficiently close. Other possible explanations are that TOL is too small and hence the accuracy requirement is too stringent, or that TOL is too large and the initial approximation too poor, leading to successively worse intermediate solutions.
IFAIL=5
Continuation away from the initial point is not possible. This error exit will usually occur if the problem has not been properly posed or the error requirement is extremely stringent.
IFAIL=6
The final problem (with θm=0 ) cannot be solved. It is likely that too much accuracy has been requested, or that the zero is at α=0  and IR=2 .
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 accuracy of the approximation to the zero depends on TOL and IR. In general decreasing TOL will give more accurate results. Care must be exercised when using the relative error criterion ( IR=2 ).
If the zero is at X=0 , or if the initial value of X and the zero bracket the point X=0 , it is likely that an error exit with IFAIL=4, 5 or 6 will occur.
It is possible to request too much or too little accuracy. Since it is not possible to achieve more than machine accuracy, a value of TOLmachine precision  should not be input and may lead to an error exit with IFAIL=4, 5 or 6. For the reasons discussed under IFAIL=4 in Section 6, TOL should not be taken too large, say no larger than TOL=1.0E−3 .

8  Parallelism and Performance

Not applicable.

9  Further Comments

For most problems, the time taken on each call to C05AXF will be negligible compared with the time spent evaluating fx  between calls to C05AXF. However, the initial value of X and the choice of TOL will clearly affect the timing. The closer that X is to the root, the less evaluations of f required. The effect of the choice of TOL will not be large, in general, unless TOL is very small, in which case the timing will increase.

10  Example

This example calculates a zero of x - e-x  with initial approximation x0=1.0 , and TOL=1.0E−3  and 1.0E−4 .

10.1  Program Text

Program Text (c05axfe.f90)

10.2  Program Data

None.

10.3  Program Results

Program Results (c05axfe.r)


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

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