- scipy.optimize.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)#
Find the roots of a function.
Return the roots of the (non-linear) equations defined by
func(x) = 0given a starting estimate.
A function that takes at least one (possibly vector) argument, and returns a value of the same length.
The starting estimate for the roots of
func(x) = 0.
- argstuple, optional
Any extra arguments to func.
f(x, *args), optional
A function to compute the Jacobian of func with derivatives across the rows. By default, the Jacobian will be estimated.
- full_outputbool, optional
If True, return optional outputs.
- col_derivbool, optional
Specify whether the Jacobian function computes derivatives down the columns (faster, because there is no transpose operation).
- xtolfloat, optional
The calculation will terminate if the relative error between two consecutive iterates is at most xtol.
- maxfevint, optional
The maximum number of calls to the function. If zero, then
100*(N+1)is the maximum where N is the number of elements in x0.
- bandtuple, optional
If 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
- epsfcnfloat, optional
A suitable step length for the forward-difference approximation of the Jacobian (for
fprime=None). If epsfcn is less than the machine precision, it is assumed that the relative errors in the functions are of the order of the machine precision.
- factorfloat, optional
A parameter determining the initial step bound (
factor * || diag * x||). Should be in the interval
- diagsequence, optional
N positive entries that serve as a scale factors for the variables.
The solution (or the result of the last iteration for an unsuccessful call).
A dictionary of optional outputs with the keys:
number of function calls
number of Jacobian calls
function evaluated at the output
the orthogonal matrix, q, produced by the QR factorization of the final approximate Jacobian matrix, stored column wise
upper triangular matrix produced by QR factorization of the same matrix
(transpose(q) * fvec)
An integer flag. Set to 1 if a solution was found, otherwise refer to mesg for more information.
If no solution is found, mesg details the cause of failure.
Interface to root finding algorithms for multivariate functions. See the
fsolveis a wrapper around MINPACK’s hybrd and hybrj algorithms.
Find a solution to the system of equations:
x0*cos(x1) = 4, x1*x0 - x1 = 5.
>>> from scipy.optimize import fsolve >>> def func(x): ... return [x * np.cos(x) - 4, ... x * x - x - 5] >>> root = fsolve(func, [1, 1]) >>> root array([6.50409711, 0.90841421]) >>> np.isclose(func(root), [0.0, 0.0]) # func(root) should be almost 0.0. array([ True, True])