Matrix Multiplication

By now you've already read our first tutorial on matrices; recall that a matrix is basically a rectangle full of numbers, and that they can be added. The question now is, of course: how do you multiply matrices?

Matrix multiplication is very unusual. Here are some of the strange things about it:

• If A is a matrix and B is a matrix, A * B is not the same as B * A.
• To add two matrices, they had to be the same size. This is not true for multiplication.
• In order for A * B to exist, A must have the same number of columns that B has rows.

As an example, let us suppose that we have a 3 × 4 matrix M and a 4 × 2 matrix N. We can take M * N, because the number of columns in M (4) is the same as the number of rows in N. However, we cannot find N * M, because the number of columns in N (2) is not the same as the number of rows in M (3).

So, if we have an a × b matrix M, and a b × c matrix N, we can find M * N. What will its dimensions be? The answer is simple: a × c.

Now that we know this, let's take a look at an example. We have a 2 × 2 matrix M and a 2 × 1 matrix N, given below:

We know that the result will be a 2 (the number of rows in M) × 1 (the number of columns in N) matrix, but so far we don't know how to find the components (x and y).

Here's how to find x (the element in row 1, column 1 of the result): take row 1 of M (2,3) and combine it with column 1 of N (5,-2) in this way: x = 2 * 5 + 3 * (-2) = 10 - 6 = 4. (That is, multiply the elements in corresponding positions, and add the results together).

Now to find y (row 2, column 1 of the result): take row 2 of M (1,-4) and combine it with column 1 of N (5, -2) in the same way: y = 1 * 5 + (-4) * (-2) = 5 + 8 = 13.

If you're curious about why the numbers are combined in that way, it happens to be the dot product of two vectors. It's something you'll find in almost any book on vectors. A vector is basically a 1-column or 1-row matrix.

In general, to find the element in row i, column j in matrix multiplication, you take row i of your first matrix and "dot" it with column j of the second matrix.

That's all there is to it! If you want more information, check any book on linear algebra ("precalculus" books will also probably give some material on matrices).