Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def det(a):
- result = 0.0
- result += a[0][0] * (a[1][1] * a[2][2] - a[2][1] * a[1][2])
- result -= a[0][1] * (a[1][0] * a[2][2] - a[2][0] * a[1][2])
- result += a[0][2] * (a[1][0] * a[2][1] - a[2][0] * a[1][1])
- return result
- def transponse(A):
- res = [[A[j][i] for j in range(3)] for i in range(3)]
- return res
- def read_matrix():
- return [list(map(float, input().split())) for _ in range(3)]
- def Solve(a):
- arr = [[[1 if j == index else a[i][j] for j in range(3)] for i in range(3)] for index in range(-1, 3)]
- det_a = det(arr[0])
- det_a1 = det(arr[1])
- det_a2 = det(arr[2])
- det_a3 = det(arr[3])
- det_a123 = det_a1 + det_a2 + det_a3
- game_cost = det_a / det_a123
- x1 = det_a1 / det_a123
- x2 = det_a2 / det_a123
- x3 = det_a3 / det_a123
- return det_a, det_a1, det_a2, det_a3, game_cost, x1, x2, x3
- matrix = read_matrix()
- c, c1, c2, c3, cost, x1, x2, x3 = Solve(matrix)
- print('Cost %.3f' % cost)
- print('C %.3f, C1 %.3f, C2 %.3f, C3 %.3f' % (c, c1, c2, c3))
- print('x1 %.3f, x2 %.3f, x3 %.3f' % (x1, x2, x3))
- c, c1, c2, c3, cost, x1, x2, x3 = Solve(transponse(matrix))
- print('C~ %.3f, C~1 %.3f, C~2 %.3f, C~3 %.3f' % (c, c1, c2, c3))
- print('y1 %.3f, y2 %.3f, y3 %.3f' % (x1, x2, x3))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement