Created
August 9, 2017 21:57
-
-
Save AllanRPereira/1aa7e1641010900852b30dda180df447 to your computer and use it in GitHub Desktop.
Python Determinantes
This file contains hidden or 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
""" | |
Nome: Laplace_Det | |
Função: Encontrar o determinante de matrizes utilizando o método de Laplace | |
Autor: Állan Rocha | |
Data: 9/8/2017 | |
""" | |
def laplace_method(smatriz): | |
""" | |
Função que resolve matrizes usando o método de Laplace | |
""" | |
if len(smatriz[0]) == 2: | |
det = smatriz[0][0] * smatriz[1][1] - (smatriz[0][1] * smatriz[1][0]) | |
return det | |
equation = 0 | |
for line in smatriz: | |
signal = ((-1) ** (smatriz.index(line) + 2)) | |
sub_matriz = [] | |
for next_line in smatriz: | |
if next_line != line: | |
sub_matriz.append(next_line[1:]) | |
equation += signal * line[0] * laplace_method(MATRIZ) | |
return equation | |
VALUES = input("Digite o valor das matrizes separadando suas linhas com \",\":").split(",") | |
MATRIZ = [] | |
for value in VALUES: | |
MATRIZ.append([int(k) for k in value.split(" ") if k != ""]) | |
print(laplace_method(VALUES)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment