Question: Question 3 of 3. Matrix Multiplication: [50 marks] Write a function which can multiply matrices. A matrix is defined as a 2-dimensional array. Given two
Question 3 of 3. Matrix Multiplication: [50 marks] Write a function which can multiply matrices. A matrix is defined as a 2-dimensional array. Given two 2-dimensional arrays A and B. if A is an n m matrix with n rows and m columns and B is an m p matrix, their matrix product AB is an n p matrix, in which the m entries across a row of A are multiplied with the m entries down a column of B and summed to produce an entry of AB. The number of columns of A should be the same as the number of rows in B. (0,0 0,0) + (0,1 1,0) + (0,2 2,0) (0,0 0,1) + (0,1 1,1) + (0,2 2,1) (0,0 0,2) + (0,1 1,2) + (0,2 2,2) (1,0 0,0) + (1,1 1,0) + (1,2 2,0) (1,0 0,1) + (1,1 1,1) + (1,2 2,1) (1,0 0,2) + (1,1 1,2) + (1,2 2,2) 2 3 Your code should ask the user for the matrix size and then take each matrix as input. Your program will check for compatibility, i.e., if the two matrices can be multiplied. Following this, if the matrices are compatible for multiplication, your program will print the resultant array from the multiplication. Your program will contain a user defined function MatrixMultiply(). Your program shall pass the input matrices and the output/result matrix variable as parameters to the function MatrixMultiply(), which will multiply the matrices and update the resultant matrix as a reference. Please use the following function declaration. void MatrixMultiply (int mat1[][20], int rows1, int cols1, int mat2[][20], int rows2, int cols2, int result[][20]); Make sure your code works for any input number, not just the test cases. Your code will be tested on other test cases not listed here. You need to assume a maximum matrix size of 20 by 20 Please properly comment your code before submission. For this part of the assignment, name your source file as MatrixMultiply_WSUID.cpp. For example, if your user ID is A999B999 name your file as MatrixMultiply_A999B999.cpp. 0,0 0,1 0,2 0,0 0,1 0,2 = 1,0 1,1 1,2 1,0 1,1 1,2
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
