[SciPy-user] how to resolve a cubic equation in scipy?
Wed May 21 18:17:47 CDT 2008
On Wed, May 21, 2008 at 6:02 PM, Johann Cohen-Tanugi
> just for fun I compared the 3 methods with timeit I got :
> [cohen@jarrett ~]$ ipython testSolveCubic.py
> using fsolve:
> 2.44568693982 1.84741111298e-12
> time= 0.000438928604126
> using roots:
> [-1.22284347+2.30637633j -1.22284347-2.30637633j 2.44568694+0.j ]
> time= 0.002277135849
> using brentq
> time= 3.31401824951e-05
> So brentq is indeed by far the fastest. I am slightly surprised that
> fsolve outperforms roots, but I guess it could be due to the fact that
> the problem is too simple...
Quite possibly. It's also worth noting that roots() actually gives you
all three roots even if they are complex where the others can only
give you one (real) root.
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the SciPy-user