Advertisement
TornioSubito

Untitled

Jun 29th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. class Matrix:
  2. def __init__(self,numrows,numcolumns):
  3. #@param numrows : int
  4. #@param numcolumns : int
  5. self.row=numrows
  6. self.col=numcolumns
  7. self.mat=[]
  8. for i in range(0,numrows):
  9. self.mat.append([])
  10. for j in range(0,numcolumns):
  11. self.mat[i].append(0)
  12.  
  13. def minor(self,j):
  14. #@ come riga di riferimento si prende i=0
  15. #@param j : int (colonna da cancellare)
  16. #@return matrix (minore ottenuto cancellando riga 0 e colonna j)
  17. if self.row > 2 :
  18. self.mat.remove(self.mat[0])
  19. for h in range (0,self.col-1):
  20. self.mat[h].pop(j)
  21. self.row=self.row-1
  22. self.col=self.col-1
  23. return self
  24.  
  25.  
  26. def det(self,D=0): #@NOT WORKING
  27. #@ return int : determinante della matrice
  28. assert self.row==self.col
  29. if self.row==1:
  30. return self.mat[0]
  31. elif self.row==2:
  32. D=D+((self.mat[0][0]*self.mat[1][1])-(self.mat[0][1]*self.mat[1][0]))
  33. return D
  34. else:
  35. #@sviluppo di Laplace
  36. for j in range (0,self.row):
  37. D=D+(pow((-1.0),(j+2.0))*float(self.mat[0][j])*float(self.minor(j).det()))
  38. return D
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement