Advertisement
maxrusmos

Untitled

Feb 25th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. static void CordanoMethod(int a, int b, int c, int d, out string result) {
  2. result = "";
  3.  
  4. double p = (-(b*b) / (3 * a*a)) + (c / a);
  5. double q = ((2 * Math.Pow(b, 3)) / (27 * Math.Pow(a, 3))) - ((b * c) / (3 * a*a)) + (d / a);
  6.  
  7. double Q = Math.Pow(p/3, 3) + Math.Pow(q/2, 2);
  8. double A = Math.Pow(((-q / 2) + (Math.Sqrt(Q))), 1.0/3.0);
  9. double B = Math.Pow(((-q / 2) - (Math.Sqrt(Q))), 1.0/3.0);
  10.  
  11. if (Q > 0) {
  12. double y1 = A + B;
  13. double x1 = y1 - (b / (3 * a));
  14. Console.WriteLine(x1); //вещественный корень
  15.  
  16. double Re_x2 = -((A + B) / 2) - (b / (3 * a));
  17. double Im_x2 = (Math.Sqrt(3) * (A - B)) / 2;
  18. Complex x2 = new Complex(Re_x2, Im_x2);
  19. Console.WriteLine(x2); //комплексный корень
  20.  
  21. double Re_x3 = -((A + B) / 2) - (b / (3 * a));
  22. double Im_x3 = (Math.Sqrt(3) * (A - B)) / 2;
  23. Complex x3 = new Complex(Re_x3, -Im_x3);
  24. Console.WriteLine(x3); //комплексный корень
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement