Multiplication of Matrices

When you add or subtract matrices, the two matrices that you add or subtract must have the same number of rows and the same number of columns. In other words, both must have the same shape.

For matrix multiplication, all that is required is that the number of columns of the first matrix be the same as the number of rows of the second matrix. In other words, you can multiply an $ m\times k$ matrix by a $ k\times n$ matrix, with the $ m\times k$ matrix on the left and the $ k\times n$ matrix on the right. The example on the left below represents a legal multiplication since there are three columns in the left multiplicand and three rows in the right one; the example on the right doesn't make sense--the left matrix has three columns, but the right one has only 2 rows. If the matrices on the right were written in the reverse order with the $ 2\times 3$ martix on the left, it would represent a valid matrix multiplication.

$\displaystyle \begin{pmatrix}1 & 3 & 5 \\ 4 & 7 & 2 \\ 9 & 1 & 6 \\ 0 & 2 & 0
\...
...1 \\ 0 & 1 & 0 \end{pmatrix}\begin{pmatrix}0 & 1 & 1 \\ 2 & 1 & 3 \end{pmatrix}$

So now we know what shapes of matrices it is legal to multiply, but how do we do the actual multiplication? Here is the method:

If we are multiplying an $ m\times k$ matrix by a $ k\times n$ matrix, the result will be an $ m\times n$ matrix. The element in the product in row $ i$ and column $ j$ is gotten by multiplying termwise all the elements in row $ i$ of the matrix on the left by all the elements in column $ j$ of the matrix on the right and adding them together.

Here is an example:

$\displaystyle \begin{pmatrix}1 & 3 & 2 \\ 5 & 0 & 7 \\ 6 & 9 & 8
\end{pmatrix}\...
...9
\end{pmatrix}=
\begin{pmatrix}
32 & 59 \\ 55 & 118 \\ 118 & 228
\end{pmatrix}$

To find what goes in the first row and first column of the product, take the number from the first row of the matrix on the left: $ (1, 3, 2)$, and multiply them, in order, by the numbers in the first column of the matrix on the right: $ (4, 6, 5)$. Add the results: $ 1\cdot 4 + 3\cdot 6 + 2\cdot 5 = 4 + 18 + 10 = 32$. To get the 228 in the third row and second column of the product, the use the numbers in the third row of the left matrix: $ (6, 9, 8)$ and the numbers in the second column of the right matrix: $ (11, 10, 9)$ to get $ 6\cdot 11 + 9\cdot 10 + 8\cdot 9 = 66+90+72=228$.

Check your understanding by verifying that the other elements in the product matrix are correct.

In general, if we multiply a general $ m\times k$ matrix by a general $ k\times n$ matrix to get an $ m\times n$ matrix as follows:

$\displaystyle \begin{pmatrix}
a_{11} & a_{12} & \cdots & a_{1k} \\
a_{21} & a_...
... & \vdots & \ddots & \vdots \\
c_{m1} & c_{m2} & \cdots & c_{mn}
\end{pmatrix}$

Then we can write $ c_{ij}$ (the number in row $ i$, column $ j$) as:

$\displaystyle c_{ij} = \sum_{p=1}^k{a_{ip}b_{pj}}. $