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

SciPy · Function

optimize.root

Find a zero of a vector-valued function from an initial guess. The function supports multiple solver methods, optional Jacobians, callbacks, and solver-specific options.

Since
0.11.0

How it works

Call root with a callable residual function and an initial guess. SciPy selects the requested solver, optionally obtains or estimates the Jacobian, and returns an OptimizeResult containing the candidate root and termination information.

Syntax

scipy.optimize.root(fun, x0, args=(), method='hybr', jac=None, tol=None, callback=None, options=None)

Parameters

NameTypeDescription
funcallableA vector function whose zero is sought.
x0ndarrayInitial guess for the unknown vector.
argstuple, optionalExtra positional arguments passed to fun and its Jacobian.
methodstr, optionalSolver type; the default is hybr.
jaccallable or bool, optionalBoolean or callable Jacobian specification.
tolfloat, optionalTermination tolerance.
callbackfunction, optionalOptional iteration callback.
optionsdict, optionalSolver-specific options, such as xtol or maxiter.

Returns

sol : OptimizeResult — the solution represented as an OptimizeResult object, including attributes such as x, success, and message.

Key points

  • Use root for systems of equations whose residual vector should be driven to zero.
  • The starting point is supplied through x0, typically as an array matching the unknown vector.
  • Use args to forward shared positional data to the residual function and Jacobian.
  • If method is omitted, SciPy uses hybr as the solver.
  • A callable jacobian may be supplied when an analytical derivative is available.
  • The options mapping provides solver-specific configuration, including controls such as xtol or maxiter.
  • The result is an OptimizeResult containing structured solver output rather than a bare array.
  • Inspect x for the candidate solution and success for whether the algorithm reported successful termination.

Common mistakes

  • With jac=False, SciPy estimates the Jacobian numerically; supplying a callable Jacobian can avoid that approximation.
  • For supported callback-based methods, the callback receives the current point and residual on each iteration; the hybr and lm methods do not accept callbacks.
  • Use options for method-specific controls such as iteration limits or tolerances rather than relying only on the global tol argument.

Example: Solve a scalar equation as a one-element system

import numpy as np
from scipy.optimize import root

def residual(x):
    return np.array([x[0]**2 - 2.0])

sol = root(residual, x0=np.array([1.0]))
print(sol.x[0], sol.success)

Defines a vector residual function, starts from an initial guess, and reads the solution and success flag from the returned OptimizeResult.

When to use it

Nonlinear systems

Solving several nonlinear equations simultaneously

Jacobian-assisted solving

Using analytical derivatives to improve solver behavior

Iteration callbacks

Monitoring iterative progress with supported methods

Interview questions

QWhat problem does scipy.optimize.root solve, and what does it return?

root solves a vector equation by seeking an x for which fun(x) is zero. It accepts an initial guess x0 and returns an OptimizeResult rather than only the numerical root.

Follow-up: How would you provide extra data? Pass it through args; those values are forwarded to fun and, when applicable, its Jacobian.

QWhat is the default solver method, and why might method selection matter?

The default method is hybr. Other documented choices include lm, the inexact-Newton family, and Krylov-based methods; the selected method determines the algorithm and available options.

Follow-up: Why might method selection matter? Solver-specific methods have different convergence behavior and option sets, so the problem structure should guide the choice.

QHow does root handle the Jacobian?

jac may be a Boolean or a callable. If it is False, the Jacobian is estimated numerically; if it is callable, it must accept the same arguments as fun and return its Jacobian.

Follow-up: What should you inspect after solving? Check success and message, then use x and evaluate the residual when solution quality matters.

  • scipy.optimize.OptimizeResult
  • scipy.optimize.show_options
  • scipy.optimize.root_scalar
  • scipy.optimize.fsolve

Source: root. Checked 2026-10-15.