author

Kien Duong

January 29, 2023

Matrix multiplication

For matrix multiplication, the number of columns in the first matrix must be equal to the number of rows in the second matrix. The result matrix has the number of rows of the first and the number of columns of the second matrix.

\[
\begin{align}
\begin{bmatrix}A\end{bmatrix} \times \begin{bmatrix}B\end{bmatrix} &=
\begin{bmatrix}
a_{11} & a_{12} & \dots & a_{1n} \\
a_{21} & a_{22} & \dots & a_{2n} \\
\vdots & \vdots & \ddots & \vdots \\
a_{m1} & a_{m2} & \dots & a_{mn}
\end{bmatrix}
\times
\begin{bmatrix}
b_{11} & a_{12} & \dots & a_{1p} \\
b_{21} & a_{22} & \dots & a_{2p} \\
\vdots & \vdots & \ddots & \vdots \\
b_{n1} & a_{n2} & \dots & a_{np}
\end{bmatrix} \\
&=
\begin{bmatrix}
c_{11} & a_{12} & \dots & a_{1p} \\
c_{21} & a_{22} & \dots & a_{2p} \\
\vdots & \vdots & \ddots & \vdots \\
c_{m1} & a_{m2} & \dots & a_{mp}
\end{bmatrix}
\end{align}
\]

\[
A_{m \times n} \times B_{n \times p} = C_{m \times p}
\Rightarrow
c_{ij} = a_{i1}b_{1j} + a_{i2}b_{2j} + … + a_{in}b_{nj} = \sum_{k=1}^n a_{ik}b_{kj}
\]

For example:

\[
\begin{bmatrix}
2 & 4 & 6 \\
3 & 5 & 7 \\
\end{bmatrix}
\times
\begin{bmatrix}
1 & 2 \\
3 & 4 \\
5 & 6
\end{bmatrix} =
\begin{bmatrix}
c_{11} & c_{12} \\
c_{21} & c_{22}
\end{bmatrix}
\]

\[
\begin{aligned}
c_{11} = a_{11}b_{11} + a_{12}b_{21} + a_{13}b_{31} = 2 \times 1 + 4 \times 3 + 6 \times 5 = 44 \\
c_{12} = a_{11}b_{12} + a_{12}b_{22} + a_{13}b_{32} = 2 \times 2 + 4 \times 4 + 6 \times 6 = 56 \\
c_{21} = a_{21}b_{11} + a_{22}b_{21} + a_{23}b_{31} = 3 \times 1 + 5 \times 3 + 7 \times 5 = 53 \\
c_{22} = a_{21}b_{12} + a_{22}b_{22} + a_{23}b_{32} = 3 \times 2 + 5 \times 4 + 7 \times 6 = 68 \\
\end{aligned}
\Rightarrow
\begin{bmatrix}
44 & 56 \\
53 & 68
\end{bmatrix}
\]

Recent Blogs