Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
Use scipy.optimize.root to solve a system of equations, and use root_scalar or brentq to solve one scalar equation. When you can identify an interval whose endpoint function values have opposite signs, brentq is usually the practical first choice: it combines bracketing with faster interpolation steps. Check the solver’s convergence status before treating its estimate as a solution.
Which SciPy root-finding function should you use?
| API | Problem type | What you provide | Best fit |
|---|---|---|---|
scipy.optimize.root |
A vector-valued function of one or more variables | An initial guess for the unknown vector | A system of equations; available methods include hybr, lm, and inexact Newton methods. See the SciPy root reference. |
scipy.optimize.root_scalar |
A scalar function of one variable | A method and its required bracket, initial value(s), and optional derivative information | A single interface for choosing among scalar solvers and checking a structured result. See the SciPy root_scalar reference. |
scipy.optimize.brentq |
A scalar function of one variable | Two bracket endpoints where the continuous function has opposite signs | A direct, bracketed root solver when you have a valid sign change. See the SciPy brentq reference. |
For the broader method overview and qualitative comparisons, see the SciPy optimize reference index. These are different problem shapes, not interchangeable spellings: root addresses a system, while root_scalar and brentq address one unknown.
When is brentq the right choice?
A bracket is an interval [a, b] with f(a) and f(b) of opposite signs. If f is continuous on that interval, a root lies between the endpoints. This is the condition that makes brentq appropriate; an interval alone is not enough if the endpoint values do not change sign or continuity is not satisfied.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →The SciPy optimization tutorial says, “In general, brentq is the best choice, but the other methods may be useful in certain circumstances or for academic purposes.” The method combines bracketing, bisection, and inverse quadratic interpolation, giving a safeguarded alternative to relying on an unbracketed starting guess. The tutorial also describes derivative methods as potentially useful when a good initial value and derivative information are available, including for functions on parts of the complex plane where bracketing cannot be used. See the SciPy optimization tutorial.
#1 Best Overall
Choose another scalar method when the inputs favor it
- No sign-changing bracket: consider Newton, secant, or Halley only when you can provide the appropriate starting value(s) and, for derivative-based methods, the required derivative information.
- First derivative available: Newton’s method uses an initial value and first derivative. It can be fast near a root, but a returned estimate does not by itself establish convergence.
- First and second derivatives available: Halley’s method requires both derivative orders as well as an initial value.
- Two starting values but no bracket: the secant method can use an initial value and a second initial value.
- Prefer a simpler, more conservative bracketed method: bisection is described by SciPy as guaranteed under its bracketing assumptions but slow; other bracketed methods can accelerate accuracy. These are qualitative descriptions, not a performance ranking for your particular function.
SciPy lists scalar options including bisect, brentq, brenth, ridder, toms748, newton, secant, and halley. Compare them by problem type, whether a sign-changing bracket exists, derivative availability, assumptions behind convergence, and the function evaluations or iterations your application can afford.
Use root_scalar with a bracket
root_scalar provides a common interface for scalar solvers. A bracket is a two-value sequence whose endpoint function values have different signs. For a simple example, solve x**3 - 1 = 0 over [0, 3]:
Rank #2
from scipy.optimize import root_scalar
def f(x):
return x**3 - 1
sol = root_scalar(f, bracket=[0, 3], method="brentq")
if not sol.converged:
raise RuntimeError(f"Root finding failed: {sol.flag}")
print(sol.root)
The root is 1.0. The explicit method="brentq" makes the choice clear and repeatable; although SciPy can select a method automatically from the available inputs, it raises an exception if it cannot determine an applicable method.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchMatch arguments to the selected method
- For bracketed methods such as
brentq, provide a valid sign-changing bracket. - For Newton, provide an initial value and first derivative information.
- For Halley, provide first- and second-derivative information.
- For secant, provide an initial value; a second initial value may also be used.
Exact parameter defaults can vary by SciPy release. Check the reference for the version installed in your environment, especially if you rely on defaults rather than explicitly setting the method and tolerances.
Call brentq directly when you only need that solver
brentq is useful when the method is already decided and you want its direct API. The required endpoints a and b must enclose a sign change for a continuous function.
from scipy.optimize import brentq
def f(x):
return x**3 - 1
root = brentq(f, 0, 3)
print(root)
By default, the function returns the root value. Set full_output=True to receive the root together with a RootResults object. With disp=True, failure to converge raises RuntimeError; when you disable that behavior, inspect the returned status rather than assuming that a numeric estimate means success.
Check convergence and understand the tolerance
root_scalar returns a RootResults object with fields including root, converged, and flag. Check converged before using root; use flag to help identify the reported status. When you call brentq with full output, apply the same discipline to its results object.
Recommended Free Tools
For brentq, SciPy defines the root accuracy target by np.isclose(x, x0, atol=xtol, rtol=rtol), where x is the exact root and x0 is the computed root. xtol must be positive, and rtol must not be less than four machine epsilons; the documented default for rtol is approximately 8.88e-16 in the referenced SciPy documentation. A tolerance describes the solver’s numerical error target under its assumptions. It does not say that the function is well-conditioned near the root or that the equation accurately represents the real-world problem.
Best Value
Do not confuse brentq with brent
scipy.optimize.brentq finds a root of a scalar function. scipy.optimize.brent is a scalar minimization method. Their shared name does not mean they solve the same task; SciPy lists them under different optimization tasks in its optimize reference index.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

