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.
The routine may be called by the names c05axf or nagf_roots_contfn_cntin_rcomm.
3Description
c05axf uses a modified version of an algorithm given in Swift and Lindfield (1978) to compute a zero $\alpha $ of a continuous function $f\left(x\right)$. The algorithm used is based on a continuation method in which a sequence of problems
are solved, where $1={\theta}_{0}>{\theta}_{1}>\cdots >{\theta}_{m}=0$
(the value of $m$ is determined as the algorithm proceeds) and where ${x}_{0}$ is your initial estimate for the zero of $f\left(x\right)$. For each ${\theta}_{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 (${\theta}_{m}=0$)
in the continuation method, and $\sqrt{{\mathbf{tol}}}$ is used to control the accuracy in the intermediate problems
(${\theta}_{1},{\theta}_{2},\dots ,{\theta}_{m-1}$).
4References
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
5Arguments
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 argument ind. Between intermediate exits and re-entries, all arguments other thanfx must remain unchanged.
1: $\mathbf{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: $\mathbf{fx}$ – Real (Kind=nag_wp)Input
On initial entry: if ${\mathbf{ind}}=1$, fx need not be set.
If ${\mathbf{ind}}=\mathrm{-1}$, fx must contain $f\left({\mathbf{x}}\right)$ for the initial value of x.
On intermediate re-entry: must contain $f\left({\mathbf{x}}\right)$ for the current value of x.
3: $\mathbf{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 (${\theta}_{m}=0$ in Section 3), and $\sqrt{{\mathbf{tol}}}$ is used for the problem defined by ${\theta}_{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:
${\mathbf{tol}}>0.0$.
4: $\mathbf{ir}$ – IntegerInput
On initial entry: indicates the type of error test required, as follows. Solving the problem defined by ${\theta}_{r}$, $1\le r\le m$, involves computing a sequence of secant iterates ${x}_{r}^{0},{x}_{r}^{1},\dots \text{}$. This sequence will be considered to have converged only if:
for some $i>1$; here $\mathit{eps}$ is either tol or $\sqrt{{\mathbf{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:
${\mathbf{ir}}=0$, $1$ or $2$.
5: $\mathbf{scal}$ – Real (Kind=nag_wp)Input
On initial entry: a factor for use in determining a significant approximation to the derivative of $f\left(x\right)$ at $x={x}_{0}$, the initial value. A number of difference approximations to ${f}^{\prime}\left({x}_{0}\right)$ are calculated using
where $\left|h\right|<\left|{\mathbf{scal}}\right|$ 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:
$\sqrt{\epsilon}$, where $\epsilon $ is the machine precision returned by x02ajf.
Constraint:
${\mathbf{scal}}$ must be sufficiently large that ${\mathbf{x}}+{\mathbf{scal}}\ne {\mathbf{x}}$ on the computer.
6: $\mathbf{c}\left(26\right)$ – Real (Kind=nag_wp) arrayCommunication Array
(${\mathbf{c}}\left(5\right)$ contains the current ${\theta}_{r}$, this value may be useful in the event of an error exit.)
7: $\mathbf{ind}$ – IntegerInput/Output
On initial entry: must be set to $1$ or $\mathrm{-1}$.
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 arguments unchanged.
On final exit: contains $0$.
Constraint:
on entry ${\mathbf{ind}}=\mathrm{-1}$, $1$, $2$, $3$ or $4$.
Note: any values you return to c05axf as part of the reverse communication procedure should not include floating-point NaN (Not a Number) or infinity values, since these are not handled by c05axf. If your code does inadvertently return any NaNs or infinities, c05axf is likely to produce unexpected results.
8: $\mathbf{ifail}$ – IntegerInput/Output
On initial entry: ifail must be set to $0$, $\mathrm{-1}$ or $1$ to set behaviour on detection of an error; these values have no effect when no error is detected.
A value of $0$ causes the printing of an error message and program execution will be halted; otherwise program execution continues. A value of $\mathrm{-1}$ means that an error message is printed while a value of $1$ means that it is not.
If halting is not appropriate, the value $\mathrm{-1}$ or $1$ is recommended. If message printing is undesirable, then the value $1$ is recommended. Otherwise, the value $\mathrm{-1}$ is recommended since useful values can be provided in some output arguments even when ${\mathbf{ifail}}\ne {\mathbf{0}}$ on exit. When the value $-\mathbf{1}$ or $\mathbf{1}$ is used it is essential to test the value of ifail on exit.
On final exit: ${\mathbf{ifail}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).
6Error Indicators and Warnings
If on entry ${\mathbf{ifail}}=0$ or $\mathrm{-1}$, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
${\mathbf{ifail}}=1$
On entry, ${\mathbf{ir}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{ir}}=0$, $1$ or $2$.
On entry, ${\mathbf{tol}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{tol}}>0.0$.
${\mathbf{ifail}}=2$
On initial entry, ${\mathbf{ind}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{ind}}=\mathrm{-1}$ or $1$.
On intermediate entry, ${\mathbf{ind}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{ind}}=2$, $3$ or $4$.
${\mathbf{ifail}}=3$
On entry, ${\mathbf{scal}}=\u27e8\mathit{\text{value}}\u27e9$.
Constraint: ${\mathbf{x}}+{\mathbf{scal}}\ne {\mathbf{x}}$ (to machine accuracy).
Significant derivatives of $f$ cannot be computed. This can happen when $f$ is almost constant and nonzero, for any value of scal.
${\mathbf{ifail}}=4$
Current problem in the continuation sequence cannot be solved. Perhaps the original problem had no solution or the continuation path passes through a set of insoluble problems: consider refining the initial approximation to the zero. Alternatively, tol is too small, and the accuracy requirement is too stringent, or too large and the initial approximation too poor.
${\mathbf{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.
${\mathbf{ifail}}=6$
Final problem (with ${\theta}_{m}=0$) cannot be solved. It is likely that too much accuracy has been requested, or that the zero is at $\alpha =0$ and ${\mathbf{ir}}=2$.
${\mathbf{ifail}}=-99$
An unexpected error has been triggered by this routine. Please
contact NAG.
See Section 7 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library FL Interface for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 9 in the Introduction to the NAG Library FL Interface for further information.
7Accuracy
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 (${\mathbf{ir}}=2$).
If the zero is at ${\mathbf{x}}=0$, or if the initial value of x and the zero bracket the point ${\mathbf{x}}=0$, it is likely that an error exit with ${\mathbf{ifail}}={\mathbf{4}}$, ${\mathbf{5}}$ or ${\mathbf{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 ${\mathbf{tol}}\ll \mathit{machineprecision}$ should not be input and may lead to an error exit with ${\mathbf{ifail}}={\mathbf{4}}$, ${\mathbf{5}}$ or ${\mathbf{6}}$. For the reasons discussed under ${\mathbf{ifail}}={\mathbf{4}}$ in Section 6,
tol should not be taken too large, say no larger than ${\mathbf{tol}}=\text{1.0E\u22123}$.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
c05axf is not threaded in any implementation.
9Further Comments
For most problems, the time taken on each call to c05axf will be negligible compared with the time spent evaluating $f\left(x\right)$ 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.
10Example
This example calculates a zero of $x-{e}^{-x}$ with initial approximation ${x}_{0}=1.0$, and ${\mathbf{tol}}=\text{1.0E\u22123}$ and $\text{1.0E\u22124}$.