Skip to content Skip to sidebar Skip to footer

Fail To Implement Cardano Method. Cube Root Of A Complex Number

In order to improve np.roots performance on cubic equation, I try to implement Cardan(o) Method : def cardan(a,b,c,d): #'resolve P=ax^3+bx^2+cx+d=0' #'x=z-b/a/3=z-z0 =>

Solution 1:

Since the sign of r as one of the square roots is free (resp. the role of u and v is interchangeable in u+v and of u^3,v^3 as roots of a quadratic polynomial) set

u3 = (abs(q+r)>abs(q-r))? -(q+r) : -(q-r)

u = u3**(1/3)
v = -p/(3*u)

This makes sure that the divisor is always as large as possible, reducing the error in the quotient and minimizing the number of cases where division by (near) zero might become an issue.


Post a Comment for "Fail To Implement Cardano Method. Cube Root Of A Complex Number"