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

后端 未结 3 1008
死守一世寂寞
死守一世寂寞 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:22

    You are using integer values - which are not automatically converted to floats by Python. The more generic solution will be to write coefficients in the function as float numbers - 18.0 instead of 18, etc. That will do the trick An illustration - from the code:

    >>> 2**(1/3)
    1
    >>> 2**(1/3.)
    1.2599210498948732
    >>> 
    

提交回复
热议问题