2023-04-20 21:11:28 -07:00

284 lines
5.0 KiB
TeX

\section{Matrices}
\definition{}
A \textit{matrix} is a two-dimensional array of numbers: \\
$$
A =
\begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6
\end{bmatrix}
$$
The above matrix has two rows and three columns. It is thus a $2 \times 3$ matrix. \\
\vspace{1mm}
The order \say{first rows, then columns} is usually consistent in linear algebra. \\
If you look closely, you may also find it in the next definition.
\definition{}<matvec>
We can define the product of a matrix $A$ and a vector $v$:
$$
Av =
\begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6
\end{bmatrix}
\begin{bmatrix}
a \\ b \\ c
\end{bmatrix}
=
\begin{bmatrix}
1a + 2b + 3c \\
4a + 5b + 6c
\end{bmatrix}
$$
Note that each element of the resulting $2 \times 1$ matrix is the dot product of a row of $A$ with $v$:
$$
Av =
\begin{bmatrix}
\text{---} r_1 \text{---} \\
\text{---} r_2 \text{---}
\end{bmatrix}
\begin{bmatrix}
| \\
v \\
| \\
\end{bmatrix}
=
\begin{bmatrix}
r_1 \cdot v \\
r_2 \cdot v
\end{bmatrix}
$$
Naturally, a vector can only be multiplied by a matrix if the number of rows in the vector equals the number of columns in the matrix.
\problem{}
Compute the following:
$$
\begin{bmatrix}
1 & 2 \\
3 & 4 \\
5 & 6
\end{bmatrix}
\begin{bmatrix}
5 \\ 3
\end{bmatrix}
$$
\vfill
\problem{}
Say you multiply a size-$m$ vector $v$ by an $m \times n$ matrix $A$. \\
What is the size of your result $Av$?
\vfill
\pagebreak
\definition{}
We can also multiply a matrix by a matrix:
$$
AB =
\begin{bmatrix}
1 & 2 \\
3 & 4
\end{bmatrix}
\begin{bmatrix}
10 & 20 \\
100 & 200
\end{bmatrix}
=
\begin{bmatrix}
210 & 420 \\
430 & 860
\end{bmatrix}
$$
Note each element of the resulting matrix is dot product of a row of $A$ and a column of $B$:
$$
AB =
\begin{bmatrix}
\text{---} r_1 \text{---} \\
\text{---} r_2 \text{---}
\end{bmatrix}
\begin{bmatrix}
| & | \\
v_1 & v_2 \\
| & | \\
\end{bmatrix}
=
\begin{bmatrix}
r_1 \cdot v_1 & r_1 \cdot v_2 \\
r_2 \cdot v_1 & r_2 \cdot v_2 \\
\end{bmatrix}
$$
\begin{center}
\begin{tikzpicture}
\begin{scope}[layer = nodes]
\matrix[
matrix of math nodes,
left delimiter={[},
right delimiter={]}
] (A) at (0, 0){
1 & 2 \\
3 & 4 \\
};
\matrix[
matrix of math nodes,
left delimiter={[},
right delimiter={]}
] (B) at (2, 0) {
10 & 20 \\
100 & 200 \\
};
\node at (3.25, 0) {$=$};
\matrix[
matrix of math nodes,
left delimiter={[},
right delimiter={]}
] (C) at (4.5, 0) {
210 & 420 \\
430 & 860 \\
};
\end{scope}
\draw[rounded corners,fill=black!30!white,draw=none] ([xshift=-2mm,yshift=2mm]A-1-1) rectangle ([xshift=2mm,yshift=-2mm]A-1-2) {};
\draw[rounded corners,fill=black!30!white,draw=none] ([xshift=-3mm,yshift=2mm]B-1-1) rectangle ([xshift=3mm,yshift=-2mm]B-2-1) {};
\draw[rounded corners,fill=black!30!white,draw=none] ([xshift=-4mm,yshift=2mm]C-1-1) rectangle ([xshift=4mm,yshift=-2mm]C-1-1) {};
\draw[rounded corners] ([xshift=-2mm,yshift=2mm]A-2-1) rectangle ([xshift=2mm,yshift=-2mm]A-2-2) {};
\draw[rounded corners] ([xshift=-3mm,yshift=2mm]B-1-2) rectangle ([xshift=3mm,yshift=-2mm]B-2-2) {};
\draw[rounded corners] ([xshift=-4mm,yshift=2mm]C-2-2) rectangle ([xshift=4mm,yshift=-2mm]C-2-2) {};
\end{tikzpicture}
\end{center}
\problem{}
Compute the following matrix product. \\
$$
\begin{bmatrix}
1 & 2 \\
3 & 4 \\
5 & 6
\end{bmatrix}
\begin{bmatrix}
9 & 8 & 7 \\
6 & 5 & 4
\end{bmatrix}
$$
\vfill
\problem{}
Compute the following matrix product or explain why you can't.
$$
\begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6
\end{bmatrix}
\begin{bmatrix}
10 & 20 \\
30 & 40
\end{bmatrix}
$$
\vfill
\problem{}
If $A$ is an $m \times n$ matrix and $B$ is a $p \times q$ matrix, when does the product $AB$ exist?
\vfill
\pagebreak
\problem{}
Is matrix multiplication commutative? \\
\note{Does $AB = BA$ for all $A, B$? \\ You only need one counterexample to show this is false.}
\vfill
\definition{}
Say we have a matrix $A$. The matrix $A^T$, pronounced \say{A-transpose}, is created by turning rows of $A$ into columns, and columns into rows:
$$
\begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6
\end{bmatrix} ^ T
=
\begin{bmatrix}
1 & 4 \\
2 & 5 \\
3 & 6
\end{bmatrix}
$$
\problem{}
Compute the following:
\hfill
$
\begin{bmatrix}
a & b \\
c & d
\end{bmatrix} ^ T
$\hfill
$
\begin{bmatrix}
1 \\
3 \\
3 \\
7 \\
\end{bmatrix} ^ T
$\hfill
$
\begin{bmatrix}
1 & 2 & 4 & 8 \\
\end{bmatrix} ^ T
$
\hfill~
\vfill
\pagebreak
The \say{transpose} operator is often used to write column vectors in a compact way. \\
Vertical arrays don't look good in horizontal text.
\problem{}
Consider the vectors $a = [1, 4, 3]^T$ and $b = [9, 1, 4]^T$ \\
\begin{itemize}
\item Compute the dot product $a \cdot b$.
\item Can you redefine the dot product using matrix multiplication?
\end{itemize}
\note{As you may have noticed, a vector is a special case of a matrix.}
\vfill
\problem{}
A \textit{column vector} is an $m \times 1$ matrix. \\
A \textit{row vector} is a $1 \times m$ matrix. \\
We usually use column vectors. Why? \\
\hint{How does vector-matrix multiplication work?}
\vfill
\pagebreak