Home /
Expert Answers /
Computer Science /
to-multiply-matrix-a-by-matrix-b-the-number-of-columns-in-a-must-be-the-same-as-the-number-of-row-pa282
(Solved):
To multiply matrix a by matrix b, the number of columns in a must be the same as the number of row ...
To multiply matrix a by matrix b, the number of columns in a must be the same as the number of rows in \( \mathrm{b} \), and the two matrices must have elements of the same or compatible types. Let \( c \) be the result of the multiplication. Assume the column size of matrix a is n. Each element \( c_{i j} \) is \( a_{i 1} \times b_{1 j}+a_{i 2} \times b_{2 j}+\ldots+a_{i n} \times b_{n j} \). For example, for two \( 3 \times 3 \) matrices \( a \) and \( b \), \( c \) is \[ \left(\begin{array}{lll} a_{11} & a_{12} & a_{13} \\ a_{21} & a_{22} & a_{23} \\ a_{31} & a_{32} & a_{33} \end{array}\right) \times\left(\begin{array}{lll} b_{11} & b_{12} & b_{13} \\ b_{21} & b_{22} & b_{23} \\ b_{31} & b_{32} & b_{33} \end{array}\right)=\left(\begin{array}{lll} c_{11} & c_{12} & c_{13} \\ c_{21} & c_{22} & c_{23} \\ c_{31} & c_{32} & c_{33} \end{array}\right) \] Write a test program that prompts the user to enter two \( 3 \times 3 \) matrices and displays their product. Here is a sample run: