c05ax 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.

# Syntax

C# |
---|

public static void c05ax( ref double x, double fx, double tol, int ir, double scal, double[] c, ref int ind, out int ifail ) |

Visual Basic |
---|

Public Shared Sub c05ax ( _ ByRef x As Double, _ fx As Double, _ tol As Double, _ ir As Integer, _ scal As Double, _ c As Double(), _ ByRef ind As Integer, _ <OutAttribute> ByRef ifail As Integer _ ) |

Visual C++ |
---|

public: static void c05ax( double% x, double fx, double tol, int ir, double scal, array<double>^ c, int% ind, [OutAttribute] int% ifail ) |

F# |
---|

static member c05ax : x : float byref * fx : float * tol : float * ir : int * scal : float * c : float[] * ind : int byref * ifail : int byref -> unit |

#### Parameters

- x
- Type: System..::..Double%
*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 method.*On final exit*: the final approximation to the zero.

- fx
- Type: System..::..Double

- tol
- Type: System..::..Double
*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 [Description]), 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$.

- ir
- Type: System..::..Int32
*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 ${\mathbf{ir}}=0$,for ${\mathbf{ir}}=1$,$$\left|{x}_{r}^{\left(i+1\right)}-{x}_{r}^{\left(i\right)}\right|\le \mathit{eps}\times \mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1.0,\left|{x}_{r}^{\left(i\right)}\right|\right)\text{,}$$ for ${\mathbf{ir}}=2$,$$\left|{x}_{r}^{\left(i+1\right)}-{x}_{r}^{\left(i\right)}\right|\le \mathit{eps}\text{,}$$ 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.$$\left|{x}_{r}^{\left(i+1\right)}-{x}_{r}^{\left(i\right)}\right|\le \mathit{eps}\times \left|{x}_{r}^{\left(i\right)}\right|\text{,}$$ *Constraint*: ${\mathbf{ir}}=0$, $1$ or $2$.

- scal
- Type: System..::..Double
*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 usingwhere $\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.$${f}^{\prime}\left({x}_{0}\right)\sim \left(f\left({x}_{0}+h\right)-f\left({x}_{0}\right)\right)/h$$ *Constraint*: ${\mathbf{scal}}$ must be sufficiently large that ${\mathbf{x}}+{\mathbf{scal}}\ne {\mathbf{x}}$ on the computer.

- c
- Type: array<System..::..Double>[]()[][]An array of size [$26$](${\mathbf{c}}\left[4\right]$ contains the current ${\theta}_{r}$, this value may be useful in the event of an error exit.)

- ind
- Type: System..::..Int32%
*On initial entry*: must be set to $1$ or $-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 c05ax with all other parameters unchanged.*On final exit*: contains $0$.*Constraint*: on entry ${\mathbf{ind}}=-1$, $1$, $2$, $3$ or $4$.

- ifail
- Type: System..::..Int32%
*On initial entry*: ifail must be set to $0$, $-1\text{ or}1$. If you are unfamiliar with this parameter you should refer to**Library Overview**for details.For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{ or}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, because for this method the values of the output parameters may be useful even if ${\mathbf{ifail}}\ne {0}$ on exit, the recommended value is $-1$.**When the value $-\mathbf{1}\text{ or}1$ is used it is essential to test the value of ifail on exit.***On final exit*: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

c05ax 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.

$$f\left(x\right)-{\theta}_{r}f\left({x}_{0}\right)\text{, \hspace{1em}}r=0,1,\dots ,m$$ |

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}$).

# 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# Error Indicators and Warnings

Errors or warnings detected by the method:

- ${\mathbf{ifail}}=1$
On entry, ${\mathbf{tol}}\le 0.0$, or ${\mathbf{ir}}\ne 0$, $1$ or $2$.

- ${\mathbf{ifail}}=2$
- The parameter ind is incorrectly set on initial or intermediate entry.

- ${\mathbf{ifail}}=3$

- ${\mathbf{ifail}}=4$
- The current problem in the continuation sequence cannot be solved, see ${\mathbf{c}}\left[4\right]$ for the value of ${\theta}_{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.

- ${\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$
- The 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$.

# 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 (${\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}}={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 ${\mathbf{tol}}\ll \mathit{machineprecision}$ should not be input and may lead to an error exit with ${\mathbf{ifail}}={4}$, ${5}$ or ${6}$. For the reasons discussed under ${\mathbf{ifail}}={4}$ in [Error Indicators and Warnings],
tol should not be taken too large, say no larger than ${\mathbf{tol}}=\text{1.0E\u22123}$.

# Parallelism and Performance

None.

# Further Comments

For most problems, the time taken on each call to c05ax will be negligible compared with the time spent evaluating $f\left(x\right)$ between calls to c05ax. 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.

# Example

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}$.