15.3: Matrix Multiplication
- Page ID
- 106898
If \(\mathbf{A}\) has dimensions \(m\times n\) and \(\mathbf{B}\) has dimensions \(n\times p\), then the product \(\mathbf{AB}\) is defined, and has dimensions \(m\times p\).
The entry \((ab)_{ij}\) is obtained by multiplying row \(i\) of \(\mathbf{A}\) by column \(j\) of \(\mathbf{B}\), which is done by multiplying corresponding entries together and then adding the results:

Calculate the product
\[\begin{pmatrix} 1 &-2 &4 \\ 5 &0 &3 \\ 0 & 1/2 &9 \end{pmatrix}\begin{pmatrix} 1 &0 \\ 5 &3 \\ -1 &0 \end{pmatrix} \nonumber\]
Solution
We need to multiply a \(3\times 3\) matrix by a \(3\times 2\) matrix, so we expect a \(3\times 2\) matrix as a result.
\[\begin{pmatrix} 1 &-2 &4 \\ 5 &0 &3 \\ 0 & 1/2 &9 \end{pmatrix}\begin{pmatrix} 1 &0 \\ 5 &3 \\ -1 &0 \end{pmatrix}=\begin{pmatrix} a&b \\ c&d \\ e &f \end{pmatrix} \nonumber\]
To calculate \(a\), which is entry (1,1), we use row 1 of the matrix on the left and column 1 of the matrix on the right:
\[\begin{pmatrix} {\color{red}1} &{\color{red}-2} &{\color{red}4} \\ 5 &0 &3 \\ 0 & 1/2 &9 \end{pmatrix}\begin{pmatrix} {\color{red}1} &0 \\ {\color{red}5} &3 \\ {\color{red}-1} &0 \end{pmatrix}=\begin{pmatrix} {\color{red}a}&b \\ c&d \\ e &f \end{pmatrix}\rightarrow a=1\times 1+(-2)\times 5+4\times (-1)=-13 \nonumber\]
To calculate \(b\), which is entry (1,2), we use row 1 of the matrix on the left and column 2 of the matrix on the right:
\[\begin{pmatrix} {\color{red}1} &{\color{red}-2} &{\color{red}4} \\ 5 &0 &3 \\ 0 & 1/2 &9 \end{pmatrix}\begin{pmatrix} 1&{\color{red}0} \\ 5&{\color{red}3} \\ -1&{\color{red}0} \end{pmatrix}=\begin{pmatrix} a&{\color{red}b} \\ c&d \\ e &f \end{pmatrix}\rightarrow b=1\times 0+(-2)\times 3+4\times 0=-6 \nonumber\]
To calculate \(c\), which is entry (2,1), we use row 2 of the matrix on the left and column 1 of the matrix on the right:
\[\begin{pmatrix} 1&-2&4\\ {\color{red}5} &{\color{red}0} &{\color{red}3} \\ 0 & 1/2 &9 \end{pmatrix}\begin{pmatrix} {\color{red}1} &0 \\ {\color{red}5} &3 \\ {\color{red}-1} &0 \end{pmatrix}=\begin{pmatrix} a&b \\ {\color{red}c}&d \\ e &f \end{pmatrix}\rightarrow c=5\times 1+0\times 5+3\times (-1)=2 \nonumber\]
To calculate \(d\), which is entry (2,2), we use row 2 of the matrix on the left and column 2 of the matrix on the right:
\[\begin{pmatrix} 1&-2&4\\ {\color{red}5} &{\color{red}0} &{\color{red}3} \\ 0 & 1/2 &9 \end{pmatrix}\begin{pmatrix} 1&{\color{red}0} \\ 5&{\color{red}3} \\ -1&{\color{red}0} \end{pmatrix}=\begin{pmatrix} a&b \\ c&{\color{red}d} \\ e &f \end{pmatrix}\rightarrow d=5\times 0+0\times 3+3\times 0=0 \nonumber\]
To calculate \(e\), which is entry (3,1), we use row 3 of the matrix on the left and column 1 of the matrix on the right:
\[\begin{pmatrix} 1&-2&4\\ 5&0&3 \\ {\color{red}0} &{\color{red}1/2} &{\color{red}9} \end{pmatrix}\begin{pmatrix} {\color{red}1} &0 \\ {\color{red}5} &3 \\ {\color{red}-1} &0 \end{pmatrix}=\begin{pmatrix} a&b \\ c&d \\ {\color{red}e} &f \end{pmatrix}\rightarrow e=0\times 1+1/2\times 5+9\times (-1)=-13/2 \nonumber\]
To calculate \(f\), which is entry (3,2), we use row 3 of the matrix on the left and column 2 of the matrix on the right:
\[\begin{pmatrix} 1&-2&4\\ 5&0&3 \\ {\color{red}0} &{\color{red}1/2} &{\color{red}9} \end{pmatrix}\begin{pmatrix} 1&{\color{red}0} \\ 5&{\color{red}3} \\ -1&{\color{red}0} \end{pmatrix}=\begin{pmatrix} a&b \\ c&d \\ e&{\color{red}f} \end{pmatrix}\rightarrow f=0\times 0+1/2\times 3+9\times 0=3/2 \nonumber\]
The result is:
\[\displaystyle{\color{Maroon}\begin{pmatrix} 1 &-2 &4 \\ 5 &0 &3 \\ 0 & 1/2 &9 \end{pmatrix}\begin{pmatrix} 1 &0 \\ 5 &3 \\ -1 &0 \end{pmatrix}=\begin{pmatrix} -13&-6 \\ 2&0 \\ -13/2 &3/2 \end{pmatrix}} \nonumber\]
Calculate
\[\begin{pmatrix} 1 &-2 &4 \\ 5 &0 &3 \\ \end{pmatrix}\begin{pmatrix} 1 \\ 5 \\ -1 \end{pmatrix}\nonumber\]
Solution
We are asked to multiply a \(2\times 3\) matrix by a \(3\times 1\) matrix (a column vector). The result will be a \(2\times 1\) matrix (a vector).
\[\begin{pmatrix} 1 &-2 &4 \\ 5 &0 &3 \\ \end{pmatrix}\begin{pmatrix} 1 \\ 5 \\ -1 \end{pmatrix}=\begin{pmatrix} a \\ b \end{pmatrix}\nonumber\]
\[a=1\times1+(-2)\times 5+ 4\times (-1)=-13\nonumber\]
\[b=5\times1+0\times 5+ 3\times (-1)=2\nonumber\]
The solution is:
\[\displaystyle{\color{Maroon}\begin{pmatrix} 1 &-2 &4 \\ 5 &0 &3 \\ \end{pmatrix}\begin{pmatrix} 1 \\ 5 \\ -1 \end{pmatrix}=\begin{pmatrix} -13 \\ 2 \end{pmatrix}}\nonumber\]
Need help? The link below contains solved examples: Multiplying matrices of different shapes (three examples): http://tinyurl.com/kn8ysqq
External links:
- Multiplying matrices, example 1: http://patrickjmt.com/matrices-multiplying-a-matrix-by-another-matrix/
- Multiplying matrices, example 2: http://patrickjmt.com/multiplying-matrices-example-2/
- Multiplying matrices, example 3: http://patrickjmt.com/multiplying-matrices-example-3/
The Commutator
Matrix multiplication is not, in general, commutative. For example, we can perform
\[\begin{pmatrix} 1 &-2 &4 \\ 5 &0 &3 \\ \end{pmatrix}\begin{pmatrix} 1 \\ 5 \\ -1 \end{pmatrix}=\begin{pmatrix} -13 \\ 2 \end{pmatrix} \nonumber\]
but cannot perform
\[\begin{pmatrix} 1 \\ 5 \\ -1 \end{pmatrix}\begin{pmatrix} 1 &-2 &4 \\ 5 &0 &3 \\ \end{pmatrix} \nonumber\]
Even with square matrices, that can be multiplied both ways, multiplication is not commutative. In this case, it is useful to define the commutator, defined as:
\[[\mathbf{A},\mathbf{B}]=\mathbf{A}\mathbf{B}-\mathbf{B}\mathbf{A} \nonumber\]
Given \(\mathbf{A}=\begin{pmatrix} 3&1 \\ 2&0 \end{pmatrix}\) and \(\mathbf{B}=\begin{pmatrix} 1&0 \\ -1&2 \end{pmatrix}\)
Calculate the commutator \([\mathbf{A},\mathbf{B}]\)
Solution
\[[\mathbf{A},\mathbf{B}]=\mathbf{A}\mathbf{B}-\mathbf{B}\mathbf{A}\nonumber\]
\[\mathbf{A}\mathbf{B}=\begin{pmatrix} 3&1 \\ 2&0 \end{pmatrix}\begin{pmatrix} 1&0 \\ -1&2 \end{pmatrix}=\begin{pmatrix} 3\times 1+1\times (-1)&3\times 0 +1\times 2 \\ 2\times 1+0\times (-1)&2\times 0+ 0\times 2 \end{pmatrix}=\begin{pmatrix} 2&2 \\ 2&0 \end{pmatrix}\nonumber\]
\[\mathbf{B}\mathbf{A}=\begin{pmatrix} 1&0 \\ -1&2 \end{pmatrix}\begin{pmatrix} 3&1 \\ 2&0 \end{pmatrix}=\begin{pmatrix} 1\times 3+0\times 2&1\times 1 +0\times 0 \\ -1\times 3+2\times 2&-1\times 1+2\times 0 \end{pmatrix}=\begin{pmatrix} 3&1 \\ 1&-1 \end{pmatrix}\nonumber\]
\[[\mathbf{A},\mathbf{B}]=\mathbf{A}\mathbf{B}-\mathbf{B}\mathbf{A}=\begin{pmatrix} 2&2 \\ 2&0 \end{pmatrix}-\begin{pmatrix} 3&1 \\ 1&-1 \end{pmatrix}=\begin{pmatrix} -1&1 \\ 1&1 \end{pmatrix}\nonumber\]
\[\displaystyle{\color{Maroon}[\mathbf{A},\mathbf{B}]=\begin{pmatrix} -1&1 \\ 1&1 \end{pmatrix}}\nonumber\]
Multiplication of a vector by a scalar
The multiplication of a vector \(\vec{v_1}\) by a scalar \(n\) produces another vector of the same dimensions that lies in the same direction as \(\vec{v_1}\);
\[n\begin{pmatrix} x \\ y \end{pmatrix}=\begin{pmatrix} nx \\ ny \end{pmatrix} \nonumber\]
The scalar can stretch or compress the length of the vector, but cannot rotate it (figure [fig:vector_by_scalar]).

Multiplication of a square matrix by a vector
The multiplication of a vector \(\vec{v_1}\) by a square matrix produces another vector of the same dimensions of \(\vec{v_1}\). For example, we can multiply a \(2\times 2\) matrix and a 2-dimensional vector:
\[\begin{pmatrix} a&b \\ c&d \end{pmatrix}\begin{pmatrix} x \\ y \end{pmatrix}=\begin{pmatrix} ax+by \\ cx+dy \end{pmatrix} \nonumber\]
For example, consider the matrix
\[\mathbf{A}=\begin{pmatrix} -2 &0 \\ 0 &1 \end{pmatrix} \nonumber\]
The product
\[\begin{pmatrix} -2&0 \\ 0&1 \end{pmatrix}\begin{pmatrix} x \\ y \end{pmatrix} \nonumber\]
is
\[\begin{pmatrix} -2x \\ y \end{pmatrix} \nonumber\]
We see that \(2\times 2\) matrices act as operators that transform one 2-dimensional vector into another 2-dimensional vector. This particular matrix keeps the value of \(y\) constant and multiplies the value of \(x\) by -2 (Figure \(\PageIndex{3}\)).

Notice that matrices are useful ways of representing operators that change the orientation and size of a vector. An important class of operators that are of particular interest to chemists are the so-called symmetry operators.