mirror of
https://github.com/Sosokker/Calculator-for-Matrix-and-Algebra.git
synced 2025-12-19 21:24:05 +01:00
Implement Complete Determiant calculate func
This commit is contained in:
parent
25e7a3d098
commit
80eb514d30
@ -76,6 +76,18 @@ class Matrix:
|
|||||||
new_matrix = Matrix(arr)
|
new_matrix = Matrix(arr)
|
||||||
return new_matrix
|
return new_matrix
|
||||||
|
|
||||||
|
def new_matrix(a,i):#FUNCTION TO FIND THE NEW MATRIX
|
||||||
|
arr = a.copy_matrix()
|
||||||
|
if len(arr) == 2:
|
||||||
|
|
||||||
|
return arr
|
||||||
|
else:
|
||||||
|
arr.pop(0)
|
||||||
|
for j in arr:
|
||||||
|
j.pop(i)
|
||||||
|
|
||||||
|
return arr
|
||||||
|
|
||||||
def determinant(self):
|
def determinant(self):
|
||||||
"""
|
"""
|
||||||
Using Cofactor Expanion.
|
Using Cofactor Expanion.
|
||||||
@ -96,14 +108,11 @@ class Matrix:
|
|||||||
return self.array[0][0] * self.array[1][1] - self.array[1][0] * self.array[0][1]
|
return self.array[0][0] * self.array[1][1] - self.array[1][0] * self.array[0][1]
|
||||||
|
|
||||||
det = 0
|
det = 0
|
||||||
for col in range(self.column):
|
for col in range(len(self.array)):
|
||||||
temp = self.copy_matrix()
|
temp = self.copy_matrix()
|
||||||
temp.array = temp.array[1:]
|
minor = lambda i, j : [row[:j] + row[j+1:] for row in (temp.array[:i]+temp.array[i+1:])]
|
||||||
for r in range(len(temp.array)):
|
temp.array = minor(0,col)
|
||||||
temp.array[r] = temp.array[r][0:col] + temp.array[r][col+1:]
|
det += ((-1)**col)*self.array[0][col]*temp.determinant()
|
||||||
|
|
||||||
det += (-1)**(col) * self.array[0][col] * temp.determinant()
|
|
||||||
|
|
||||||
return det
|
return det
|
||||||
|
|
||||||
def tranpose(self):
|
def tranpose(self):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user