This file contains hidden or 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
def calcDeterminant(matrix): | |
det = 0 | |
for c in range(len(matrix)): | |
det += matrix[0][c] * calcMinorMeheraj(matrix, 0, c) | |
return det |
This file contains hidden or 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
def inverseUtil(matrix, det): | |
inverse_matrix = [[matrix[r][c] * (1 / det) for c in range(3)] for r in range(3)] | |
return inverse_matrix |
This file contains hidden or 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
def calcCofactorMatrix(matrix): | |
cofactor_matrix = [[float(calcMinor(matrix, r, c)) for c in range(3)] for r in range(3)] | |
return cofactor_matrix |
This file contains hidden or 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
matrix = [[1, 2, 3], | |
[0, 1, 4], | |
[5, 6, 0]] |
This file contains hidden or 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
def calcMinor(matrix, r, c): | |
minor = (matrix[r-2][c-2] * matrix[r-1][c-1]) - (matrix[r-1][c-2] * matrix[r-2][c-1]) | |
return minor |
This file contains hidden or 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
def calcDeterminant(matrix): | |
det = 0 | |
for c in range(len(matrix)): | |
det += matrix[0][c] * calcMinor(matrix, 0, c) | |
return det | |
def calcMinor(matrix, r, c): | |
minor = (matrix[r-2][c-2] * matrix[r-1][c-1]) - (matrix[r-1][c-2] * matrix[r-2][c-1]) | |
return minor |
This file contains hidden or 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
def zeros(rows, cols): | |
matrix = [[0 for i in range(cols)] for j in range(rows)] | |
return matrix | |
mat = zeros(3, 3) |
This file contains hidden or 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
def ones(rows, cols): | |
matrix = [[1 for i in range(cols)] for j in range(rows)] | |
return matrix | |
mat = ones(3, 3) |
This file contains hidden or 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
def identity(n): | |
mat = zeros(n, n) | |
for i in range(n): | |
mat[i][i] = 1 | |
return mat | |
mat = identity(3) |
This file contains hidden or 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
def add(mat1, mat2): | |
row1 = len(mat1) | |
col2 = len(mat2[0]) | |
result = zeros(row1, col2) | |
for i in range(row1): | |
for j in range(col2): | |
result[i][j] = mat1[i][j] + mat2[i][j] | |
OlderNewer