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].



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.