Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void CordanoMethod(int a, int b, int c, int d, out string result) {
- result = "";
- double p = (-(b*b) / (3 * a*a)) + (c / a);
- double q = ((2 * Math.Pow(b, 3)) / (27 * Math.Pow(a, 3))) - ((b * c) / (3 * a*a)) + (d / a);
- double Q = Math.Pow(p/3, 3) + Math.Pow(q/2, 2);
- double A = Math.Pow(((-q / 2) + (Math.Sqrt(Q))), 1.0/3.0);
- double B = Math.Pow(((-q / 2) - (Math.Sqrt(Q))), 1.0/3.0);
- if (Q > 0) {
- double y1 = A + B;
- double x1 = y1 - (b / (3 * a));
- Console.WriteLine(x1); //вещественный корень
- double Re_x2 = -((A + B) / 2) - (b / (3 * a));
- double Im_x2 = (Math.Sqrt(3) * (A - B)) / 2;
- Complex x2 = new Complex(Re_x2, Im_x2);
- Console.WriteLine(x2); //комплексный корень
- double Re_x3 = -((A + B) / 2) - (b / (3 * a));
- double Im_x3 = (Math.Sqrt(3) * (A - B)) / 2;
- Complex x3 = new Complex(Re_x3, -Im_x3);
- Console.WriteLine(x3); //комплексный корень
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement