Advertisement
AllanRocha

Matrizes_Laplace

May 29th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. """
  2. Nome: Laplace_Det
  3. Função: Encontrar o determinante de matrizes utilizando o método de Laplace
  4. Autor: Állan Rocha
  5. Data: 9/8/2017
  6. """
  7.  
  8. def laplace_method(smatriz):
  9.     """
  10.    Função que resolve matrizes usando o método de Laplace
  11.    """
  12.  
  13.     if len(smatriz[0]) == 2:
  14.         det = smatriz[0][0] * smatriz[1][1] - (smatriz[0][1] * smatriz[1][0])
  15.         return det
  16.  
  17.     equation = 0
  18.     for line in smatriz:
  19.         signal = ((-1) ** (smatriz.index(line) + 2))
  20.         sub_matriz = []
  21.         for next_line in smatriz:
  22.             if next_line != line:
  23.                 sub_matriz.append(next_line[1:])
  24.         equation += signal * line[0] * laplace_method(MATRIZ)
  25.     return equation
  26.  
  27. VALUES = input("Digite o valor das matrizes separadando suas linhas com \",\":").split(",")
  28. MATRIZ = []
  29.  
  30. for value in VALUES:
  31.     MATRIZ.append([int(k) for k in value.split(" ") if k != ""])
  32.  
  33. print(laplace_method(VALUES))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement