\documentclass[11pt]{article}
\usepackage{precalc}
\usepackage[usenames]{color}
% \usepackage{showkeys}
\newcommand{\cb}{\color{Blue}}
\newcommand{\cd}{\color{Red}}
\newcommand{\cp}{\color{Purple}}
\begin{document}
\assigntitle{18}{Matrices}
The \term{complex numbers} you learned about in previous weeks are a
particular generalization of the concept of ``number;'' so, too, are
\term{matrices}. You can think of a matrix as a sort of
``multi-dimensional number.''
Now, why might this be useful? Matrices, as it turns out, have a ton
of applications; we'll look at a few next week. For example, matrices
can be used to represent certain sorts of transformations in two or
three dimensions, so they are used extensively in computer
graphics. (In fact, it turns out that the graphics card inside your
computer is essentially just a glorified piece of hardware for doing
lots of matrix multiplications, very quickly, in parallel!) Matrices
can also be used to represent systems of linear equations, or sets of
transition probabilities in multi-state systems, or pretty much
anything having to do with sets of data having multiple dimensions.
Before we get there, however, we'll spend this week learning some
matrix basics.
Be sure to look at the \LaTeX\ notes in the last section of this
assignment for some tips on typing up your solutions!
\section{The basics}
\label{sec:basics}
\begin{defn}{matrix}
A \term{matrix} is a rectangular array of numbers. We say that a
matrix $M$ is an $m \times n$ matrix when it has $m$ rows and $n$
columns, and call $m$ and $n$ the \term{dimensions} of $M$.
\end{defn}
For example, this is a $2 \times 3$
matrix: \begin{equation} \label{eq:matrix-a} A =
\begin{pmatrix}
2 & 3 & 5 \\
4 & 1 & -9
\end{pmatrix}
\end{equation}
A matrix is \term{square} if it has the same number of rows and
columns.
\topic{row, column}
Repeat this phrase to yourself: ``row, column.'' We always refer to
the \emph{rows} of a matrix first, and the \emph{columns} second.
(This is completely arbitrary, of course. It \emph{could} have been
the other way around.\footnote{But it isn't.}) This applies to matrix
dimensions (the dimensions $m \times n$ mean $m$ \emph{rows} and $n$
\emph{columns}) and also, as you will see, to remembering how matrix
multiplication works.
\topic{subscript notation}
We can use subscript notation to refer to particular entries in a
matrix: the notation $M_{ij}$ refers to the entry of matrix $M$ in row
$i$ and column $j$.
\begin{problem}
Let $A$ be the matrix in \pref{eq:matrix-a}. What is $A_{13}$?
\end{problem}
\begin{defn}{transpose}
The \term{transpose} of a matrix $M$, denoted $M^T$, is the matrix
$M$ with the rows and columns switched. That is, $(M^T)_{ij} = M_{ji}$.
\end{defn}
You can think of the transpose as flipping the matrix along a diagonal
line going from the top left to bottom right. For example,
\[ A^T = \begin{pmatrix} 2 & 4 \\ 3 & 1 \\ 5 & -9 \end{pmatrix}. \]
\section{Matrix arithmetic}
\label{sec:arithmetic}
\topic{matrices as generalized numbers}
That's right, we can do arithmetic with matrices---in other words, we
can treat them as a particular kind of ``generalized number.'' Why
might we want to do this? There are many good reasons, some of which
you'll see later on in the assignment. For now, let's see how matrix
arithmetic works.
\subsection{Matrix addition}
\label{sec:addition}
\topic{easy peasy}
Matrix addition is very simple, and works in exactly the way you might
guess. We can only add two matrices with the same dimensions; but
assuming we do have two matrices $A$ and $B$ with the same dimensions,
we can add them simply by adding corresponding entries. For example,
\[
\begin{pmatrix} 2 & 3 \\ 4 & -1 \end{pmatrix}
+
\begin{pmatrix} 5 & 0 \\ -6 & 3 \end{pmatrix}
=
\begin{pmatrix} 2+5 & 3+0 \\ 4 - 6 & -1 + 3 \end{pmatrix}
=
\begin{pmatrix} 7 & 3 \\ -2 & 2 \end{pmatrix}
\]
\begin{problem} \label{prob:addition}
Suppose we have the following matrices:
\[
A = \begin{pmatrix} 2 & 3 & 5 \\ 4 & 1 & -9 \end{pmatrix} \quad
B = \begin{pmatrix} 4 & 6 \\ 2 & 1 \\ 0 & 0 \end{pmatrix} \quad
C = \begin{pmatrix} 1 & 1/2 & 1/3 \\ 1/2 & 1/3 & 1/4 \end{pmatrix}
\] Evaluate each of the following.
\begin{subproblems}
\item $A + C$
\item $B + C$
\item $B + A^T$
\item $A + B^T + C$
\end{subproblems}
\end{problem}
\begin{problem}
For two matrices $X$ and $Y$, is $X + Y$ always the same as $Y + X$?
Explain why, or give a counterexample.
\end{problem}
\subsection{Matrix multiplication}
\label{sec:multiplication}
Multiplying two matrices, on the other hand, is \emph{not} quite as
straightforward as addition!
\topic{say what?}
To multiply two matrices, the number of \emph{columns} of the first
matrix must be the same as the number of \emph{rows} of the second
matrix. Let's say that we have two matrices, $X$, which is $m \times
k$, and $Y$, which is $k \times n$. Then their product, denoted $XY$,
will be an $m \times n$ matrix. Here is how to determine the elements
of the matrix product $XY$: to get $(XY)_{ij}$ (the entry in the $i$th
row and $j$th column), take the $i$th row of $X$ and the $j$th column
of $Y$, multiply their corresponding elements, and add the results.
Now, maybe you are confused by that description; I wouldn't blame
you. But it's really not so bad once you get the hang of it; let's go
through an example.
\topic{matrix multiplication example}
Suppose we have the matrices
\[
X = \begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{pmatrix}
\qquad Y = \begin{pmatrix} 0 & -2 & 1 & 9 \\ 5 & 4 & 2 & 6 \\ 1 & -3
& 0 & -1 \end{pmatrix}.
\]
$X$ has dimensions $2 \times 3$, and $Y$ has dimensions $3 \times
4$. Since the number of columns of $X$ ($3$) equals
the number of rows of $Y$ (also $3$), we can multiply them, and the
result will be a $2 \times 4$ matrix. Think to yourself: ``$2
\times 3$ and $3 \times 4$---the $3$'s match up, so they disappear,
leaving $2 \times 4$.''
Now, to determine the entry in the first row and first column of the
product $XY$, we look at the first row of $X$ and the first column of
$Y$, here shown highlighted in blue and red:
\[
X = \begin{pmatrix} \cb 1 & \cb 2 & \cb 3
\\ 4 & 5 & 6 \end{pmatrix} \qquad Y = \begin{pmatrix} \cd 0 & -2 & 1 & 9
\\ \cd 5 & 4 & 2 & 6 \\ \cd 1 & -3 & 0 & -1 \end{pmatrix}.
\]
We now take these two lists of three numbers, multiply them
element-by-element, and add the results: \[ {\cb 1} \cdot
{\cd 0} + {\cb 2} \cdot {\cd 5} + {\cb 3} \cdot {\cd 1} = {\cp 0} +
{\cp 10} + {\cp 3} = 13. \]
So far, we know that the matrix product $XY$ looks like this: \[ XY =
\begin{pmatrix}
13 & {\cd ?} & ? & ? \\
? & ? & ? & ?
\end{pmatrix} \]
Now let's compute $(XY)_{12}$ (highlighted in red above). Since we
are trying to compute the entry of $XY$ in the \emph{first row} and
\emph{second column}, we take the
\emph{first row} of $X$, and the \emph{second column} of $Y$:
\[
X = \begin{pmatrix} \cb 1 & \cb 2 & \cb 3
\\ 4 & 5 & 6 \end{pmatrix} \qquad Y = \begin{pmatrix} 0 & \cd -2 & 1 & 9
\\ 5 & \cd 4 & 2 & 6 \\ 1 & \cd -3 & 0 & -1 \end{pmatrix}.
\]
Multiplying them pairwise and then adding yields \[ {\cb 1} \cdot
{\cd -2} + {\cb 2} \cdot {\cd 4} + {\cb 3} \cdot {\cd -3} = {\cp -2} +
{\cp 8} + {\cp -9} = -3. \] Now $XY$ looks like
\[ XY = \begin{pmatrix}
13 & -3 & ? & ? \\
? & ? & ? & ?
\end{pmatrix}. \]
Getting the hang of it?
\begin{problem}
Go back and read the paragraph at the beginning of
\pref{sec:multiplication}. Does it make sense now?
\end{problem}
\begin{problem}
Finish computing the matrix product $XY$. (You don't have to show
all the work, just the final answer.)
\end{problem}
\begin{problem}
Use the matrices $A$, $B$, and $C$ defined in \pref{prob:addition},
and also \[ D = \begin{pmatrix} 2 & 4 \\ -1 & 1 \end{pmatrix}
\qquad E = \begin{pmatrix} 1 & 3 \\ 2 & 2 \end{pmatrix}. \] Compute
each of the following:
\begin{subproblems}
\item $AB$
\item $AC$
\item $BD$
\item $DE$
\item $ED$
\end{subproblems}
\end{problem}
\begin{problem} \label{prob:mult-non-comm}
Suppose $X$ and $Y$ are square matrices. Is $XY$ always the same as
$YX$? Explain why, or give a counterexample.
\end{problem}
\topic{matrix multiplication is not commutative}
What you found in \pref{prob:mult-non-comm}---that matrix
multiplication is not \term{commutative}---is one of the biggest ways
that matrices are different from any other sort of ``number.'' With
real numbers, you are used to being able to switch around the order of
things being multiplied, but you have to be very careful: you cannot
do this with matrices!
\topic{matrix multiplication is associative} It turns out, however,
that matrix multiplication is \term{associative}: for any matrices
$X$, $Y$, and $Z$, as long as they have dimensions that match up
properly, it is always true that $(XY)Z = X(YZ)$. That is, when doing
more than one matrix multiplication, it doesn't matter which
multiplication we do first, as long as we keep them in the right
order. This means that we can write things like $ABCDE$ instead of
$((AB)C)(DE)$ or $A(B(C(DE)))$ or $((AB)(CD))E$ since they are all the
same.
\begin{problem}
Can you find a $2 \times 2$ matrix $I$, which when multiplied by any
other $2 \times 2$ matrix $X$, yields $X$? That is, $IX = X$ for
any $2 \times 2$ matrix $X$. $I$ is called the $2 \times 2$
\term{identity matrix} (sometimes also written $I_2$).
\end{problem}
\begin{problem}
What is the $3 \times 3$ identity matrix, $I_3$? In general, what
does the $n \times n$ identity matrix $I_n$ look like?
\end{problem}
\begin{problem}
There is no such thing as a $2 \times 3$ identity matrix. Why not?
\end{problem}
\section{Inverses and the determinant}
\label{sec:det-inv}
\begin{problem} \label{prob:inverse-matrices}
Multiply the following two matrices:
\[A = \begin{pmatrix} 2 & 3 \\ 3 & 5 \end{pmatrix} \qquad
B = \begin{pmatrix} 5 & -3 \\ -3 & 2 \end{pmatrix}
\]
What do you get? Why is this interesting?
\end{problem}
\begin{defn}{inverse}
The \term{inverse} of a square matrix $A$, written $A^{-1}$, is a
matrix which when multiplied by $A$ results in the identity matrix: $A
A^{-1} = A^{-1}A = I$.
\end{defn}
\begin{problem}
As it turns out, not all matrices have an inverse. But this should
not be too surprising---why not? (Hint: think about the real
numbers.)
\end{problem}
\topic{solving matrix equations}
Matrices which have an inverse are called \term{invertible}, and
matrices which do \emph{not} have an inverse are called
\term{singular}. Why do we care whether a matrix is invertible?
Well, remember what you do in algebra to solve an equation like $3x =
12$: you multiply both sides by $1/3$, the \emph{inverse} of $3$. In
the same way, inverting matrices allows us to solve \emph{matrix
equations} like $AX = Y$ (where $A$, $X$, and $Y$ are all
matrices)---if $A$ is invertible, we can multiply both sides of the
equation by $A^{-1}$ to get $X = A^{-1}Y$.
So, we would like a way to be able to tell whether a matrix has an
inverse, and, if it does, to be able to compute it. Interestingly,
both of these require something called the \term{determinant}.
\begin{defn}{determinant}
The \term{determinant} of a matrix $M$, denoted $\det M$, is a
number computed from $M$ in a particular way (to be described
later), which has the special property that $M$ is invertible
\emph{if and only if} $\det M \neq 0$.
\end{defn}
That is, to check whether a matrix $M$ has an inverse, just compute
its determinant---if the determinant is zero, $M$ is singular (that
is, not invertible); it the determinant is anything other than zero,
$M$ is invertible. Nifty, huh? Oh, except I haven't told you
how to compute the determinant yet!
\topic{$2 \times 2$ determinant}
This week, I'll only show you how to compute the determinant of a $2
\times 2$ matrix.\footnote{If you're extra good, next week I might
show you how to compute the determinants of larger ones\dots}
Suppose we have the matrix \[ X = \begin{pmatrix} a & b \\ c &
d \end{pmatrix}. \] Then the determinant of $X$ (which we can
abbreviate using vertical bars instead of parentheses around the
matrix elements) can be computed
by \[ \det X = \begin{vmatrix} a & b \\ c & d \end{vmatrix} = ad - bc. \]
\begin{problem} \label{prob:det-A}
What is the determinant of matrix $A$ from \pref{prob:inverse-matrices}?
\end{problem}
\begin{problem} \label{prob:matrs-det-5}
Write down a $2 \times 2$ matrix with determinant $5$.
\end{problem}
\topic{$2 \times 2$ inverses}
Now let's see how to compute the inverse of a $2 \times 2$ matrix.
If \[ A = \begin{pmatrix} a & b \\ c & d \end{pmatrix}, \] then \[
A^{-1} = \frac{1}{\det A} \begin{pmatrix} d & -b \\ -c &
a \end{pmatrix}. \]
\begin{problem} \label{prob:inverses}
For each of the following matrices, compute its inverse, or state
that it has none.
\begin{subproblems}
\item $\begin{pmatrix} 2 & 3 \\ 3 & 5 \end{pmatrix}$
\item $\begin{pmatrix} 1 & 1 \\ 1 & 1 \end{pmatrix}$
\item $\begin{pmatrix} 5 & 7 \\ 2 & -3 \end{pmatrix}$
\item $\begin{pmatrix} 3 & 0 \\ 0 & 3 \end{pmatrix}$
\item $\begin{pmatrix} \cos \theta & -\sin \theta \\ \sin \theta &
\cos \theta \end{pmatrix}$ (\emph{Hint: remember the
Pythagorean Identity!})
\end{subproblems}
\end{problem}
\begin{problem}
Solve this matrix equation for $X$: \[ \begin{pmatrix} 1 & 2 \\ 3 &
4 \end{pmatrix} X = \begin{pmatrix} 7 \\ -2 \end{pmatrix}. \]
\end{problem}
\section{\LaTeX\ notes}
\label{sec:latex-notes}
\begin{itemize}
\item To typeset the size of a matrix (for example, ``$m \times n$''),
you should write something like \verb|$m \times n$|; do not just
write an `x', like \verb|$m x n$|. Do these look the same to you: $m
\times n$, $m x n$? I didn't think so.
\item You can typeset a matrix using the \verb|pmatrix| environment.
Elements within a row are separated by \verb|&|; rows are separated
by \verb|\\|. For example, you could typeset the following matrix: \[
\begin{pmatrix}
4 & 5 & x + 2 \\
9 & 0 & \pi \\
6 + 5i & \sqrt{3} & -2
\end{pmatrix}
\]
with this code:
\begin{verbatim}
\[
\begin{pmatrix}
4 & 5 & x + 2 \\
9 & 0 & \pi \\
6 + 5i & \sqrt{3} & -2
\end{pmatrix}
\]
\end{verbatim}
To get a matrix with vertical bars instead of parentheses, you can use
\verb|vmatrix| instead of \verb|pmatrix|. (There is also
\verb|bmatrix| to make a matrix with square brackets, but you won't
need that.)
\item When using matrix subscript notation, remember to use curly
braces around the subscripts; otherwise, only the
first digit will be included in the subscript. For example,
\verb|M_12| is wrong, since it produces this output: $M_12$.
Correct would be \verb|M_{12}|, which produces $M_{12}$.
\item When typesetting the determinant operator, you should use the
special \LaTeX\ command \verb|\det| instead of just writing
\verb|det| (just like you use \verb|\cos| instead of \verb|cos|).
See the difference: $\det M$ (correct), $det M$ (incorrect).
\item If anything is still not clear, take a look at the \LaTeX\
source for this assignment!
\end{itemize}
\end{document}