-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix Inverse.py
More file actions
45 lines (39 loc) · 908 Bytes
/
Matrix Inverse.py
File metadata and controls
45 lines (39 loc) · 908 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
A = [] #Initialize Matrix A
B = [] #Initialize Matrix B (Inverse Of A)
multResult = [] #Initialize Result.
ord = int(input("Enter Order Of Matrix: ")) #get order of square matrix
def make(matrix):
for i in range(ord):
l = []
for j in range(ord):
inp = int(input("Enter Value: "))
l.append(inp)
matrix.append(l)
def matrixMultiply():
for i in range(ord):
l = []
for j in range(ord):
result = 0
for k in range(ord):
result += A[i][k] * B[k][j]
if k == ord - 1:
l.append(result)
if j == ord - 1:
multResult.append(l)
def check():
I = []
for i in range(ord):
l = []
for j in range(ord):
if i == j:
l.append(1)
else:
l.append(0)
I.append(l)
if multResult == I:
print("It is the inverse.")
else:
print("Not Inverse")
make(A),make(B)
matrixMultiply()
check()