A matrix, as opposed to the matrix of movie fame, is an array of numbers. You will often see a matrix referred to as an (m x n) matrix where m and n denote the number of rows and columns, respectively. Matrix multiplication is not commutative.
Here's your math lesson for the day.
In order to multiply 2 matrices, the number of columns in the first matrix must equal the number of rows in the second matrix. If you have an (m x n) matrix multiplying an (r x s) matrix, you must have n = r. The funny thing is that if you switch the order so that you're multiplying the same (r x s) matrix by the same (m x n) matrix, then you need s = m.
Here's an example: if matrix A is a (3 x 3) matrix and matrix B is a (3 x 1) matrix, you can multiply A by B – a (3 x 3) multiplying a (3 x 1), where n and r both equal 3. But you can’t commute the two matrices. Multiplying B by A is undefined since you have a (3 x 1) multiplying a (3 x 3) and n = 1 while r = 3.
But what if you have two matrices with the same number of rows and columns? Shouldn't they be commutative? First, you need to know how matrix multiplication is performed. The simple (text book) definition looks like this:
For a matrix A = (aij) and a matrix B = (bij), the product AB is defined as
In math speak that makes very little sense. It looks something like this.
Nasty! Let’s try an example with numbers. I’m going to use (2 x 2) matrices A and B where
When you multiply AB, you get
And when you multiply BA, you get
So, for this example, you can see that AB is not equal to BA. There are occasional instances where AB will equal BA, but this is not generally true.
Just to briefly return to the Fundamental Theorem of Arithmetic where this started. The theorem orders the prime factors. This is important within the proof - order matters - but I think we’ll get to that tomorrow.
Reference: Johnson, L.W., Riess, R.D. & Arnold, J.T. (2002). Introduction to Linear Algebra (5th ed.). Boston, MA: Addison-Wesley.