Created
December 20, 2012 22:11
-
-
Save askn/4349017 to your computer and use it in GitHub Desktop.
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
import copy | |
def determinant(liste): | |
sonuc = 0 | |
if(len(liste) == 1): | |
return liste[0][0] | |
if(len(liste) == 2): #dogru | |
# 2li matrisin determinanti | |
return (liste[0][0] * liste[1][1]) - (liste[0][1] * liste[1][0]) | |
for sutun in range(len(liste)): | |
# listeyi kopyala | |
gecici = copy.deepcopy(liste) | |
# satiri sil | |
del gecici[0] | |
for i in range(len(gecici)): | |
# secilen elemanin sutunlarini sil | |
del gecici[i][sutun] | |
# kofaktor | |
sonuc += determinant(gecici) * ((-1) ** (0 + sutun)) * liste[0][sutun] | |
return sonuc | |
print determinant([[4, 9],[6, 4]]) | |
print determinant([[5, 3, 7], [2, 4, 9], [3, 6, 4]]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment