Skip to content

Mathematics · Ch 4 — Determinants and Matrices

Multiplication of Two Matrices

4.5.4

Multiplication of Two Matrices

Multiplication of Two Matrices

Two matrices Am×nA_{m\times n} and Bn×pB_{n\times p} are conformable for the product ABAB exactly when the number of columns of AA equals the number of rows of BB. The product is then C=ABC=AB of order m×pm\times p, with entries

Cij=∑k=1naikbkj=ai1b1j+ai2b2j+⋯+ainbnjC_{ij}=\sum_{k=1}^{n}a_{ik}b_{kj}=a_{i1}b_{1j}+a_{i2}b_{2j}+\cdots+a_{in}b_{nj}

— that is, CijC_{ij} is "row ii of AA dotted with column jj of BB".

Worked Examples

Example 1. A=[a11 a12 a13]1×3A=[a_{11}\ a_{12}\ a_{13}]_{1\times3}, B=[b11b21b31]3×1B=\begin{bmatrix}b_{11}\\b_{21}\\b_{31}\end{bmatrix}_{3\times1}: since columns of AA = rows of BB = 3, ABAB is defined, order 1×11\times1: AB=[a11b11+a12b21+a13b31]AB=[a_{11}b_{11}+a_{12}b_{21}+a_{13}b_{31}].

Example 2. A=[1  3  2]1×3A=[1\ \ 3\ \ 2]_{1\times3}, B=[321]3×1B=\begin{bmatrix}3\\2\\1\end{bmatrix}_{3\times1}.

Step 1: AB=[1×3+3×2+2×1]=[3+6+2]=[11]1×1AB=[1\times3+3\times2+2\times1]=[3+6+2]=[11]_{1\times1}.

Step 2: BABA is also defined (columns of BB=1=rows of AA), order 3×33\times3: BA=[321][1  3  2]=[396264132]BA=\begin{bmatrix}3\\2\\1\end{bmatrix}[1\ \ 3\ \ 2]=\begin{bmatrix}3&9&6\\2&6&4\\1&3&2\end{bmatrix}.

Here both ABAB and BABA exist, but ABAB is 1×11\times1 while BABA is 3×33\times3 — they aren't even the same shape, let alone equal.

Example 3. A=[1−22−130]3×2A=\begin{bmatrix}1&-2\\2&-1\\3&0\end{bmatrix}_{3\times2}, B=[1−2−12]2×2B=\begin{bmatrix}1&-2\\-1&2\end{bmatrix}_{2\times2}.

Step 1: AA is 3×23\times2, BB is 2×22\times2, so ABAB (order 3×23\times2) is defined but BABA is NOT (columns of BB=2 ≠ rows of AA=3).

Step 2: AB=[1(1)+(−2)(−1)1(−2)+(−2)(2)2(1)+(−1)(−1)2(−2)+(−1)(2)3(1)+0(−1)3(−2)+0(2)]=[3−63−63−6]AB=\begin{bmatrix}1(1)+(-2)(-1)&1(-2)+(-2)(2)\\2(1)+(-1)(-1)&2(-2)+(-1)(2)\\3(1)+0(-1)&3(-2)+0(2)\end{bmatrix}=\begin{bmatrix}3&-6\\3&-6\\3&-6\end{bmatrix}.

Example 4. A=[3−21254]2×3A=\begin{bmatrix}3&-2&1\\2&5&4\end{bmatrix}_{2\times3}, B=[−323−2]2×2B=\begin{bmatrix}-3&2\\3&-2\end{bmatrix}_{2\times2}: since columns of AA(3) ≠ rows of BB(2), ABAB is not defined; but columns of BB(2)=rows of AA(2), so BABA (order 2×32\times3) is defined and can be computed by the row-times-column rule.

Example 5. A=[4532]A=\begin{bmatrix}4&5\\3&2\end{bmatrix}, B=[−134−2]B=\begin{bmatrix}-1&3\\4&-2\end{bmatrix} — both 2×22\times2, so both ABAB and BABA exist and are 2×22\times2. …

Misc 4.5.4Worked Example 1 — product of a row matrix and a column matrix

Worked out. Two 2×2 matrices are multiplied both ways, both products coming out 2×2 but with different entries, confirming matrix multiplication is not commutative even when both orders are defined. …

Misc 4.5.4Worked Example 2 — AB and BA both exist but differ

Worked out. Two 2×2 matrices are multiplied both ways, both products coming out 2×2 but with different entries, confirming matrix multiplication is not commutative even when both orders are defined. …

Misc 4.5.4Worked Example 3 — AB defined but BA not defined

Worked out. Two 2×2 matrices are multiplied both ways, both products coming out 2×2 but with different entries, confirming matrix multiplication is not commutative even when both orders are defined. …

Misc 4.5.4Worked Example 4 — BA defined but AB not defined

Worked out. Two 2×2 matrices are multiplied both ways, both products coming out 2×2 but with different entries, confirming matrix multiplication is not commutative even when both orders are defined. …

Misc 4.5.4Worked Example 5 — both AB and BA defined, of the same order, but unequal

Worked out. Two 2×2 matrices are multiplied both ways, both products coming out 2×2 but with different entries, confirming matrix multiplication is not commutative even when both orders are defined. …