Skip to content

Commit

Permalink
Update lab0
Browse files Browse the repository at this point in the history
  • Loading branch information
857l authored Feb 3, 2025
1 parent 304807f commit e3b2ae3
Showing 1 changed file with 18 additions and 35 deletions.
53 changes: 18 additions & 35 deletions lab0/basic_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,27 @@ def functions(a_1, a_2):
Необходимо найти точки экстремума функции и определить, есть ли у функций общие решения.
Вернуть нужно координаты найденных решения списком, если они есть. None, если их бесконечно много.
"""
index1 = [int(a) for a in a_1.split()]
index2 = [int(a) for a in a_2.split()]

if index1 == index2:
if a_1 == a_2:
return None
a1, b1, c1 = map(int, a_1.split())
a2, b2, c2 = map(int, a_2.split())
a3, b3, c3 = (a1 - a2), (b1 - b2), (c1 - c2)

def F(x, index=index1):
return index[0] * x ** 2 + index[1] * x + index[2]

def P(x, index=index2):
return index[0] * x ** 2 + index[1] * x + index[2]
# минимум фукнций
resF = sc.optimize.minimize_scalar(F)
minimum_F = resF.fun
minimizer_F = resF.x
resP = sc.optimize.minimize_scalar(P)
minimum_P = resP.fun
minimizer_P = resP.x

a = index1[0] - index2[0]
b = index1[1] - index2[1]
c = index1[2] - index2[2]
if a == 0 and b != 0:
root = -c/b
return [(root, F(root))]
elif a == 0:
return []
else:
D = b ** 2 - 4 * a * c

if D < 0:
if a3 == 0:
if b3 == 0:
return []

root1 = (-b + (D**0.5))/(2*a)
root2 = (-b - (D**0.5))/(2*a)
if D == 0:
return [(root1, F(root1))]
return [(root1, F(root1)), (root2, F(root2))]
x = -c3 / b3
return [(x, a3 * x ** 2 + b3 * x + c3)]
dis = b3 ** 2 - 4 * a3 * c3
if dis < 0:
return None
elif dis == 0:
x = -(b3 / (2 * a3))
return [int(x), int(a3 * x ** 2 + b3 * x + c3)]
sqrt_dis = int(math.sqrt(dis))
x_plus = int((-b3 + sqrt_dis) / (2 * a3))
x_minus = int((-b3 - sqrt_dis) / (2 * a3))
return [(x_plus, int(a1 * x_plus ** 2 + b1 * x_plus + c1)), (x_minus, int(a2 * x_minus ** 2 + b2 * x_minus + c2))]


def skew(x):
Expand Down

0 comments on commit e3b2ae3

Please sign in to comment.