Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- print("Ввод абсц:")
- a=float(input("a="))
- b=float(input("b="))
- c=float(input("c="))
- d=float(input("d="))
- print(Cardano(a,b,c,d))
- def Cardano(a, b, c, d):
- if a == 0:
- return 0
- res = []
- p = (3 * a * c - b * b) / 3 * a ** 2
- q = (2 * math.pow(b, 3) - 9 * a * b * c + 27 * a * a * d) / 27 * math.pow(a, 3)
- D = (q / 2) ** 2 + (p / 3) ** 3
- if D < 0:
- if q < 0:
- fi = math.arctg(math.sqrt(-D))
- elif q > 0:
- fi = math.arctg(math.sqrt(-D)) + math.pi
- else:
- fi = math.pi / 2
- y1 = 2 * math.sqrt(-p / 3) * math.cos(fi / 3)
- y2 = 2 * math.sqrt(-p / 3) * math.cos(fi / 3 + 2 * math.pi / 3)
- y3 = 2 * math.sqrt(-p / 3) * math.cos(fi / 3 + 4 * math.pi / 3)
- res.append(y1 - b / 3 * a)
- res.append(y2 - b / 3 * a)
- res.append(y3 - b / 3 * a)
- return res
- print(Cardano(1, 6, 3, -10))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement