# Strassion's Matrix Multiplication
A=[] # 2D Matrix
B=[] # 2D Matrix
Res=[] # 2D Matrix
def getData():
global A
global B
global Res
print("Enter first matrix: ")
for i in range(2):
A.append([])
for j in range(2):
A[i].append([])
A[i][j]=int(input())
print("Enter second matrix: ")
for i in range(2):
B.append([])
for j in range(2):
B[i].append([])
B[i][j]=int(input())
# Defining Res matrix
for i in range(2):
Res.append([])
for j in range(2):
Res[i].append([])
def showData():
global A
global B
print("\nFirst matrix is:\n")
for i in range(2):
for j in range(2):
print(A[i][j]," ",end="")
print()
print("\nSecond matrix is:\n")
for i in range(2):
for j in range(2):
print(B[i][j]," ",end="")
print()
def calculation():
global A
global B
global Res
p = (A[0][0] + A[1][1]) * (B[0][0] + B[1][1])
q = B[0][0] * (A[1][0] + A[1][1])
r = A[0][0] * (B[0][1] - B[1][1])
s = A[1][1] * (B[1][0] - B[0][0])
t = B[1][1] * (A[0][0] + A[0][1])
u = (A[1][0] - A[0][0]) * (B[0][0] + B[0][1])
v = (A[0][1] - A[1][1]) * (B[1][1] + B[1][0])
Res[0][0] = p + s - t + v
Res[0][1] = r + t
Res[1][0] = q + s
Res[1][1] = p + r - q + u
print("\nResult matrix is:\n")
for i in range(2):
for j in range(2):
print(Res[i][j]," ",end="")
print()
# __________________________ Main Block Starts __________________________
print("\t\t\t____Strassions Matrix Multiplication____")
getData()
showData()
calculation()
No comments:
Post a Comment