idlastro / Math and Statistics: ZBRENT

[Source code]

NAME
ZBRENT
PURPOSE
Find the zero of a 1-D function up to specified tolerance.
EXPLANTION
This routine assumes that the function is known to have a zero.
Adapted from procedure of the same name in "Numerical Recipes" by
Press et al. (1992), Section 9.3
CALLING
x_zero = ZBRENT( x1, x2, FUNC_NAME="name", MaX_Iter=, Tolerance=, 
                          _EXTRA =  )
INPUTS
x1, x2 = scalars, 2 points which bracket location of function zero,
                                        that is, F(x1) < 0 < F(x2).
Note: computations are performed with
same precision (single/double) as the inputs and user supplied function.
REQUIRED INPUT KEYWORD
FUNC_NAME = function name (string)
        Calling mechanism should be:  F = func_name( px )
        where:  px = scalar independent variable, input.
                F = scalar value of function at px,
                    should be same precision (single/double) as input.
OPTIONAL INPUT KEYWORDS
MAX_ITER = maximum allowed number iterations, default=100.
TOLERANCE = desired accuracy of minimum location, default = 1.e-3.
Any other keywords are passed directly to the user-supplied function
via the _EXTRA facility.
OUTPUTS
Returns the location of zero, with accuracy of specified tolerance.
PROCEDURE
Brent's method to find zero of a function by using bracketing,
bisection, and inverse quadratic interpolation,
EXAMPLE
Find the root of the COSINE function between 1. and 2.  radians
 IDL> print, zbrent( 1, 2, FUNC = 'COS')
and the result will be !PI/2 within the specified tolerance
MODIFICATION HISTORY
Written, Frank Varosi NASA/GSFC 1992.
FV.1994, mod to check for single/double prec. and set zeps accordingly.
Use MACHAR() to define machine precision   W. Landsman September 2002
Added _EXTRA keyword  W. Landsman  December 2011
Need to check whether user function accepts keywords W.L. Jan 2012