コード例 #1
0
ファイル: matrix.py プロジェクト: olpyhn/lin_alg
 def compute_det(self):
     if self.is_det_computed:
         return self.det
     permutations = Permutation.get_permutations(self.n, list(range(self.n)))
     value = 0
     for permutation in permutations:
         x = 1
         for i in range(self.n):
             x *= self.matrix[i][permutation[i]]
         value += Permutation(permutation).get_permutation_sign() * x
     if self.n == 0:
         value = 1
     self.is_det_computed = True
     self.det = value
     return value
コード例 #2
0
from matrix import Matrix, SquareMatrix
from permutation import Permutation

print("Задание 1.")
p1 = Permutation([4, 5, 6, 2, 3, 7, 0, 1])
p2 = Permutation([4, 1, 3, 7, 6, 5, 0, 2])
p3 = Permutation([5, 4, 0, 2, 3, 7, 6, 1])
all_permutations = Permutation.get_permutations(8, list(range(8)))
right = (p1.get_inverse_permutation() * (p2**13))**187
for permutation in all_permutations:
    p = Permutation(permutation)
    if (p * p3 * p).permutation == right.permutation:
        print("Результат:")
        print("(0 1 2 3 4 5 6 7)")
        print("(", " ".join(str(i) for i in p.permutation), ")", sep="")
print("Задание 2.")
a = SquareMatrix([[2, -2, 2, -3], [1, -3, 2, -1], [1, 1, -3, 3],
                  [-2, -3, 3, 2]])
b = SquareMatrix([[-9, 3, 9, -4], [-6, -2, 4, 9], [-9, 6, 10, -3],
                  [6, -10, 9, 6]])
c = SquareMatrix([[2, 2, 3, 1], [2, 1, 1, -2], [2, 1, -1, -1], [-1, 2, -1, 2]])
d = SquareMatrix([[-1, -1, -1, -1], [-1, -2, -2, -2], [-1, -2, -3, -1],
                  [1, 2, 3, 2]])
left = (SquareMatrix.get_e(4).multiply_on_number(
    a.compute_det() * c.compute_det()) -
        (b * c.get_adjugate_matrix() * d * c.get_adjugate_matrix()))
left = left * c * d.get_adjugate_matrix() * a
print("Определителитель матрицы, на которую домножаем = ",
      (c * d.get_adjugate_matrix() * a).compute_det())
print(left.multiply_on_number(1 / 851))
print("Задание 3.")