Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

SciPy · Function

optimize.fsolve

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.

How it works

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.

Syntax

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)

Parameters

NameTypeDescription
funccallableCallable f(x, *args) returning values with the same length as its argument.
x0ndarrayInitial estimate for the roots.
argstuple, optionalExtra arguments passed to func and fprime.
fprimecallable, optionalJacobian callable; estimated numerically when omitted.
full_outputbool, optionalWhether to return optional diagnostic outputs.
col_derivbool, optionalWhether fprime computes derivatives down columns.
xtolfloat, optionalRelative-error termination tolerance between consecutive iterates.
maxfevint, optionalMaximum function calls; zero selects 100*(N+1).
band2-tuple, optionalJacobian band widths for banded problems.
epsfcnfloat, optionalStep length for forward-difference Jacobian approximation.
factorfloat, optionalInitial step-bound multiplier; must be in (0.1, 100).
diagsequence, optionalPositive variable scale factors.

Returns

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.

Key points

  • Use fsolve to locate zeros of a scalar or vector-valued function.
  • For systems, func must return as many values as x has elements.
  • Define func so its output length matches the input vector and accept any extra args passed through args.
  • Choose x0 as the initial guess; convergence can depend strongly on this estimate.
  • Set full_output=True when convergence diagnostics or intermediate information are needed.
  • Provide fprime to avoid numerical Jacobian estimation when an analytic Jacobian is available.

Common mistakes

  • The returned array can be only the final iterate when the solver does not converge; inspect the diagnostic output when using full_output=True.
  • If no fprime is supplied, SciPy approximates the Jacobian numerically, which can add function evaluations and sensitivity to finite-difference settings.
  • factor must remain between 0.1 and 100 because it controls the initial step bound.

Example: Solve a system of equations

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.

When to use it

Nonlinear systems

Solve coupled nonlinear equations in several unknowns.

Scalar root finding

Find a scalar x where a numerical expression evaluates to zero.

Jacobian-aware solving

Use an analytic Jacobian to guide a computationally expensive solve.

Interview questions

QWhat problem does fsolve 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.

QWhat is the role of fprime?

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.

QHow should convergence be assessed?

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.root
  • scipy.optimize.leastsq
  • scipy.optimize.minimize

Source: fsolve. Checked 2026-10-15.