# continuation of my last question i am having problems in calculating roots of a quartic equation in c

I got an algorithm from here that works. It seems simpler than yours.

``````            double D0 = c * c - 3 * b * d + 12 * a * e;
double D1 = 2 * c * c * c - 9 * b * c * d + 27 * b * b * e + 27 * a * d * d - 72 * a * c * e;
double p = (8 * a * c - 3 * b * b) / (8 * a * a);
double q = (b * b * b - 4 * a * b * c + 8 * a * a * d) / (8 * a * a * a);
Complex Q = Complex.Pow((D1 + Complex.Sqrt(D1 * D1 - 4 * D0 * D0 * D0)) / 2, 1.0 / 3.0);
Complex S = Complex.Sqrt(-2 * p / 3 + (Q + D0 / Q) / (3 * a)) / 2;
Complex u = Complex.Sqrt(-4 * S * S - 2 * p + q / S) / 2;
Complex v = Complex.Sqrt(-4 * S * S - 2 * p - q / S) / 2;
Complex x1 = -b / (4 * a) - S + u;
Complex x2 = -b / (4 * a) - S - u;
Complex x3 = -b / (4 * a) + S + v;
Complex x4 = -b / (4 * a) + S - v;
``````

Also, according to this page, you can use this instead of the very long discriminant formula just to get its sign:

``````            double discriminantSign = c * c - 3 * b * d + 12 * a * e;
``````

I also noticed 4 typos, you forgot to mention the 5 decimal when you apply the Math.Round function, so your results are rounded to an integer.

EDIT: If you still have issues in you imaginary part, it’s because you didn’t correct the typos:

``````     Console.WriteLine(x1rp + " - " + Math.Round(Complex.Abs(x1.Imaginary)) + "i");
``````

Into:

``````     Console.WriteLine(x1rp + " - " + Math.Round(Complex.Abs(x1.Imaginary), 5) + "i");
``````

You take 5 decimals everywhere except in 4 lines as above. So it’s rounding the integer. Replace them all.