Problems finding a numerical root

48 views
Skip to first unread message

Philipp Janert

unread,
Mar 19, 2026, 11:49:54 AM (5 days ago) Mar 19
to sy...@googlegroups.com
Consider the following SymPy session:

>>> from sympy import *
>>> x = Symbol( "x", Real=True )
>>> f = 5*x**(2/3)/243 + x**(-2) - 3/x**4 + 15/x**6 - 1/(9*x**(2/3)) - 1/(3*x**(4/3))
>>> nsolve( f, x, (1,3) )
3.08052599290539 - 0.62790375155299*I

The problem is that f has a real root, very near x=2.09,
as plotting f(x) will reveal immediately. 

If I give tighter bounds, such as: nsolve( f, x, (2,2.2) ),
nsolve fails to converge entirely, "Could not find a root".

True, f(x) blows up as x -> 0, but that's well outside
the specified bounds. 

I understand that SymPy is not a numerical library, 
but this problem seems sufficiently straightforward. 

Is this expected behavior, or a bug, or a user error 
(which is the most probable case)?

Best, 

  Ph.

Davide Sandona'

unread,
Mar 20, 2026, 6:11:21 AM (4 days ago) Mar 20
to sy...@googlegroups.com
Hello Philipp, are you sure you have written down the correct expression? This is what it looks like upon closer inspection:

plot(f, (x, 0, 5), ylim=(-0.1, 1), title="$%s$" % latex(f))

image.png

There is no real root! However, nsolve was able to find one of the complex roots. You can see which one from the domain coloring plot below:

plot_complex(f, (x, -2-3j, 4+3j), coloring="b", grid=False, n=500, cmap=colorcet.colorwheel, title="$%s$" % latex(f))

image.png
Charts are generated with SymPy Plotting Backends: https://sympy-plot-backends.readthedocs.io/en/latest/index.html

Davide.


--
You received this message because you are subscribed to the Google Groups "sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sympy+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/sympy/CAAQAZOsq5A_AAKe8k7X802D4GW4ZZwPmVB8noGyc2HXd5xDDyQ%40mail.gmail.com.

Philipp Janert

unread,
Mar 20, 2026, 8:40:47 AM (4 days ago) Mar 20
to sympy
You are right; I must have made a mistake when transcribing the formula.
I need to look into that.

Sorry about the spam. ;-(
Reply all
Reply to author
Forward
0 new messages