bracket_root()

rootfinding.bracket_root(f, interval, growth_factor=2, maxiter=100, f_interval=(None, None), ftol=None)

Find an interval that brackets a root of a function by searching in one direction.

Starting from an interval, it moves and expands the interval in the direction of the second endpoint until the interval brackets a root of the given function.

Parameters
  • f (callable) – Continuous scalar function.

  • interval (sequence of two floats) – Starting interval. Must have non-equal endpoints, but they do not need to be listed in order. During the search, the interval will be shifted and expanded in the direction of interval[1].

  • growth_factor (float, optional) – Factor by which to grow the width of the working interval between iterations. Must be >= 1.

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

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

  • ftol (None or float) – An optional absolute tolerance for the value of f at a root. If given, the algorithm will immediately return any root it happens to discover in its execution.

Returns

result – Normally contains a bracket and no root. However, if ftol is not None and a root is found, it will contain that root; in this case, the result will also include a bracket only if one was found at the same time as the root.

Return type

Result

See also

bisect

Notes

If ftol is not None and both endpoints of the starting interval qualify as roots, the one where the absolute value of f is lower is chosen as the root.