Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import sqrt
- def frange(start, end=None, inc=None):
- if end == None:
- end = start + 0.0
- start = 0.0
- if inc == None:
- inc = 1.0
- L = []
- while 1:
- next = start + len(L) * inc
- if inc > 0 and next >= end:
- break
- elif inc < 0 and next <= end:
- break
- L.append(next)
- return L
- def uravnenie(a, b, c):
- a = float(a)
- b = float(b)
- c = float(c)
- discriminant = b ** 2 - 4 * a * c
- if discriminant < 0:
- print('Корней нет')
- return float(-2000)
- elif discriminant == 0:
- x = -b / (2 * a)
- return x
- else:
- x1 = (-b + discriminant ** 0.5) / (2 * a)
- x2 = (-b - discriminant ** 0.5) / (2 * a)
- return x1, x2
- maximum = -20000
- for y in frange(-3.00000, 3.00001, 0.00001):
- arr_of_x = list(uravnenie(1, sqrt(3)*y, (y ** 2 - 25)))
- if len(arr_of_x) == 1:
- arr_of_z = uravnenie(1, arr_of_x[0], (arr_of_x[0] ** 2 - 16))
- number = arr_of_x[0] * y + 2 * y * arr_of_z + sqrt(3) * arr_of_z * arr_of_x[0]
- if number > maximum:
- maximum = number
- if len(arr_of_x) == 2:
- arr_of_z = [uravnenie(1, arr_of_x[0], (arr_of_x[0] ** 2 - 16)),
- uravnenie(1, arr_of_x[1], (arr_of_x[1] ** 2 - 16))]
- if len(arr_of_z) == 0:
- continue
- if len(arr_of_z) == 2:
- number1 = arr_of_x[0] * y + 2 * y * arr_of_z[0] + sqrt(3) * arr_of_z[0] * arr_of_x[0]
- number2 = arr_of_x[1] * y + 2 * y * arr_of_z[0] + sqrt(3) * arr_of_z[0] * arr_of_x[1]
- number3 = arr_of_x[0] * y + 2 * y * arr_of_z[1] + sqrt(3) * arr_of_z[1] * arr_of_x[0]
- number4 = arr_of_x[1] * y + 2 * y * arr_of_z[1] + sqrt(3) * arr_of_z[1] * arr_of_x[1]
- if max(number1, number2, number3, number4) > maximum:
- maximum = max(number1, number2, number3, number4)
- if len(arr_of_z) == 4:
- number1 = arr_of_x[0] * y + 2 * y * arr_of_z[0] + sqrt(3) * arr_of_z[0] * arr_of_x[0]
- number2 = arr_of_x[0] * y + 2 * y * arr_of_z[1] + sqrt(3) * arr_of_z[0] * arr_of_x[1]
- number3 = arr_of_x[0] * y + 2 * y * arr_of_z[2] + sqrt(3) * arr_of_z[0] * arr_of_x[2]
- number4 = arr_of_x[0] * y + 2 * y * arr_of_z[3] + sqrt(3) * arr_of_z[0] * arr_of_x[3]
- number5 = arr_of_x[1] * y + 2 * y * arr_of_z[0] + sqrt(3) * arr_of_z[1] * arr_of_x[0]
- number6 = arr_of_x[1] * y + 2 * y * arr_of_z[1] + sqrt(3) * arr_of_z[1] * arr_of_x[1]
- number7 = arr_of_x[1] * y + 2 * y * arr_of_z[2] + sqrt(3) * arr_of_z[1] * arr_of_x[2]
- number8 = arr_of_x[1] * y + 2 * y * arr_of_z[3] + sqrt(3) * arr_of_z[1] * arr_of_x[3]
- if max(number1, number2, number3, number4, number5, number6, number7, number8) > maximum:
- maximum = max(number1, number2, number3, number4, number5, number6, number7, number8)
- print(maximum)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement