What's wrong with this function to solve cubic equations?

后端 未结 3 996
死守一世寂寞
死守一世寂寞 2021-01-14 10:56

I am using Python 2 and the fairly simple method given in Wikipedia\'s article \"Cubic function\". This could also be a problem with the cube root function I have to define

3条回答
  •  清酒与你
    2021-01-14 11:29

    Hooked's answer is the way to go if you want to do this numerically. You can also do it symbolically using sympy:

    >>> from sympy import roots
    >>> roots('2*x**3 + 8*x**2 - 8*x - 32')
    {2: 1, -4: 1, -2: 1} 
    

    This gives you the roots and their multiplicity.

提交回复
热议问题