Advertisement
Guest User

Untitled

a guest
Feb 13th, 2022
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. import math
  2.  
  3. print("Ввод абсц:")
  4. a=float(input("a="))
  5. b=float(input("b="))
  6. c=float(input("c="))
  7. d=float(input("d="))
  8. print(Cardano(a,b,c,d))
  9.  
  10.  
  11. def Cardano(a, b, c, d):
  12. if a == 0:
  13. return 0
  14. res = []
  15. p = (3 * a * c - b * b) / 3 * a ** 2
  16. q = (2 * math.pow(b, 3) - 9 * a * b * c + 27 * a * a * d) / 27 * math.pow(a, 3)
  17. D = (q / 2) ** 2 + (p / 3) ** 3
  18.  
  19. if D < 0:
  20. if q < 0:
  21. fi = math.arctg(math.sqrt(-D))
  22. elif q > 0:
  23. fi = math.arctg(math.sqrt(-D)) + math.pi
  24. else:
  25. fi = math.pi / 2
  26. y1 = 2 * math.sqrt(-p / 3) * math.cos(fi / 3)
  27. y2 = 2 * math.sqrt(-p / 3) * math.cos(fi / 3 + 2 * math.pi / 3)
  28. y3 = 2 * math.sqrt(-p / 3) * math.cos(fi / 3 + 4 * math.pi / 3)
  29. res.append(y1 - b / 3 * a)
  30. res.append(y2 - b / 3 * a)
  31. res.append(y3 - b / 3 * a)
  32.  
  33. return res
  34.  
  35.  
  36. print(Cardano(1, 6, 3, -10))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement