c05azc locates a simple zero of a continuous function in a given interval by using Brent's method, which is a combination of nonlinear interpolation, linear extrapolation and bisection. It uses reverse communication for evaluating the function.
The function may be called by the names: c05azc, nag_roots_contfn_brent_rcomm or nag_zero_cont_func_brent_rcomm.
You must supply x and y to define an initial interval containing a simple zero of the function (the choice of x and y
must be such that ). The function combines the methods of bisection, nonlinear interpolation and linear extrapolation (see Dahlquist and Björck (1974)), to find a sequence of sub-intervals of the initial interval such that the final interval contains the zero and is less than some tolerance specified by tolx and ir (see Section 5). In fact,
since the intermediate intervals are determined only so that , it is possible that the final interval may contain a discontinuity or a pole of
(violating the requirement that be continuous). c05azc checks if the sign change is likely to correspond to a pole of and gives an error return in this case.
A feature of the algorithm used by this function is that unlike some other methods it guarantees convergence within about function evaluations, where is related to the argument tolx. See Brent (1973) for more details.
c05azc returns to the calling program for each evaluation of . On each return you should set and call c05azc
The function is a modified version of procedure ‘zeroin’ given by Brent (1973).
Brent R P (1973) Algorithms for Minimization Without Derivatives Prentice–Hall
Bus J C P and Dekker T J (1975) Two efficient algorithms with guaranteed convergence for finding a zero of a function ACM Trans. Math. Software1 330–345
Dahlquist G and Björck Å (1974) Numerical Methods Prentice–Hall
Note: this function 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: – double *Input/Output
2: – double *Input/Output
On initial entry: x and y must define an initial interval containing the zero, such that . It is not necessary that .
On intermediate exit:
x contains the point at which must be evaluated before re-entry to the function.
On final exit: x and y define a smaller interval containing the zero, such that , and satisfies the accuracy specified by tolx and ir, unless an error has occurred. If NE_PROBABLE_POLE, x and y generally contain very good approximations to a pole; if NW_TOO_MUCH_ACC_REQUESTED, x and y generally contain very good approximations to the zero (see Section 6). If a point x is found such that , on final exit (in this case there is no guarantee that x is a simple zero). In all cases, the value returned in x is the better approximation to the zero.
On intermediate exit:
contains , or . The calling program must evaluate at x, storing the result in fx, and re-enter c05azc with all other arguments unchanged.
On final exit: contains .
on entry , , , or .
Note: any values you return to c05azc 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 c05azc. If your code inadvertently does return any NaNs or infinities, c05azc is likely to produce unexpected results.
8: – NagError *Input/Output
The NAG error argument (see Section 7 in the Introduction to the NAG Library CL Interface).
6Error Indicators and Warnings
Dynamic memory allocation failed.
See Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
On entry, argument had an illegal value.
On entry, .
Constraint: , , , or .
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 8 in the Introduction to the NAG Library CL Interface for further information.
On entry, and have the same sign with neither equalling : and .
The final interval may contain a pole rather than a zero. Note that this error exit is not completely reliable: it may be taken in extreme cases when contains a zero, or it may not be taken when contains a pole. Both these cases occur most frequently when tolx is large.
On entry, .
The tolerance tolx has been set too small for the problem being solved. However, the values x and y returned may well be good approximations to the zero. .
The accuracy of the final value x as an approximation of the zero is determined by tolx and ir (see Section 5). A relative accuracy criterion () should not be used when the initial values x and y are of different orders of magnitude. In this case a change of origin of the independent variable may be appropriate. For example, if the initial interval is transformed linearly to the interval , then the zero can be determined to a precise number of figures using an absolute
() or relative () error test and the effect of the transformation back to the original interval can also be determined. Except for the accuracy check, such a transformation has no effect on the calculation of the zero.
8Parallelism and Performance
Background information to multithreading can be found in the Multithreading documentation.
c05azc is not threaded in any implementation.
For most problems, the time taken on each call to c05azc will be negligible compared with the time spent evaluating between calls to c05azc.
If the calculation terminates because ,
then on return y is set to x. (In fact, on return only in this case and, possibly, when NW_TOO_MUCH_ACC_REQUESTED.) There is no guarantee that the value returned in x corresponds to a simple
root and you should check whether it does. One way to check this is to compute the derivative of at the point x, preferably analytically, or, if this is not possible, numerically, perhaps by using a central difference estimate. If , then x must correspond to a multiple zero of rather than a simple zero.
This example calculates a zero of with an initial interval , and a mixed error test.