Skip to content

Commit 4fec6ce

Browse files
committed
fix: use adjoint matrix for 3x3 inverse
1 parent e3b01ec commit 4fec6ce

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

matrix/inverse_of_matrix.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def inverse_of_matrix(matrix: list[list[float]]) -> list[list[float]]:
3131
3232
Doctests for 3x3
3333
>>> inverse_of_matrix([[2, 5, 7], [2, 0, 1], [1, 2, 3]])
34-
[[2.0, 5.0, -4.0], [1.0, 1.0, -1.0], [-5.0, -12.0, 10.0]]
34+
[[2.0, 1.0, -5.0], [5.0, 1.0, -12.0], [-4.0, -1.0, 10.0]]
3535
>>> inverse_of_matrix([[1, 2, 2], [1, 2, 2], [3, 2, -1]])
3636
Traceback (most recent call last):
3737
...
@@ -145,7 +145,7 @@ def inverse_of_matrix(matrix: list[list[float]]) -> list[list[float]]:
145145
adjoint_matrix[i][j] = cofactor_matrix[j][i]
146146

147147
# Inverse of the matrix using the formula (1/determinant) * adjoint matrix
148-
inverse_matrix = array(cofactor_matrix)
148+
inverse_matrix = array(adjoint_matrix)
149149
for i in range(3):
150150
for j in range(3):
151151
inverse_matrix[i][j] /= d(determinant)

0 commit comments

Comments
 (0)