The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 4 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
Given an RA ×CA matrix A and an RB ×CB matrix B, with 1 ≤ RA, RB ,CA,CB ≤ 300, write a programthat computes the matrix product C = AB. All entries in matrices A and B are integers with absolutevalue less than 1000, so you don’t need to worry about overflow. If matrices A and B do not have theright dimensions to be multiplied, the product matrix C should have its number of rows and columnsboth set to zero.Use the code at provided in the file matrix.data.zip as a basis for your program–the input/outputneeded is already written for you. Matrices will be stored as a structure which we’ll typedefas Matrix. This structure will contain the size of our matrix along with a statically-sizedtwo-dimensional array to store the entries.#define MAXN 300typedef struct Matrix s {size t R, C;int index[MAXN][MAXN];} Matrix;Of course, this is rather inefficient if we need to create a lot of matrices, since every single matrix structholds MAXN*MAXN ints! For this problem, we only use three matrices, so it’s fine for this use, but we’llsee how to dynamically allocate a matrix in problem matrix2.Input FormatLine 1: Two space-separated integers, RA and CA.Lines 2 . . . RA + 1: Line i + 1 contains CA space-separated integers: row i of matrix A.Line RA + 2: Two space-separated integers, RB and CB .Lines RA + 3 . . . RA + RB + 4: Line i + RA + 3 contains CB space-separated integers: row i of matrix A.Sample Input (file matrix.in)3 21 11 2-4 02 31 2 13 2 1Output FormatLine 1: Two space-separated integers RC and CC , the dimensions of the product matrix C .Lines 2 . . . RC + 1: Line i + 1 contains CC space-separated integers: row i of matrix C .1 MIT 6.S096 Assignment 1, Problem 2If A and B do not have the right dimensions to be multiplied, your output should just be one linecontaining 0 0.Sample Output (file matrix.out)3 34 4 27 6 3-4 -8 -4Output ExplanationWe are given⎛ ⎞ 1 1 1 2 1 A = ⎝ 1 2⎠ and B = 3 2 1 −4 0so the product is the 3 × 3 matrix⎛ ⎞ ⎛ ⎞ 1 1 4 4 2 1 2 1 AB = ⎝ 1 2⎠ = ⎝ 7 6 3 ⎠. 3 2 1 −4 0 −4 −8 −4
-MIT 6.S096Assignment 1, Problem 2Problem 2: Matrix Multiplication (matrix)Given anRA×CAmatrixAand anRB×CBmatrixB, with 1≤RA,RB,CA,CB≤300, write a programthat computes the matrix productC=AB. All entries in matricesAandBare integers with absolutevalue less than 1000, so you don’t need to worry about overflow. If matricesAandBdo not have theright dimensions to be multiplied, the product matrixCshould have its number of rows and columnsboth set to zero.Use the code atprovided in the file matrix.data.zip as a basis for your program–the input/outputneeded is already written for you. Matrices will be stored as a structure which we’lltypedefasMatrix. This structure will contain the size of our matrix along with a statically-sizedtwo-dimensional array to store the entries.#defineMAXN300typedefstructMatrix s{size tR,C;intindex[MAXN][MAXN];}Matrix;Of course, this is rather ineFcient if we need to create a lot of matrices, since every single matrix structholdsMAXN*MAXNints! ±or this problem, we only use three matrices, so it’s fine for this use, but we’llsee how to dynamically allocate a matrix in problemmatrix2.Input FormatLine 1: Two space-separated integers,RAandCA.²Lines 2.. .RA+1: Linei+1containsCAspace-separated integers: rowiof matrixA.²LineRA+2: Two space-separated integers,RBandCB.²LinesRA+3...RA+RB+4: Linei+RA+3containsCBspace-separated integers: rowiof matrixA.²Sample Input (file matrix.in)3 21 11 2-402 31 2 13 21Output FormatLine 1: Two space-separated integersRCandCC, the dimensions of the product matrixC.Lines 2.. .RC+1: Linei+1containsCCspace-separated integers: rowiof matrixC.1²
Attachments:
-----------