\documentclass[10pt]{article}

\usepackage{systeme}

\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
%\usepackage{palatino}
\usepackage{setdeck}

\usepackage{xcolor}
\usepackage{tcolorbox}

%\usepackage[textheight=8.5in, margin=1.6in]{geometry}
\usepackage[total={6in,8in}]{geometry}

\usepackage{tikz}
\usetikzlibrary{cd}
\tikzset{
      labr/.style={anchor=north, rotate=90, inner sep=.7mm}
    }
\tikzset{
      labl/.style={anchor=south, rotate=90, inner sep=.7mm}
    }

%\usepackage{pgfplots}
\tikzstyle{ball} = [circle,shading=ball, ball color=black,
    minimum size=1mm,inner sep=1.3pt]
%\usetikzlibrary{arrows.meta}
%\tikzset{>={Latex[length=2mm,width=1.5mm]}}

%\usepackage{graphicx}

\usepackage{needspace}  % <-- to prevent bad pagebreak over environment titles
% Use:  \Needspace{3\baselineskip} before opening an environment

\usepackage[shortlabels]{enumitem}
\setlist[enumerate]{leftmargin=*,label=(\alph*)}

%\usepackage[colorlinks=true,citecolor=black,linkcolor=black,urlcolor=blue]{hyperref}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\sn}{\mathfrak{S}}
\newcommand{\PP}{\mathbb{P}}
\newcommand{\ve}{\varepsilon}
\newcommand{\ips}[2]{\langle{#1}, {#2}\rangle}
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\Span}{\mathrm{Span}}
\DeclareMathOperator{\rk}{\mathrm{rank}}
\DeclareMathOperator{\rspace}{\mathrm{rowspace}}
\DeclareMathOperator{\cspace}{\mathrm{colspace}}
\DeclareMathOperator{\trace}{\mathrm{tr}}
\DeclareMathOperator{\im}{\mathrm{im}}
\DeclareMathOperator{\Sym}{\mathrm{Sym}}
\DeclareMathOperator{\Hom}{\mathrm{Hom}}
\DeclareMathOperator{\diag}{\mathrm{diag}}
\DeclareMathOperator{\glb}{\mathrm{glb}}
\DeclareMathOperator{\lub}{\mathrm{lub}}

\parskip = 0.05in
\parindent = 0.0in

%\pagestyle{empty}

\allowdisplaybreaks

\begin{document}
\centerline{Math 201 lecture for Monday, Week 10}
\bigskip

\centerline{\textbf{Diagonalization algorithm}}  
\bigskip

Recall from last time: an \emph{eigenvector} for a linear transformation
$f\colon V\to V$ is a \emph{nonzero} vector~$v\in V$ such that
\[
  f(v)=\lambda v
\]
for some~$\lambda\in F$.  In that case,~$\lambda$ is called an \emph{eigenvalue}
for~$f$.  
\medskip

\textbf{Definition.} Let~$V$ be an~$n$-dimensional vector space.  A linear
mapping~$f\colon V\to V$ is \emph{diagonalizable} if there exists an
ordered basis~$\alpha$ of~$V$ such
that~$[f]_{\alpha}^{\alpha}=\diag(\lambda_1,\dots,\lambda_n)$.
A matrix~$A\in M_{n\times n}(F)$ is \emph{diagonalizable} if its
corresponding linear mapping~$f_A$ is diagonalizable.
\medskip

\textbf{Proposition.} A linear mapping~$f\colon V\to V$ is diagonalizable if
and only if~$V$ has a basis consisting solely of eigenvectors for~$f$.
\begin{proof}
  Let~$\alpha$ be any ordered basis. Then~$[f]_{\alpha}^{\alpha}$
  is diagonal if and only if, for each~$j=1,\dots,n$, the~$j$-th column of
  $[f]_{\alpha}^{\alpha}$ has a single non-zero entry, in the~$j$-th row.
  That~$j$-th column is determined by
  \[
    f(v_j)=0\cdot v_1+\cdots+0\cdot v_{j-1}+\lambda_j\cdot v_j+0\cdot
    v_{j+1}+\dots+0\cdot v_n,
  \]
  for some scalar~$\lambda_j$.
  However, the above condition is equivalent
  to~$f(v_j)=\lambda_jv_j$ for~$j=1,\dots,n$, i.e., to~$\alpha$ being a basis of
  eigenvectors.
\end{proof}

\textbf{Example.} Not all linear transformations of a vector space to itself are
diagonalizable.  For instance, consider the linear
transformation~$f\colon\R^2\to\R^2$ that is rotation of the plane
by~$90^{\circ}$, having matrix
\[
  A=
  \left(\begin{array}{cc}
      0&-1\\
      1&0
  \end{array} \right).
\]
\begin{center}
  \begin{tikzpicture}
    \draw[->] (-2,0)--(2,0);
    \draw[->] (0,-0.5)--(0,2);
    \draw[-latex] (1,0) arc (0:90:1);
    \draw[-latex] (0,1) arc (90:180:1);
    \node[ball] at (1,0) {};
    \node[ball] at (0,1) {};
    \node[ball] at (-1,0) {};
    \node at (1,-0.3) {$(1,0)$};
    \node at (0.7,1.3) {$(0,1)$};
    \node at (-1,-0.3) {$(-1,0)$};
  \end{tikzpicture}
\end{center}
There is no point~$0\neq v\in\R^2$ such that~$Av=\lambda v$ for some~$\lambda$.
(The matrix is diagonalizable over~$\C$, though.  Can you find two eigenvectors?
  Don't get your hopes up, though---there are matrices that are not diagonalizable
over~$\C$.)
\medskip

Suppose~$f\colon F^n\to F^n$ is a linear transformation, and let~$A$ be the
matrix corresponding to~$f$, i.e., the matrix whose~$j$-th column is~$f(e_j)$
for all~$j$ (i.e., the matrix for~$f$ with respect to the standard basis
for~$F^n$). Suppose we can find a basis~$\alpha=\langle v_1,\dots,v_n\rangle$ of
eigenvectors for~$f$ with corresponding, not necessarily distinct,
eigenvalues~$\lambda_1,\dots,\lambda_n$.  Let~$P$ be the matrix with
columns~$v_1,\dots,v_n$.  Then, as we saw last time,
\[
  P^{-1}AP=\diag(\lambda_1,\dots,\lambda_n).
\]
\medskip

\textbf{Definition.} Two~$n\times n$ matrices~$A$ and~$B$ over~$F$ are \emph{similar}
or \emph{conjugate} if there exists an invertible matrix~$P$ such
that~$A=P^{-1}BP$.
\medskip

\textbf{Exercise.} The reader should verify that similarity is an equivalence
relation.
\medskip

\textbf{Remark.} Let~$f\colon V\to V$ be a linear transformation of a
finite-dimensional vector space, and let~$\alpha$ and~$\beta$ be two ordered
bases for~$V$.  Then we saw earlier in the semester that the matrices~$A :=
[f]_{\alpha}^{\alpha}$ and~$B:=[f]_{\beta}^{\beta}$ are conjugate, i.e., the
matrices for~$f$ with respect to any two bases for~$V$ are conjugate. The
converse is also true: every matrix conjugate to~$A$ is the matrix
representing~$f$ with respect to some basis.
\medskip


\textbf{Finding eigenvectors and eigenvalues.} Let~$A\in M_{n\times n}(F)$
with corresponding linear function
\begin{align*}
  f_A\colon F^n&\to F^n\\
  v&\mapsto Av.
\end{align*}
As mentioned last time, the following argument is of central importance in the
story of eigenvectors and eigenvalues: We are looking for nonzero~$v\in F^n$ and
any~$\lambda\in F$ such that~$Av=\lambda v$.  We have
\[
  Av=\lambda v\quad\Leftrightarrow\quad (A-\lambda I_n)v=0
  \quad\Leftrightarrow\quad v\in\ker(A-\lambda v).
\]
This says that: 
\begin{quote}
  $\lambda\in F$ is an eigenvalue for~$A$ if and only
  if~$\ker(A-\lambda I_n)\neq\left\{ 0 \right\}$.
\end{quote}
So we would like to determine those~$\lambda$ for which the kernel of~$A-\lambda
I_n$ is nontrivial.  The following is key:
\[
  \ker(A-\lambda I_n)\neq\left\{ 0 \right\}
  \quad\Leftrightarrow\quad
  \rk(A-\lambda I_n)<n
  \quad\Leftrightarrow\quad
  \det(A-\lambda I_n)=0.
\]
\medskip

\textbf{Definition.} The \emph{characteristic polynomial} of~$A$ is
\[
  p_A(x):=\det(A-x I_n).
\]
\medskip

We have just seen that
\begin{quote} 
$\lambda\in F$ is an eigenvalue for~$A$ if and only if it is a zero of the characteristic
polynomial for~$A$, i.e., if and only if~$p_A(\lambda)=0$.  
\end{quote}
\medskip

\textbf{Example.} Let
\[
  A=
  \left(\begin{array}{rrr}
      2&-7&3\\
      0&-5&3\\
      0&0&2
  \end{array} \right).
\]
The characteristic polynomial of~$A$ is
\begin{align*}
  p_A(t)
  &=
  \det\left( 
  \left(\begin{array}{rrr}
      2&-7&3\\
      0&-5&3\\
      0&0&2
  \end{array} \right)
  -x
  \left(\begin{array}{ccc}
      1&0&0\\
      0&1&0\\
      0&0&1
\end{array} \right) \right)\\[12pt]
  &=
  \det\left(
  \left(\begin{array}{rrr}
      2&-7&3\\
      0&-5&3\\
      0&0&2
  \end{array} \right)
  -
  \left(\begin{array}{ccc}
      x&0&0\\
      0&x&0\\
      0&0&x
\end{array} \right)  \right)\\[12pt]
  &=
  \det
  \left(\begin{array}{rrr}
      2-x&-7&3\\
      0&-5-x&3\\
      0&0&2-x
  \end{array} \right)\\[12pt]
  &=(2-x)(-5-x)(2-x)\\[10pt]
  &=-(x-2)^2(x+5).
\end{align*}
Thus,~$p_A(x)=0$ if and only if~$x\in\{2,-5\}$.  So the eigenvalues of~$A$
are~$2$ (with {\em multiplicity}~$2$), and~$-5$.
\medskip

Recall that our goal is to diagonalize~$A$ by finding a basis of eigenvectors.
That's not always possible, but we can try.  The \textbf{first step} is to compute the
zeros of the characteristic polynomial,~$p_A(x)$.  This tells us the eigenvalues
for~$A$.  We then need to find the eigenvectors to go along with these
eigenvalues.  Recall that nonzero~$v\in F^n$ is an eigenvector for~$A$ with
eigenvalue~$\lambda$ if and only~$v\in\ker(A-\lambda I_n)$. 
\medskip

\textbf{Definition.} Let~$\lambda$ be an eigenvalue of the~$n\times n$
matrix~$A$ over~$F$.  Then the \emph{eigenspace for~$\lambda$} is
\[
  E_{\lambda}:=E(A)_{\lambda}:=\left\{ v\in F^n:Av=\lambda
  v\right\}=\ker(A-\lambda I_n v).
\]
\medskip

The eigenspace, being the kernel of a matrix, is a linear subspace of~$F^n$.

The \textbf{second step} in trying to diagonalize~$A$ is to compute a basis for each
eigenspace~$E_{\lambda}$.  
\medskip

\textbf{Example.} We have seen that the eigenvalues for
\[
  A=
  \left(\begin{array}{rrr}
      2&-7&3\\
      0&-5&3\\
      0&0&2
  \end{array} \right).
\]
are~$2$ (with multiplicity~$2$) and~$-5$.  Let's compute the corresponding
eigenspaces in the case~$F=\R$.
\medskip

\fbox{$E_2$}
\begin{align*}
  A-2 I_3
  &=
  \left(\begin{array}{rrr}
      2&-7&3\\
      0&-5&3\\
      0&0&2
  \end{array} \right)
  -
  \left(\begin{array}{ccc}
      2&0&0\\0&2&0\\0&0&2
  \end{array} \right)
\\[12pt]
  &=
  \left(\begin{array}{rrr}
      0&-7&3\\
      0&-7&3\\
      0&0&0
  \end{array} \right)
\\[12pt]
&\longrightarrow
\left(\begin{array}{ccc}
      0&1&-3/7\\
      0&0&0\\
      0&0&0
\end{array} \right).
\end{align*}
The first and third variables are free.
Hence,
\[
  \ker(A-2I_3)=\left\{ (x,\tfrac{3}{7}z,z):x,z\in\R \right\}.
\]
For a basis we could take $\left\{ (1,0,0),(0,\tfrac{3}{7},1) \right\}$, or easier, 
$\left\{ (1,0,0),(0,3,7) \right\}$.
\medskip

\fbox{$E_{-5}$}
\begin{align*}
  A-(-5) I_3
  &=
  \left(\begin{array}{rrr}
      2&-7&3\\
      0&-5&3\\
      0&0&2
  \end{array} \right)
  +
  \left(\begin{array}{ccc}
      5&0&0\\0&5&0\\0&0&5
  \end{array} \right)
\\[12pt]
  &=
  \left(\begin{array}{rrr}
      7&-7&3\\
      0&0&3\\
      0&0&7
  \end{array} \right)
\\[12pt]
&\longrightarrow
  \left(\begin{array}{rrr}
      1&-1&0\\
      0&0&1\\
      0&0&0
  \end{array} \right).
\end{align*}
Hence,
\[
  \ker(A+5I_3)=\left\{ (y,y,0):y\in\R \right\}.
\]
For a basis we could take~$(1,1,0)$.

Thus, we have found three eigenvectors~$(1,0,0)$, $(0,3,7)$, and~$(1,1,0)$.  It turns out that
eigenvectors for distinct eigenvalues are always linearly independent (we'll see
this later).  Hence, we have found a basis of eigenvectors. Thus,~$A$ is
diagonalizable, and if we use these eigenvectors as the columns for a matrix:
\[
P=
\left(\begin{array}{rrr}
    1&0&1\\
    0&3&1\\
    0&7&0
\end{array} \right),
\]
then one may check that
\[
  P^{-1}AP=\diag(2,2,-5).
\]

\textbf{Example.} Now consider a matrix that is just slightly different
from~$A$: 
\[
  B=
  \left(\begin{array}{rrr}
      2&1&3\\
      0&-5&3\\
      0&0&2
  \end{array} \right).
\]
The characteristic polynomial for~$A$ and for~$B$ are the same:
\[
  \det\left( B-xI_3
  \right)=
  \det
  \left(\begin{array}{rrr}
      2-x&1&3\\
      0&-5-x&3\\
      0&0&2-x
  \end{array} \right)
  =-(x-2)^2(x+5).
\]
Thus,~$A$ and~$B$ have the same eigenvalues.  Let's compute the eigenspaces
for~$B$ over~$\R$.
\medskip

\fbox{$E_2$}
\begin{align*}
  B-2 I_3
  &=
  \left(\begin{array}{rrr}
      2&1&3\\
      0&-5&3\\
      0&0&2
  \end{array} \right)
  -
  \left(\begin{array}{ccc}
      2&0&0\\0&2&0\\0&0&2
  \end{array} \right)
\\[12pt]
  &=
  \left(\begin{array}{rrr}
      0&1&3\\
      0&-7&3\\
      0&0&0
  \end{array} \right)
\\[12pt]
&\longrightarrow
\left(\begin{array}{ccc}
      0&1&0\\
      0&0&1\\
      0&0&0
\end{array} \right).
\end{align*}
Thus,~$\ker(B-2I_3)$ has basis~$\left\{ (1,0,0) \right\}$.  It is only
one-dimensional.  Recall that~$\ker(A-2I_3)$ was two-dimensional.  This is a
crucial difference.  
\medskip

\fbox{$E_{-5}$}
\begin{align*}
  A-(-5) I_3
  &=
  \left(\begin{array}{rrr}
      2&1&3\\
      0&-5&3\\
      0&0&2
  \end{array} \right)
  +
  \left(\begin{array}{ccc}
      5&0&0\\0&5&0\\0&0&5
  \end{array} \right)
\\[12pt]
  &=
  \left(\begin{array}{rrr}
      7&1&3\\
      0&0&3\\
      0&0&7
  \end{array} \right)
\\[12pt]
&\longrightarrow
  \left(\begin{array}{rrr}
      1&1/7&0\\
      0&0&1\\
      0&0&0
  \end{array} \right).
\end{align*}
Hence,
\[
  \ker(A-3I_3)=\left\{ (y,-y/7,0):y\in\R \right\}.
\]
For a basis we could take~$(-7,1,0)$.

Our calculations prove that, at most, we can find two linearly independent
vectors that are eigenvectors for~$B$.  Thus, there is no basis for~$\R^3$
consisting of eigenvectors for~$B$. Therefore,~$B$ is not diagonalizable.
\newpage 


\begin{tcolorbox}[colback=white]
\textbf{Diagonalizing Algorithm} 
Let~$A\in M_{n\times n}(F)$.
\begin{enumerate}
  \item Find the eigenvalues of~$A$ as the zeros of its characteristic
    polynomial,
    \[
      p_A(x)=\det(A-x I_n).
    \]
  \item For each eigenvalue~$\lambda$, compute a basis for the
    eigenspace~$E_{\lambda}=\ker{A-\lambda I_n}$.
  \item\label{10mon3} \textbf{The matrix~$A$ is diagonalizable if and only if of
    the total number of eigenvectors in the bases found in the previous step
  is~$n$.  i.e., if and only if the sum of the dimensions of the eigenspaces
is~$n$.} If so, the union of these vectors is a basis for~$F^n$. Create a
matrix~$P$ whose columns are these vectors. Then~$P^{-1}AP=D$, where~$D$ is a
diagonal matrix with the eigenvalues along the diagonal, and we get a
corresponding commutative diagram: \begin{center}
\begin{tikzpicture}
  \node at (0,0) {
\begin{tikzcd}
  F^n\arrow[d,swap, "P^{-1}","\sim" labr]\arrow[r,"A"]&
  F^n\arrow[d,"P^{-1}","\sim" labl]\\
  F^n\arrow[r,"D"]&F^n.
\end{tikzcd}
};
\end{tikzpicture}
\end{center}
The matrix~$P^{-1}$, considered as a linear function, takes coordinates with respect to the basis
of eigenvalues.
\end{enumerate}
\end{tcolorbox}
\bigskip


\textbf{Remark.} An~$n\times n$ matrix~$A$ is diagonalizable if and only if it
has~$n$ linearly independent eigenvectors.  Step~\ref{10mon3} of the
diagonalization algorithm depends on a fact we will prove next time:
eigenvectors with distinct eigenvalues are linearly independent.  (We compute
bases for each eigenspace, and of course the elements in a basis are linearly
independent.  But when we combine the bases for all of the eigenspaces, why is
the resulting set independent?)
\end{document}  
