NAG Library Chapter Introduction
C05 (roots)
Roots of One or More Transcendental Equations
1
Scope of the Chapter
This chapter is concerned with the calculation of zeros of continuous functions of one or more variables. The majority of problems considered are for realvalued functions of real variables, in which case complex equations must be expressed in terms of the equivalent larger system of real equations.
2
Background to the Problems
The chapter divides naturally into two parts.
2.1
A Single Equation
The first deals with the real zeros of a real function of a single variable $f\left(x\right)$.
There are three routines with simple calling sequences. The first assumes that you can determine an initial interval
$\left[a,b\right]$ within which the desired zero lies, (that is, where
$f\left(a\right)\times f\left(b\right)<0$), and outside which all other zeros lie. The routine then systematically subdivides the interval to produce a final interval containing the zero. This final interval has a length bounded by your specified error requirements; the end of the interval where the function has smallest magnitude is returned as the zero. This routine is guaranteed to converge to a
simple zero of the function. (Here we define a simple zero as a zero corresponding to a signchange of the function; none of the available routines are capable of making any finer distinction.) However, as with the other routines described below, a nonsimple zero might be determined and it is left to you to check for this. The algorithm used is due to
Brent (1973).
The two other routines are both designed for the case where you are unable to specify an interval containing the simple zero. One starts from an initial point and performs a search for an interval containing a simple zero. If such an interval is computed then the method described above is used next to determine the zero accurately. The other method uses a ‘continuation’ method based on a secant iteration. A sequence of subproblems is solved; the first of these is trivial and the last is the actual problem of finding a zero of $f\left(x\right)$. The intermediate problems employ the solutions of earlier problems to provide initial guesses for the secant iterations used to calculate their solutions.
Three other routines are also supplied. They employ reverse communication and use the same core algorithms as the routines described above.
Finally, two routines are provided to return values of Lambert's
$W$ function (sometimes known as the ‘product log’ or ‘Omega’ function), which is the inverse function of
that is, if Lambert's
$W$ function
$W\left(x\right)=a$ for
$x,a\in C$, then
$a$ is a zero of the function
$F\left(w\right)=w{e}^{w}x$. One routine uses the iterative method described in
Barry et al. (1995) to return values from the real branches of
$W$ (restricting
$x,a\in R$). The second routine enforces no such restriction, and uses the approach described in
Corless et al. (1996).
2.2
Systems of Equations
The routines in the second part of this chapter are designed to solve a set of nonlinear equations in
$n$ unknowns
where
$\mathrm{T}$ stands for transpose.
It is assumed that the functions are continuous and differentiable so that the matrix of first partial derivatives of the functions, the Jacobian matrix ${J}_{ij}\left(x\right)=\left(\frac{\partial {f}_{i}}{\partial {x}_{j}}\right)$ evaluated at the point $x$, exists, though it may not be possible to calculate it directly.
The functions ${f}_{i}$ must be independent, otherwise there will be an infinity of solutions and the methods will fail. However, even when the functions are independent the solutions may not be unique. Since the methods are iterative, an initial guess at the solution has to be supplied, and the solution located will usually be the one closest to this initial guess.
3
Recommendations on Choice and Use of Available Routines
3.1
Zeros of Functions of One Variable
The routines can be divided into two classes. There are three routines (
c05avf,
c05axf and
c05azf) all written in reverse communication form and three (
c05auf,
c05awf and
c05ayf) written in direct communication form (see
Section 3.3.3 in How to Use the NAG Library and its Documentation for a description of the difference between these two conventions). The direct communication routines are designed for inexperienced users and, in particular, for solving problems where the function
$f\left(x\right)$ whose zero is to be calculated, can be coded as a usersupplied (sub)program. These routines find the zero by using the same core algorithms as the reverse communication routines. Experienced users are recommended to use the reverse communication routines directly as they permit you more control of the calculation. Indeed, if the zerofinding process is embedded in a much larger program then the reverse communication routines should always be used.
The recommendation as to which routine should be used depends mainly on whether you can supply an interval
$\left[a,b\right]$ containing the zero; that is, where
$f\left(a\right)\times f\left(b\right)<0$. If the interval can be supplied, then
c05ayf (or, in reverse communication,
c05azf) should be used, in general. This recommendation should be qualified in the case when the only interval which can be supplied is very long relative to your error requirements
and you can also supply a good approximation to the zero. In this case
c05awf (or, in reverse communication,
c05axf)
may prove more efficient (though these latter routines will not provide the error bound available from
c05azf).
If an interval containing the zero cannot be supplied then you must choose between
c05auf (or, in reverse communication,
c05avf followed by
c05azf) and
c05awf (or, in reverse communication,
c05axf).
c05auf first determines an interval containing the zero, and then proceeds as in
c05ayf; it is particularly recommended when you do not have a good initial approximation to the zero. If a good initial approximation to the zero is available then
c05awf is to be preferred. Since neither of these latter routines has guaranteed convergence to the zero, you are recommended to experiment with both in case of difficulty.
3.2
Solution of Sets of Nonlinear Equations
The solution of a set of nonlinear equations
can be regarded as a special case of the problem of finding a minimum of a sum of squares
So the routines in
Chapter E04 are relevant as well as the special nonlinear equations routines.
The routines for solving a set of nonlinear equations can also be divided into classes. There are five routines (
c05qbf,
c05qcf,
c05qsf,
c05rbf and
c05rcf) all written in direct communication form and three (
c05mdf,
c05qdf and
c05rdf) written in reverse communication form. The direct communication routines are designed for inexperienced users and, in particular, these routines require the
${f}_{i}$ (and possibly their derivatives) to be calculated in usersupplied subroutines. These should be set up carefully so the Library routines can work as efficiently as possible. Experienced users are recommended to use the reverse communication routines as they permit you more control of the calculation. Indeed, if the zerofinding process is embedded in a much larger program then the reverse communication routines should always be used.
The main decision you have to make is whether to supply the derivatives $\frac{\partial {f}_{i}}{\partial {x}_{j}}$. It is advisable to do so if possible, since the results obtained by algorithms which use derivatives are generally more reliable than those obtained by algorithms which do not use derivatives.
c05rbf,
c05rcf and
c05rdf require you to provide the derivatives, whilst
c05mdf,
c05qbf,
c05qcf,
c05qdf and
c05qsf do not.
c05qbf,
c05qsf and
c05rbf are easytouse routines; greater flexibility may be obtained using
c05qcf and
c05rcf (or, in reverse communication,
c05qdf and
c05rdf), but these have longer argument lists.
c05qbf,
c05qcf,
c05qdf and
c05qsf approximate the derivatives internally using finite differences.
c05mdf does not use derivatives at all, and may be useful when the cost of evaluating
$f\left(x\right)$ is high.
c05qsf is an easytouse routine specially adapted for sparse problems, that is, problems where each function depends on a small subset of the
$n$ variables so that the Jacobian matrix has many zeros. It employs sparse linear algebra methods and consequently is expected to take significantly less time to complete than the other routines, especially if
$n$ is large.
c05zdf is provided for use in conjunction with
c05rbf,
c05rcf and
c05rdf to check the usersupplied derivatives for consistency with the functions themselves. You are strongly advised to make use of this routine whenever
c05rbf,
c05rcf or
c05rdf is used.
Firstly, the calculation of the functions and their derivatives should be ordered so that cancellation errors are avoided. This is particularly important in a routine that uses these quantities to build up estimates of higher derivatives.
Secondly, scaling of the variables has a considerable effect on the efficiency of a routine. The problem should be designed so that the elements of $x$ are of similar magnitude. The same comment applies to the functions, i.e., all the ${f}_{i}$ should be of comparable size.
The accuracy is usually determined by the accuracy arguments of the routines, but the following points may be useful.
(i) 
Greater accuracy in the solution may be requested by choosing smaller input values for the accuracy arguments. However, if unreasonable accuracy is demanded, rounding errors may become important and cause a failure. 
(ii) 
Some idea of the accuracies of the ${x}_{i}$ may be obtained by monitoring the progress of the routine to see how many figures remain unchanged during the last few iterations. 
(iii) 
An approximation to the error in the solution $x$ is given by $e$ where $e$ is the solution to the set of linear equations
where $f\left(x\right)={\left({f}_{1}\left(x\right),{f}_{2}\left(x\right),\dots ,{f}_{n}\left(x\right)\right)}^{\mathrm{T}}$.
Note that the $QR$ decomposition of $J$ is available from c05qcf and c05rcf (or, in reverse communication, c05qdf and c05rdf) so that
and ${Q}^{\mathrm{T}}f$ is also provided by these routines. 
(iv) 
If the functions
${f}_{i}\left(x\right)$ are changed by small amounts ${\epsilon}_{i}$, for $\mathit{i}=1,2,\dots ,n$, then the corresponding change in the solution $x$ is given approximately by $\sigma $, where $\sigma $ is the solution of the set of linear equations
Thus one can estimate the sensitivity of $x$ to any uncertainties in the specification of
${f}_{i}\left(x\right)$, for $\mathit{i}=1,2,\dots ,n$. As noted above, the sophisticated routines c05qcf and c05rcf (or, in reverse communication, c05qdf and c05rdf) provide the $QR$ decomposition of $J$. 
3.3
Values of Lambert's $W$ function
If you require purelyreal values of
$W$, these will be evaluated marginally more efficiently by
c05baf than
c05bbf owing to the differing iterative procedures used by each routine.
4
Decision Trees
Tree 1: Functions of One Variable
Is reverse communication required? 

Is there available an interval $\left[a,b\right]$ containing a simple zero, and no others? 

c05azf 
yes  yes 
 no    no  

Is a good approximation to the zero available? 

c05axf 
 yes 
  no  

c05avf followed by c05azf 


Do you wish to compute the values of Lambert's $W$ function? 

do you require values from only the real branches? 

c05baf 
yes  yes 
 no    no  

c05bbf 


Is there available an interval $\left[a,b\right]$ containing a simple zero, and no others? 

c05ayf 
yes 
 no  
Is a good approximation to the zero available? 

c05awf 
yes 
 no  
c05auf 

Tree 2: Functions of several variables
Do you wish to avoid the use of the Jacobian matrix? 

c05mdf 
yes 
 no  
Is the Jacobian matrix sparse? 

c05qsf 
yes 
 no  
Is reverse communication required? 

Is the Jacobian matrix available? 

c05rdf and c05zdf 
yes  yes 
 no    no  

c05qdf 


Is the Jacobian matrix available? 

Is flexibility required? 

c05rcf and c05zdf 
yes  yes 
 no    no  

c05rbf and c05zdf 


Is flexibility required? 

c05qcf 
yes 
 no  
c05qbf 

5
Functionality Index
Zeros of functions of one variable,   
binary search followed by Brent algorithm   c05auf 
Zeros of functions of several variables,   
checks usersupplied Jacobian   c05zdf 
no derivatives required   c05qbf 
no derivatives required, sparse   c05qsf 
no derivatives required   c05qcf 
no derivatives required   c05qdf 
6
Auxiliary Routines Associated with Library Routine Arguments
None.
7
Routines Withdrawn or Scheduled for Withdrawal
The following lists all those routines that have been withdrawn since Mark 19 of the Library or are scheduled for withdrawal at one of the next two marks.
8
References
Anderson D G (1965) Iterative Procedures for Nonlinear Integral Equations J. Assoc. Comput. Mach. 12 547–560
Barry D J, Culligan–Hensley P J, and Barry S J (1995) Real values of the $W$function ACM Trans. Math. Software 21(2) 161–171
Brent R P (1973) Algorithms for Minimization Without Derivatives Prentice–Hall
Corless R M, Gonnet G H, Hare D E G, Jeffrey D J and Knuth D
E (1996) On the Lambert $W$ function Advances in Comp. Math. 3 329–359
Gill P E and Murray W (1976) Algorithms for the solution of the nonlinear least squares problem Report NAC 71 National Physical Laboratory
Moré J J, Garbow B S and Hillstrom K E (1980) User guide for MINPACK1 Technical Report ANL8074 Argonne National Laboratory
Ortega J M and Rheinboldt W C (1970) Iterative Solution of Nonlinear Equations in Several Variables Academic Press
Rabinowitz P (1970) Numerical Methods for Nonlinear Algebraic Equations Gordon and Breach