bisection

sherpa.utils.bisection(fcn, xa, xb, fa=None, fb=None, args=(), maxfev=48, tol=1e-06)[source] [edit on github]

A basic root finding algorithm that uses standard bisection

Bisection is a relatively slow method for root finding, but it guaranteed to work for a continuous function with a root in a bracketed interval; in other words the function must undergo a sign change between the bracketing values.

See https://en.wikipedia.org/wiki/Bisection_method for a description of the bisection method.

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.