It is a fact that matrix multiplication is NOT commutative in general. This means that we may get a different result depending on the order in which the matrices are multiplied, that is, AB≠BA. There are special kinds of matrices called scalar matrices which commute with every other matrix. This means that matrix multiplication is commutative when one of the matrices is a scalar matrix. Scalar matrices are diagonal matrices where all diagonal entries all equal.
Counterexample Showing Matrix Multiplication is Non-Commutative:
Consider the two matrices A = \begin{bmatrix} 1 & 0 \\ 0 & 0 \end{bmatrix} \text { and } B = \begin{bmatrix} 0 & 0 \\ 1 & 0 \end{bmatrix}. We now calculate the product AB. AB = \begin{bmatrix} 1 & 0 \\ 0 & 0 \end{bmatrix} \begin{bmatrix} 0 & 0 \\ 1 & 0 \end{bmatrix} = \begin{bmatrix} 0 & 0 \\ 0 & 0 \end{bmatrix} . On the other hand the product BA is equal to, BA =\begin{bmatrix} 0 & 0 \\ 1 & 0 \end{bmatrix} \begin{bmatrix} 1 & 0 \\ 0 & 0 \end{bmatrix} = \begin{bmatrix} 0 & 0 \\ 1 & 0 \end{bmatrix} . We see that AB \neq BA which shows that matrix multiplication is not commutative in general.
In order to find more counterexamples, we can try to consider two general 2 x 2 matrices and check when the two products are equal. Consider the two matrices A = \begin{bmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{bmatrix} \text { and } B = \begin{bmatrix} b_{11} & b_{12} \\ b_{21} & b_{22} \end{bmatrix}. We now calculate the two products AB and BA. AB = \begin{bmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{bmatrix} \begin{bmatrix} b_{11} & b_{12} \\ b_{21} & b_{22} \end{bmatrix} = \begin{bmatrix} a_{11}b_{11} + a_{12}b_{21} & a_{11}b_{12} + a_{12}b_{22} \\ a_{21}b_{11} + a_{22}b_{21} & a_{21}b_{12} + a_{22}b_{22} \end{bmatrix} . BA = \begin{bmatrix} b_{11} & b_{12} \\ b_{21} & b_{22} \end{bmatrix} \begin{bmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{bmatrix} = \begin{bmatrix} b_{11}a_{11} + b_{12}a_{21} & b_{11}a_{12} + b_{12}a_{22} \\ b_{21}a_{11} + b_{22}a_{21} & b_{21}a_{12} + b_{22}a_{22} \end{bmatrix} .
We see that the two products AB and BA are not equal in general. For example, if we take a_{11}=1, a_{22}=-1, a_{12}=a_{21}=0 and b_{21}=1, b_{12}=-1, b_{11}=b_{22}=0 then we see that, AB = \begin{bmatrix} 0 & -1 \\ -1 & 0 \end{bmatrix} \neq \begin{bmatrix}0 & 1 \\ 1 & 0 \end{bmatrix} = BA .
Notice that if B is a scalar matrix of the form, B = \begin{bmatrix} \lambda & 0 \\ 0 & \lambda \end{bmatrix} then AB = BA holds and in this particular case the matrix multiplication is commutative.