Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lab0 PYАД 1.1 Абдрахманов М.М. #5

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 56 additions & 4 deletions lab0/basic_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@ def matrix_multiplication(matrix_a, matrix_b):
Вернуть нужно матрицу в формате списка.
"""
# put your code here
pass

new_matrix = [[0 for _ in range(len(matrix_b[0]))] for _ in range(len(matrix_a))]
if len(matrix_a[0]) != len(matrix_b):
raise ValueError()
for i in range(len(matrix_a)):
for j in range(len(matrix_a[0])):
for k in range(len(matrix_b[0])):
new_matrix[i][k] += matrix_a[i][j] * matrix_b[j][k]
return new_matrix


def functions(a_1, a_2):
Expand All @@ -18,7 +26,43 @@ def functions(a_1, a_2):
Вернуть нужно координаты найденных решения списком, если они есть. None, если их бесконечно много.
"""
# put your code here
pass
eq1 = [int(x) for x in a_1.split()]
eq2 = [int(x) for x in a_2.split()]

if eq1 == eq2:
return

def f(x):
return eq1[0]*x**2 + eq1[1]*x + eq1[2]


#min_result1 = fmin(lambda x: eq1[0]*x**2 + eq1[1]*x + eq1[2], [0]) #точка экстремума первой функции
#min_result2 = fmin(lambda x: eq2[0]*x**2 + eq2[1]*x + eq2[2], [0]) #точка экстремума второй функции

#func = (eq1[0]-eq2[0])*x**2 + (eq1[1]-eq2[1])*x + (eq1[2]-eq2[2])

a = (eq1[0]-eq2[0])
b = (eq1[1]-eq2[1])
c = (eq1[2]-eq2[2])

if a != 0:
D = b**2 - 4*a*c
if D < 0:
return []
else:
root1 = (-b + D**0.5)/(2*a)
root2 = (-b - D**0.5)/(2*a)
if root2 == root1:
return [(root1, f(root1))]
else:
return [(root1, f(root1)), ((root2, f(root2)))]
elif a == 0 and b != 0:
root1 = -c/b
return [(root1, f(root1))]
else:
return []




def skew(x):
Expand All @@ -27,7 +71,11 @@ def skew(x):
Необходимо вернуть значение коэффициента асимметрии, округленное до 2 знаков после запятой.
"""
# put your code here
pass
x_e = sum(x)/len(x)
sigma = (sum([(num - x_e)**2 for num in x])/len(x))**0.5
m_3 = sum([(num - x_e)**3 for num in x])/len(x)
A_3 = m_3/(sigma**3)
return round(A_3, 2)


def kurtosis(x):
Expand All @@ -36,4 +84,8 @@ def kurtosis(x):
Необходимо вернуть значение коэффициента эксцесса, округленное до 2 знаков после запятой.
"""
# put your code here
pass
x_e = sum(x)/len(x)
sigma = (sum([(num - x_e)**2 for num in x])/len(x))**0.5
m_4 = sum([(num - x_e)**4 for num in x])/len(x)
E_4 = m_4/(sigma**4) - 3
return round(E_4,2)
Loading