NAG Library Routine Document
C05AXF
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
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
. The algorithm used is based on a continuation method in which a sequence of problems
are solved, where
(the value of
is determined as the algorithm proceeds) and where
is your initial estimate for the zero of
. For each
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 (
)
in the continuation method, and
is used to control the accuracy in the intermediate problems
(
).
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 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
,
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: 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 (
in
Section 3), and
is used for the problem defined by
,
. 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:
.
- 4: IR – INTEGERInput
On initial entry: indicates the type of error test required, as follows. Solving the problem defined by
,
, involves computing a sequence of secant iterates
. This sequence will be considered to have converged only if:
for
,
for
,
for
,
for some
; here
is either
TOL or
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:
, or .
- 5: SCAL – REAL (KIND=nag_wp)Input
On initial entry: a factor for use in determining a significant approximation to the derivative of
at
, the initial value. A number of difference approximations to
are calculated using
where
and
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:
must be sufficiently large that on the computer.
- 6: C() – REAL (KIND=nag_wp) arrayCommunication Array
( contains the current , this value may be useful in the event of an error exit.)
- 7: 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 C05AXF with all other parameters unchanged.
On final exit: contains .
Constraint:
on entry , , , or .
- 8: 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 . |
The parameter
IND is incorrectly set on initial or intermediate entry.
SCAL is too small, or significant derivatives of
cannot be computed (this can happen when
is almost constant and nonzero, for any value of
SCAL).
The current problem in the continuation sequence cannot be solved, see
for the value of
. 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.
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.
The final problem (with ) cannot be solved. It is likely that too much accuracy has been requested, or that the zero is at and .
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 (
).
If the zero is at
, or if the initial value of
X and the zero bracket the point
, it is likely that an error exit with
,
or
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
should not be input and may lead to an error exit with
,
or
. For the reasons discussed under
in
Section 6,
TOL should not be taken too large, say no larger than
.
For most problems, the time taken on each call to C05AXF will be negligible compared with the time spent evaluating
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
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.
9 Example
This example calculates a zero of with initial approximation , and and .
9.1 Program Text
Program Text (c05axfe.f90)
9.2 Program Data
None.
9.3 Program Results
Program Results (c05axfe.r)