cmlabs.optimize.find_root_brackets

cmlabs.optimize.find_root_brackets(f, a, b, bins=10)[source]

Find the root brackets of a function.

Parameters:
  • f (callable) – The function to find the root brackets for.

  • a (float) – The lower bound of the interval.

  • b (float) – The upper bound of the interval.

  • bins (int, optional) – The number of bins to use for the search.

Returns:

A list of tuples containing the lower and upper bounds of each root bracket.

Return type:

list of tuples

Notes

The function passed to this method must be continuous on the interval \([a, b]\). According to the Bolzano–Cauchy theorem, if a continuous function \(f\) satisfies \(f(a) \cdot f(b) < 0\), then there exists at least one point \(c \in (a, b)\) such that \(f(c) = 0\).

Examples

>>> from cmlabs.optimize import find_root_brackets
>>> f = lambda x: x**2 - 4
>>> a = 0
>>> b = 10
>>> bins = 10
>>> find_root_brackets(f, a, b, bins)
>>> # [(np.float64(1.1111111111111112), np.float64(2.2222222222222223))]