Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

 

Complete this code using Python

 

m1 = [] #Matrix 1
m2 = [] #Matrix 2

#Write a function that will return the addition of Matrix A and B.
#Create a new matrix C that will hold the addtion result of Matrix A and B (A+B).
#Return the resultant matrix C
def addMatrix(A,B):
#Write your code here


#Write a function that will return the subtraction of Matrix B from A.
#Create a new matrix C that will hold the substraction result of Matrix B from A (A-B).
#Return the resultant matrix C
def subsMatrix(A,B):
#Write your code here


#Write a function that will return the multiplication of Matrix A and B.
#Create a new matrix C that will hold the multiplication result of Matrix A and B (A*B).
#Keep in mind,in order to perform matrix multiplication, the number of columns in Matrix A must be equal to the number of columns in Matrix B.
#Return the resultant matrix C
def multipyMatrix(A,B):
#Write your code here


#Write a function that will transform matrix A to the transpose of matrix A.
#The transpose of a matrix means the rows of the matrix will become the columns of the matrix, the columns will become rows of the matrix
def transpose(A):
#Write your code here

def takeRowColInput():
row = int(input("Please enter the number of rows in the matrix:"))
col = int(input("Please enter the number of columns in the matrix:"))
matrixInitialization(m1,row,col)
matrixInitialization(m2,row,col)
printMatrix(m1)
printMatrix(m2)

def matrixInitialization(m,row,col):
for r in range(row):
l=[]
for c in range(col):
l.append(0)
m.append(l)
def printMatrix(m):
for row in range(len(m)):
print("| ",end="")
for col in range(len(m[row])):
print(m[row][col], end =" ")
print("|")
print()
def takeMatrixInput(m):
for row in range(len(m)):
for col in range(len(m[row])):
m[row][col] = int(input(f"Enter value for [{row},{col}] : "))
printMatrix(m)

takeRowColInput()
takeMatrixInput(m1)
takeMatrixInput(m2)

addRes = addMatrix(m1,m2) #m1+m2
printMatrix(addRes)

subRes = subsMatrix(m1,m2) #m1-m2
printMatrix(subRes)

mulRes = multipyMatrix(m1,m2) #m1*m2
print(mulRes)

transpose(m1)
printMatrix(m1)

transpose(m2)
printMatrix(m2)

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education