Matrix multiplication is a very common operation. Just like addition works only for matrices of the same size, there are conditions for when two matrices can be multiplied but in this case it is a little bit more complicated. Given two matrices equation and equation where equation is a equation x equation matrix, they can only be multiplied if equation is a equation x equation matrix with a result that is a equation x equation matrix. This means the number of columns of equation (the first matrix) must match the number of rows of equation (the second matrix) and the resulting matrix will have as many rows as equation and as many columns as equation. Note that the order of the matrices matters! The following illustrates this:

matrixmul

To calculate one entry equation in the result matrix equation, we look at row equation of equation and column equation of equation. The following diagram illustrates how each entry in equation is obtained from a row of equation and column of equation:

matrixmul2

Let us see how equation is calculated. For that we look at row 1 of equation which is equation and column 1 of equation which is equation. We then calculate equation similar to how we calculate the dot product of two vectors:

    equation

Example

We are given the following two matrices:

(1)   equation

We can confirm that the number of rows of equation matches the number of columns of equation so we can multiply them. The resulting matrix be a 2×2 matrix (because equation has 2 rows and equation has 2 columns).

    equation

For equation we look at the first row of equation and first column of equation and multiply them:

(2)   equation

For equation we look at the first row of equation and second column of equation and multiply them:

(3)   equation

We repeat the same for equation and equation:

(4)   equation

Now we calculated all entries of our result:

    equation

Rules

Matrix multiplication is not commutative. This means that the order of the multiplication is important. In general, this means equation for different matrices equation and equation. However, the identity matrix (explained later) is an exception so if one of the two matrices is the identity matrix and the other matrix is a square matrix, it can be pre-multiplied or post-multiplied to give the same result.

Matrix multiplication is associative. This means equation.

With regards to the transpose, the following operation is allowed for matrix multiplication: equation.

Identity matrix

A square matrix equation that is multiplied with an identity matrix equation of the same order, gives the same matrix equation. The order of the multiplication does not matter in this case:

    equation

The identity matrix with regards to matrix multiplication is similar to the number 1 for normal multiplication. Just like any number multiplied by 1 gives the same number, the same is true for any matrix multiplied with the identity matrix.

Inverse matrix

Some matrices can be inverted. This means that given a matrix equation, there may be an inverse of it equation, such that:

    equation

The inverse for matrix multiplication is similar to normal multiplication. Take a number equation, then its inverse equation is equation, so equation. For matrix multiplication, the inverse is a bit more difficult to find and not every matrix has an inverse. Read more on inverse matrices.