Last active
April 1, 2019 12:34
-
-
Save willhbr/77357dc28ff6ff54d79e to your computer and use it in GitHub Desktop.
Python Matrix Determinant Calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! py | |
def solve(matrix, mul): | |
width = len(matrix) | |
if width == 1: | |
return mul * matrix[0][0] | |
else: | |
sign = -1 | |
total = 0 | |
for i in range(width): | |
m = [] | |
for j in range(1, width): | |
buff = [] | |
for k in range(width): | |
if k != i: | |
buff.append(matrix[j][k]) | |
m.append(buff) | |
sign *= -1 | |
total += mul * solve(m, sign * matrix[0][i]) | |
return total | |
matrix = [[1,-2,3],[0,-3,-4],[0,0,-3]] | |
print(solve(matrix, 1)) |
Could you post the problem description too? What are you trying to accomplish in this code ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I didn´t understand your code, it seems perfect but I wish you can explain it.