Cardano's solution of the cubic equation

Hi,
The problem is not (completely) the fortran code, it is the exercise !!
Take the following parameters: a1=a2=0 and a3=8.
The three solutions are the three cubic roots of -8 so proportional to 2.

With those, parameters:
Q=0, R=a3/2=4 and Q3-R2<0
Then s=-(4+4)=-8

With the exercise expression, the first root, x1=s+Q/s-a1/3=s=-8

Obviously, x1 is not the root of the polynomial.

=> I’m guessing, instead of s you have to use s**(1/3)
and correct sign(R,R) in sign(1,R) (as mentioned)

And now, with your parameters:
Real root is: -1.27568233 Complex roots are: (0.137859225,-1.52726758) (0.137781680,1.52726758)

4 Likes