Matrix multiplication

To multiply two matrices, you don't just multiply the corresponding entries of the matrices – it's a bit more complicated than that.

The simplest matrices to multiply are a row matrix and a column matrix, provided they have the same number of entries.

To form the product of a 1 x n row matrix and a n x 1 column matrix, in that order,

multiply their corresponding entries together

add the results.

For example,

You can think of this product as either a scalar or a 1 x 1 matrix.

In general, you can't multiply matrices if their sizes don't "match": the "width" of the first has to be the same as the "height" of the second. Once that's true, you can multiply more general matrices just by multiplying all the rows of the first by all of the columns of the second.

To form the product of an m x n matrix A and an n x k matrix B:

The product AB is an m x k matrix.

The entry in row i and column j of AB is the product of row i of A and column j of B.

Here's an example.

Notice that the order of the matrices you're multiplying is important, since you always use rows from the first matrix and columns from the second. The two matrices above cannot be multiplied in the opposite order.

 

Unlike addition and scalar multiplication, matrix multiplication does not obey all the same rules that number multiplication does. Below are two lists. One gives the multiplication rules for number arithmetic that do work for matrix multiplication; the other lists the rules for number arithmetic that don't work for matrices.

Calculation rules for numbers that also work for matrices

For any number a, 1a = a.

The matrices which behave like the number 1 for multiplication are the identity matrices. Identity matrices are square matrices with 1's along the main diagonal and 0's everywhere else – the 2 x 2 identity matrix is

for example. The n x n matrix is written as In, or just I if the size is not important or is clear from the context.

If A is any m x n matrix, then ImA = A and AIn = A. (Notice that you generally need a different size identity matrix to multiply on one side from the one you need to multiply on the other.)

For any number a, 0a = 0.

The matrices which behave like the number 0 for multiplications are the zero matrices Omn

For any m x n matrix A,

OkmA = Okn and AOmj = Onj

For any numbers a, b and c, (ab)c = a(bc) (associative rule).

For any matrices A, B and C for which the multiplications are defined,

(AB)C = A(BC).

(Matrix multiplication is associative.)

For any numbers a, b and c, a(b + c) = ab + ac.

For any matrices A, B and C for which the sums and products are defined

A(B + C) = AB + BC   and   (B + C)A = BA + CA

(Matrix multiplication is distributive.)

 

Calculation rules for numbers that don't work for matrices.

For any numbers a and b, ab = ba (commutative rule).

For most matrices A and B, ABBA, even when both multiplications are defined and the same size.

Example:

Matrix multiplication is not commutative.

For any numbers a, c and c, if ab = ac and a ≠ 0, then b = c (cancellation).

For most matrices A, B and C with AB = AC, BC even if AO.

Example:

You can't cancel matrices in matrix multiplication.

For any numbers a and b, if ab = 0, then either a = 0 or b = 0.

It's possible to have matrices A and B with neither O but with AB = O.

Example:

 

Square matrices can always be multiplied by themselves, so you can talk about their powers; for example A4 = AAAA. We define A0 = I for square matrices, so you can also talk about polynomials of square matrices – expressions such as 3A2 – 2A + 5I, for example.

However, many common algebraic identities don't work for square matrices. For example, the "difference of squares" factoring doesn't work because, for any same-sized square matrices A and B,
         (A + B)(AB) = A(AB) + B(AB) = A2AB + BAB2,

which does not equal A2B2 unless AB = BA.