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

SciPy · Function

optimize.newton

Finds a zero of a real or complex scalar function with Newton-Raphson, secant, or Halley iteration. The selected method depends on whether first- and second-derivative callables are supplied.

How it works

newton iteratively seeks a zero of a scalar-valued function. Providing its first derivative selects Newton-Raphson, omitting it selects the secant method, and providing both first- and second-derivative functions selects Halley’s method. A scalar starting value returns one root; multiple starting values are processed elementwise.

Syntax

scipy.optimize.newton(func, x0, fprime=None, args=(), tol=1.48e-08, maxiter=50, fprime2=None, x1=None, rtol=0.0, full_output=False, disp=True)

Parameters

NameTypeDescription
funccallableThe function whose root is sought.
x0float, complex, or array_likeAn initial estimate of the root. If x0 is a sequence, the method is applied to each element.
fprimecallable, optionalThe first derivative of func. If provided, Newton-Raphson is used.
argstuple, optionalExtra positional arguments passed to func, fprime, and fprime2.
tolfloat, optionalAbsolute tolerance for the root; the algorithm stops when the step meets the documented tolerance test.
maxiterint, optionalMaximum number of iterations.
fprime2callable, optionalThe second derivative of func. If provided together with fprime, Halley’s method is used.
x1float or array_like, optionalA second starting point for the secant method when fprime is not supplied.
rtolfloat, optionalRelative tolerance for the root.
full_outputbool, optionalIf True, return additional convergence information.
dispbool, optionalIf True, raise RuntimeError when the algorithm fails to converge.

Returns

A scalar root for scalar x0, or an array of roots for multiple starting values. With full_output=True and scalar x0, returns the root plus a RootResults object; with array-like x0, returns the roots, a convergence mask, and a zero-derivative mask.

Key points

  • Use newton to find a zero of either a real- or complex-valued function.
  • The presence of fprime determines whether iteration uses Newton-Raphson or the derivative-free secant method.
  • Providing the second derivative in addition to fprime switches the iteration to Halley’s method.
  • A sequence of initial guesses requests independent root estimates and returns them in an array.

Example: Solve a scalar equation

import numpy as np
from scipy.optimize import newton

root = newton(lambda x: np.cos(x) - x, 0.5)
print(root)

Finds the fixed point of cosine starting near 0.5.

When to use it

Scalar root finding

Solving a scalar nonlinear equation when an approximate root is available.

Batch initial guesses

Solving several independent scalar equations using a collection of starting estimates.

Derivative-assisted iteration

Accelerating local convergence when analytic first and second derivatives are available.

Interview questions

QWhich algorithm does newton use under different derivative arguments?

The function solves f(x)=0 from a nearby starting value. Supplying fprime uses Newton-Raphson, omitting it uses the secant method, and supplying fprime2 as well uses Halley’s method.

Follow-up: What changes for multiple initial values? A sequence x0 produces an array of roots, with convergence and zero-derivative information returned when full_output is enabled.

QHow are extra parameters passed to func?

func must accept the current scalar x as its first argument. Extra fixed arguments are passed after x through args, so a function can be written as f(x, a, b).

Follow-up: How can derivative functions receive those values? Pass the same args tuple; SciPy calls fprime and fprime2 with x followed by those extra arguments.

QWhat controls termination?

tol controls the absolute tolerance for the iterate change, while rtol controls the relative tolerance. maxiter limits the number of iterations, and the default maximum is 50.

Follow-up: Why should users validate convergence? The documentation notes that the stopping test is based on step size and does not guarantee that the returned value is a root.

  • scipy.optimize.root_scalar
  • scipy.optimize.brentq
  • scipy.optimize.fixed_point
  • scipy.optimize.newton_krylov

Source: Newton. Checked 2026-10-15.