Nonlinear systems
Solve coupled nonlinear equations in several unknowns.
SciPy · Function
Finds roots of scalar or vector nonlinear equations from an initial estimate. It can use a supplied Jacobian or estimate one numerically, with optional convergence diagnostics.
fsolve applies MINPACK’s hybrid algorithms to seek a vector x whose function values are zero. It starts from x0, estimates the Jacobian unless fprime is supplied, and can optionally return diagnostic information about convergence.
scipy.optimize.fsolve(func, x0, args=(), fprime=None, full_output=False, col_deriv=False, xtol=1.49012e-08, maxfev=0, band=None, epsfcn=None, factor=100, diag=None)| Name | Type | Description |
|---|---|---|
func | callable | Callable f(x, *args) returning values with the same length as its argument. |
x0 | ndarray | Initial estimate for the roots. |
args | tuple, optional | Extra arguments passed to func and fprime. |
fprime | callable, optional | Jacobian callable; estimated numerically when omitted. |
full_output | bool, optional | Whether to return optional diagnostic outputs. |
col_deriv | bool, optional | Whether fprime computes derivatives down columns. |
xtol | float, optional | Relative-error termination tolerance between consecutive iterates. |
maxfev | int, optional | Maximum function calls; zero selects 100*(N+1). |
band | 2-tuple, optional | Jacobian band widths for banded problems. |
epsfcn | float, optional | Step length for forward-difference Jacobian approximation. |
factor | float, optional | Initial step-bound multiplier; must be in (0.1, 100). |
diag | sequence, optional | Positive variable scale factors. |
x ndarray: the solution, or the result of the last iteration for an unsuccessful call. With full_output=True, optional diagnostic outputs are also returned.
import numpy as np
from scipy.optimize import fsolve
def equations(x):
a, b = x
return [a + b - 3, a - b - 1]
root = fsolve(equations, x0=[1.0, 1.0])
print(root) # [2. 1.]Solves two nonlinear equations simultaneously from an initial estimate.
Solve coupled nonlinear equations in several unknowns.
Find a scalar x where a numerical expression evaluates to zero.
Use an analytic Jacobian to guide a computationally expensive solve.
fsolve finds roots of a vector function by solving func(x)=0 from a supplied starting estimate x0. It is intended for scalar or multidimensional systems whose function returns a value array matching the input length.
Follow-up: How can the Jacobian be provided? Supply fprime; its derivatives are arranged across rows unless col_deriv indicates derivatives down columns.
fprime is optional. Without it, the Jacobian is estimated numerically; with it, the callable computes the Jacobian of func.
Follow-up: When might a user adjust epsfcn? It specifies a suitable step length for the forward-difference Jacobian approximation when fprime is omitted.
With full_output=True, fsolve returns optional diagnostic outputs in addition to x. The primary x result is the solution, or the last iteration if the call is unsuccessful.
Follow-up: What is the default maximum number of function calls? When maxfev is zero, it is 100*(N+1), where N is the number of variables.
scipy.optimize.rootscipy.optimize.leastsqscipy.optimize.minimize