bundles / scipy 1.17.1 / scipy / optimize / _chandrupatla / _chandrupatla
function
scipy.optimize._chandrupatla:_chandrupatla
Signature
def _chandrupatla ( func , a , b , * , args = () , xatol = None , xrtol = None , fatol = None , frtol = 0 , maxiter = None , callback = None ) Summary
Find the root of an elementwise function using Chandrupatla's algorithm.
Extended Summary
For each element of the output of func, chandrupatla seeks the scalar root that makes the element 0. This function allows for a, b, and the output of func to be of any broadcastable shapes.
Parameters
func: callableThe function whose root is desired. The signature must be
func(x: ndarray, *args) -> ndarray where each element of ``x`` is a finite real and ``args`` is a tuple, which may contain an arbitrary number of components of any type(s). ``func`` must be an elementwise function: each element ``func(x)[i]`` must equal ``func(x[i])`` for all indices ``i``. `_chandrupatla` seeks an array ``x`` such that ``func(x)`` is an array of zeros.
a, b: array_likeThe lower and upper bounds of the root of the function. Must be broadcastable with one another.
args: tuple, optionalAdditional positional arguments to be passed to
func.xatol, xrtol, fatol, frtol: float, optionalAbsolute and relative tolerances on the root and function value. See Notes for details.
maxiter: int, optionalThe maximum number of iterations of the algorithm to perform. The default is the maximum possible number of bisections within the (normal) floating point numbers of the relevant dtype.
callback: callable, optionalAn optional user-supplied function to be called before the first iteration and after each iteration. Called as
callback(res), whereresis a_RichResultsimilar to that returned by _chandrupatla (but containing the current iterate's values of all variables). Ifcallbackraises aStopIteration, the algorithm will terminate immediately and _chandrupatla will return a result.
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.x
x
nfev
nfev
nit
nit
status
status
success
success
fun
fun
xl,xr
xl, xr
fl,fr
fl, fr
Notes
Implemented based on Chandrupatla's original paper [1].
If xl and xr are the left and right ends of the bracket, xmin = xl if abs(func(xl)) <= abs(func(xr)) else xr, and fmin0 = min(func(a), func(b)), then the algorithm is considered to have converged when abs(xr - xl) < xatol + abs(xmin) * xrtol or fun(xmin) <= fatol + abs(fmin0) * frtol. This is equivalent to the termination condition described in [1] with xrtol = 4e-10, xatol = 1e-5, and fatol = frtol = 0. The default values are xatol = 4*tiny, xrtol = 4*eps, frtol = 0, and fatol = tiny, where eps and tiny are the precision and smallest normal number of the result dtype of function inputs and outputs.
Examples
from scipy import optimize def f(x, c): return x**3 - 2*x - c c = 5 res = optimize._chandrupatla._chandrupatla(f, 0, 3, args=(c,))✓
res.x
✗c = [3, 4, 5] res = optimize._chandrupatla._chandrupatla(f, 0, 3, args=(c,))✓
res.x
✗See also
Aliases
-
scipy.optimize._chandrupatla._chandrupatla