bundles / scipy latest / scipy / optimize / _minpack_py / fsolve
function
scipy.optimize._minpack_py:fsolve
Signature
def fsolve ( func , x0 , args = () , fprime = None , full_output = 0 , col_deriv = 0 , xtol = 1.49012e-08 , maxfev = 0 , band = None , epsfcn = None , factor = 100 , diag = None ) Summary
Find the roots of a function.
Extended Summary
Return the roots of the (non-linear) equations defined by func(x) = 0 given a starting estimate.
Parameters
func: callable ``f(x, *args)``A function that takes at least one (possibly vector) argument, and returns a value of the same length.
x0: ndarrayThe starting estimate for the roots of
func(x) = 0.args: tuple, optionalAny extra arguments to
func.fprime: callable ``f(x, *args)``, optionalA function to compute the Jacobian of
funcwith derivatives across the rows. By default, the Jacobian will be estimated.full_output: bool, optionalIf True, return optional outputs.
col_deriv: bool, optionalSpecify whether the Jacobian function computes derivatives down the columns (faster, because there is no transpose operation).
xtol: float, optionalThe calculation will terminate if the relative error between two consecutive iterates is at most
xtol.maxfev: int, optionalThe maximum number of calls to the function. If zero, then
100*(N+1)is the maximum where N is the number of elements inx0.band: tuple, optionalIf set to a two-sequence containing the number of sub- and super-diagonals within the band of the Jacobi matrix, the Jacobi matrix is considered banded (only for
fprime=None).epsfcn: float, optionalA suitable step length for the forward-difference approximation of the Jacobian (for
fprime=None). Ifepsfcnis less than the machine precision, it is assumed that the relative errors in the functions are of the order of the machine precision.factor: float, optionalA parameter determining the initial step bound (
factor * || diag * x||). Should be in the interval(0.1, 100).diag: sequence, optionalN positive entries that serve as a scale factors for the variables.
Returns
x: ndarrayThe solution (or the result of the last iteration for an unsuccessful call).
infodict: dictA dictionary of optional outputs with the keys:
nfevnumber of function calls
njevnumber of Jacobian calls
fvecfunction evaluated at the output
fjacthe orthogonal matrix, q, produced by the QR factorization of the final approximate Jacobian matrix, stored column wise
rupper triangular matrix produced by QR factorization of the same matrix
qtfthe vector
(transpose(q) * fvec)
ier: intAn integer flag. Set to 1 if a solution was found, otherwise refer to mesg for more information.
mesg: strIf no solution is found, mesg details the cause of failure.
Notes
fsolve is a wrapper around MINPACK's hybrd and hybrj algorithms.
Examples
Find a solution to the system of equations: ``x0*cos(x1) = 4, x1*x0 - x1 = 5``.import numpy as np from scipy.optimize import fsolve def func(x): return [x[0] * np.cos(x[1]) - 4, x[1] * x[0] - x[1] - 5] root = fsolve(func, [1, 1])✓
root
✗np.isclose(func(root), [0.0, 0.0]) # func(root) should be almost 0.0.
✓See also
- root
Interface to root finding algorithms for multivariate functions. See the
method='hybr'in particular.
Aliases
-
scipy.optimize.fsolve