zeroin

sherpa.utils.zeroin(fcn, xa, xb, fa=None, fb=None, args=(), maxfev=32, tol=0.01)[source] [edit on github]

Obtain a zero of a function of one variable using Brent’s root finder.

Return an approximate location for the root with accuracy:

4*DBL_EPSILON*abs(x) + tol

using the algorithm from [1].

Parameters:
fcncallable()

The function with a root. The function signature is fcn(x, *args).

xafloat

Lower limit of the bracketing interval

xbfloat

Upper limit of the bracketing interval

fafloat or None

Function value at xa. This parameter is optional and can be passed to save time in cases where fcn(xa, *args) is already known and function evaluation takes a long time. If None, it will be calculated.

fbfloat or None

Function value at xb. This parameter is optional and can be passed to save time in cases where fcn(xb, *args) is already known and function evaluation takes a long time. If None, it will be calculated.

argstuple

Additional parameters that will be passed through to fcn.

maxfevint

Maximal number of function evaluations

tolfloat

The root finding algorithm stops if a value x with abs(fcn(x)) < tol is found.

Returns:
outlist

The output has the form of a list: [[x, fcn(x)], [x1, fcn(x1)], [x2, fcn(x2)], nfev] where x is the location of the root, and x1 and x2 are the previous steps. The function value for those steps is returned as well. nfev is the total number of function evaluations. If any of those values is not available, None will be returned instead.

Notes

The function makes use of a bisection procedure combined with a linear or quadratic inverse interpolation.

At each step the code operates three abscissae - a, b, and c:

  • b - the last and the best approximation to the root

  • a - the last but one approximation

  • c - the last but one or even an earlier approximation such that:

    1. |f(b)| <= |f(c)|

    2. f(b) and f(c) have opposite signs, i.e. b and c encompass the root

Given these abscissae, the code computes two new approximations, one by the bisection procedure and the other one from interpolation (if a,b, and c are all different the quadratic interpolation is used, linear otherwise). If the approximation obtained by the interpolation looks reasonable (i.e. falls within the current interval [b,c], not too close to the end points of the interval), the point is accepted as a new approximation to the root. Otherwise, the result of the bissection is used.

References

[1]

G.Forsythe, M.Malcolm, C.Moler, Computer methods for mathematical computations. M., Mir, 1980, p.180 of the Russian edition