Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Matrix:
- def __init__(self,numrows,numcolumns):
- #@param numrows : int
- #@param numcolumns : int
- self.row=numrows
- self.col=numcolumns
- self.mat=[]
- for i in range(0,numrows):
- self.mat.append([])
- for j in range(0,numcolumns):
- self.mat[i].append(0)
- def minor(self,j):
- #@ come riga di riferimento si prende i=0
- #@param j : int (colonna da cancellare)
- #@return matrix (minore della matrice ottenuto cancellando riga 0 e colonna j)
- self.mat.remove(self.mat[0])
- for h in range (0,self.col-1):
- self.mat[h].pop(j)
- print_matrix(self.mat)
- return self.mat
- def det(self,D=0):
- #@ (metodo basato su ricorsione, essendo lo sviluppo di Laplace una sommatoria)
- #@ return int : determinante della matrice
- assert self.row==self.col
- if self.row==1:
- return self.mat[0]
- elif self.row==2:
- D=D+((self.mat[0][0]*self.mat[1][1])-(self.mat[0][1]*self.mat[1][0]))
- return D
- else:
- #@sviluppo di Laplace
- for j in range (0,self.row):
- D=D+(pow((-1),(j+2))*self.mat[0][j]*det(self.minor(self,j))) #@Qui mi da errore, non riesco ad impostare la ricorsiva
- return D
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement