bisect()

rootfinding.bisect(f, bracket, ftol=1e-12, maxiter=100, f_bracket=None, None)

Find root of a function within a bracket using the bisection method.

The function must have opposite signs at the endpoints of the bracket.

Compared to SciPy’s scipy.optimize.bisect() and scipy.optimize.root_scalar() functions, this function tests for a root by looking only at the residual (i.e., the value of f).

Parameters
  • f (callable) – Continuous scalar function.

  • bracket (sequence of two floats) – An interval bracketing a root. f must have different signs at the two endpoints, or a NotABracketError will be raised. The endpoints do not need to be listed in order.

  • ftol (float, optional) – Absolute tolerance for the value of f at the root. Must be nonnegative.

  • maxiter (int or None, optional) – Maximum number of iterations. Must be nonnegative. An IterationLimitReached exception will be raised if the specified tolerance is not achieved within this number of iterations. If None, there is no maximum number of iterations.

  • f_bracket (sequence of two of {None, float}, optional) – Values of f at the endpoints of bracket, if known (use None if a value is not known). For every known value, one fewer call to f will be required.

Returns

result – Contains the root and the final bracket.

Return type

Result

See also

bracket_root()

Search for a bracket.

Notes

The function starts by testing the endpoints of the bracket. If a root is found at one of the endpoints of a valid bracket, no bisection iterations are performed and the root is immediately returned. If both endpoints qualify as roots, the one where the absolute value of f is lower is returned.