Skip to content
scipython.com

Q8.4.1Equation solving with scipy.optimize.brentq

Use scipy.optimize.brentq to find the solutions to the equation

\[x + 1 = -\frac{1}{(x-3)^3}\]
Show solution

Rewrite the equation as

\[f(x) = x + 1 + (x-3)^{-3} = 0.\]

This function is readily plotted and the roots may be bracketed in \((-2, -0.5)\) and \((0, 2.99)\) (avoiding the singularity at \(x=3\)).

In [x]: f = lambda x: x + 1 + (x-3)**-3
In [x]: brentq(f, -2, -0.5), brentq(f, 0, 2.99)
Out[x]: (-0.984188231211512, 2.3303684533047426)