pynbody.util.bisect#
- pynbody.util.bisect(left, right, f, epsilon=None, eta=0, niter_max=200)[source]#
Finds the value x such that f(x)=0 for a monotonically increasing function f, using a binary search.
The search stops when either the bounding domain is smaller than epsilon (by default 10^-7 times the original region) OR a value f(x) is found such that |f(x)|<eta (by default eta=0, so this criterion is never satisfied).
- Parameters:
left (float) – The left-hand boundary of the search region
right (float) – The right-hand boundary of the search region
f (function) – The function to find the root of
epsilon (float, optional) – The tolerance for the search. If not specified, this is set to 10^-7 times the original region.
eta (float, optional) – The tolerance for the function value. If a value f(x) is found such that |f(x)|<eta, the search stops.
niter_max (int, optional) – The maximum number of iterations to perform. If the search does not converge after this, a ValueError is raised.
- Returns:
The value x such that f(x)=0
- Return type:
float