scipy.optimize — Root finding and minimization

The scipy.optimize submodule provides simple routines for finding roots and minima of user-defined scalar functions. Because each iteration must call back into the user-supplied Python callable, the speed gain over a pure-Python implementation is modest (typically about 2x).

Functions

scipy.optimize.bisect(f: Callable[[float], float], a: float, b: float, *, xtol: float = xtolerance, maxiter: int = 100) float

Find a root of f in the bracket [a, b] using the bisection method. f must change sign on the interval.

Parameters:
  • f – callable taking a single float and returning a float.

  • a – left endpoint of the bracket.

  • b – right endpoint of the bracket.

  • xtol – absolute tolerance on the root location (default xtolerance).

  • maxiter – maximum number of bisections (default 100).

Returns:

the location of the root as a float.

Raises:

ValueError – if f(a) * f(b) > 0.

scipy.optimize.curve_fit(f: Callable[..., float], xdata: ndarray | list | tuple, ydata: ndarray | list | tuple, p0: ndarray | list | tuple, *, xatol: float = xtolerance, fatol: float = xtolerance, maxiter: int | None = None) None

Stub for non-linear least-squares curve fitting (Levenberg-Marquardt). Present in the module table for API compatibility but currently a placeholder: it accepts and validates its arguments but always returns None. Prefer fmin() or external libraries until this routine is implemented.

Parameters:
  • f – model callable f(x, *params) -> float.

  • xdata – 1-D array-like of independent values.

  • ydata – 1-D array-like of dependent values, same length as xdata.

  • p0 – 1-D array-like of initial parameter estimates.

scipy.optimize.fmin(f: Callable[[float], float], x0: float, *, xatol: float = xtolerance, fatol: float = xtolerance, maxiter: int = 200) float

Find the position of a local minimum of the scalar function f using the downhill simplex (Nelder-Mead) method.

Parameters:
  • f – callable taking a single float and returning a float.

  • x0 – initial guess.

  • xatol – absolute tolerance on the position (default xtolerance).

  • fatol – absolute tolerance on the function value (default xtolerance).

  • maxiter – maximum number of iterations (default 200).

Returns:

the location of the minimum as a float.

scipy.optimize.newton(f: Callable[[float], float], x0: float, *, tol: float = xtolerance, rtol: float = rtolerance, maxiter: int = 50) float

Find a zero of the real-valued, scalar function f by the Newton-Raphson (secant) method.

Parameters:
  • f – callable taking a single float and returning a float.

  • x0 – initial guess.

  • tol – absolute tolerance on the root (default xtolerance).

  • rtol – relative tolerance on the root (default rtolerance).

  • maxiter – maximum number of iterations (default 50).

Returns:

the location of the root as a float.