bundles / scipy 1.17.1 / scipy / optimize / _bracket / _bracket_root
function
scipy.optimize._bracket:_bracket_root
source: /scipy/optimize/_bracket.py :72
Signature
def _bracket_root ( func , xl0 , xr0 = None , * , xmin = None , xmax = None , factor = None , args = () , maxiter = 1000 ) Summary
Bracket the root of a monotonic scalar function of one variable
Extended Summary
This function works elementwise when xl0, xr0, xmin, xmax, factor, and the elements of args are broadcastable arrays.
Parameters
func: callableThe function for which the root is to be bracketed. The signature must be
func(x: ndarray, *args) -> ndarraywhere each element of
xis a finite real andargsis a tuple, which may contain an arbitrary number of arrays that are broadcastable withx.funcmust be an elementwise function: each elementfunc(x)[i]must equalfunc(x[i])for all indicesi.xl0, xr0: float array_likeStarting guess of bracket, which need not contain a root. If
xr0is not provided,xr0 = xl0 + 1. Must be broadcastable with one another.xmin, xmax: float array_like, optionalMinimum and maximum allowable endpoints of the bracket, inclusive. Must be broadcastable with
xl0andxr0.factor: float array_like, default: 2The factor used to grow the bracket. See notes for details.
args: tuple, optionalAdditional positional arguments to be passed to
func. Must be arrays broadcastable withxl0,xr0,xmin, andxmax. If the callable to be bracketed requires arguments that are not broadcastable with these arrays, wrap that callable withfuncsuch thatfuncaccepts onlyxand broadcastable arrays.maxiter: int, optionalThe maximum number of iterations of the algorithm to perform.
Returns
res: _RichResultAn instance of scipy._lib._util._RichResult with the following attributes. The descriptions are written as though the values will be scalars; however, if
funcreturns an array, the outputs will be arrays of the same shape.xl,xr
xl, xr
fl,fr
fl, fr
nfev
nfev
nit
nit
status
status
success
success
Notes
This function generalizes an algorithm found in pieces throughout scipy.stats. The strategy is to iteratively grow the bracket (l, r) until func(l) < 0 < func(r). The bracket grows to the left as follows.
If
xminis not provided, the distance betweenxl0andlis iteratively increased byfactor.If
xminis provided, the distance betweenxminandlis iteratively decreased byfactor. Note that this also increases the bracket size.
Growth of the bracket to the right is analogous.
Growth of the bracket in one direction stops when the endpoint is no longer finite, the function value at the endpoint is no longer finite, or the endpoint reaches its limiting value (xmin or xmax). Iteration terminates when the bracket stops growing in both directions, the bracket surrounds the root, or a root is found (accidentally).
If two brackets are found - that is, a bracket is found on both sides in the same iteration, the smaller of the two is returned. If roots of the function are found, both l and r are set to the leftmost root.
Aliases
-
scipy.optimize._bracket._bracket_root