% DEFINE some information that will be populated throughout the course notes.
\def \coursename {Linear Algebra}
\def \coursecode {MATH 2221}
\def \courseterm {Winter 2017}
\def \instructorname {Nathan Johnston}
% END DEFINITIONS


% IMPORT the course note formatting and templates
\input{course_notes_template}
% END IMPORT
	
	
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setcounter{chapter}{3} % Set to one less than the week number
\chapter{Linear Transformations}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

{\large This week we will learn about:

\begin{itemize}
	\item Understanding linear transformations geometrically,
	\item The standard matrix of a linear transformation, and
	\item Composition of linear transformations.
\end{itemize}\bigskip\bigskip

\noindent Extra reading and watching:
\begin{itemize}
	\item Section 1.4 in the textbook
	\item Lecture videos \href{https://www.youtube.com/watch?v=HZCFVf5YH7g&list=PLOAf1ViVP13jmawPabxnAa00YFIetVqbd&index=13}{13}, \href{https://www.youtube.com/watch?v=V8Ph36zHsLM&list=PLOAf1ViVP13jmawPabxnAa00YFIetVqbd&index=14}{14}, \href{https://www.youtube.com/watch?v=hI5k4h8d0HI&list=PLOAf1ViVP13jmawPabxnAa00YFIetVqbd&index=15}{15}, and \href{https://www.youtube.com/watch?v=7Dw0jhDoF18&list=PLOAf1ViVP13jmawPabxnAa00YFIetVqbd&index=16}{16} on YouTube
	\item \href{https://en.wikipedia.org/wiki/Linear_map}{Linear map} at Wikipedia
\end{itemize}\bigskip\bigskip

\noindent Extra textbook problems:
\begin{itemize}
	\item[$\star$] 1.4.1, 1.4.4, 1.4.5(a,b,e,f)
	\item[$\star \, \star$] 1.4.2, 1.4.3, 1.4.6, 1.4.7(a,b), 1.4.8, 1.4.14--1.4.16
	\item[$\star\star\star$] 1.4.18, 1.4.22, 1.4.23
	\item[$\skull$] 1.4.19, 1.4.20
\end{itemize}}


\newpage


\section*{Linear Transformations}

The final main ingredient of linear algebra, after vectors and matrices, are linear transformations: functions that act on vectors and that do not ``mess up'' vector addition and scalar multiplication:

\begin{definition}[Linear Transformations]\label{defn:linear_transform}
	A \textbf{linear transformation} is a function $T : \R^n \rightarrow \R^m$ that satisfies the following two properties:
	\begin{enumerate}[label=\alph*)]
		\item $T(\v + \w) = T(\v) + T(\w)$ for all vectors $\v,\w \in \R^n$, and
		
		\item $T(c\v) = cT(\v)$ for all vectors $\v \in \R^n$ and all scalars $c \in \R$.
	\end{enumerate}
\end{definition}

% Clarify that these are functions; just a special type of function.
% Can be thought of as sending vectors to vectors or as multivariable functions

Before looking at specific examples of linear transformations, let's think geometrically about what they do to $\R^n$:

\horlines{8}
% Square grid on R^2 gets mapped to parallelogram grid with vectors in the same boxes.
% Start by drawing e1 and e2 on left half, then T(e1) and T(e2) on right half, then build grid from there. Or just insert an image.
% Make a special note that 0 has to stay at 0.

Another way of thinking about this: linear transformations are exactly the functions that preserve linear combinations:

\horlines{3}
% T(c_1v_1 + ... + c_nv_n) = c_1T(v_1) + ... + c_nT(v_n) for all c_i,v_i


\newpage


\exx[22]{Which of the following functions are linear transformations?}
% v -> Av. Is linear. Prove (easy enough).
% Give an example of a linear function like T(v1,v2) = (v1-v2,v1+v2). Draw picture showing where e1 and e2 go. Draw grid. PROVE that this is linear.
% Not linear: one that multiplies v1 and v2. One that has sin, cos, ln, squares, etc. Prove that a condition is violated for one of these functions, but then just state it for the others.


\newpage


Recall that every vector $\v = (v_1,v_2,\ldots,v_n) \in \R^n$ can be written in the form

\horlines{1}
% $\v = v_1\e_1 + v_2\e_2 + \cdots + v_n\e_n$ (where e_1,...,e_n are standard basis vectors)

\noindent By using the fact that linear transformations preserve linear combinations, we see that

\horlines{1}
% T(\v) = T(v_1\e_1 + v_2\e_2 + \cdots + v_n\e_n) = v_1T(\e_1) + v_2T(\e_2) + \cdots + v_nT(\e_n).

\noindent But this is exactly what we said before: if $\v \in \R^2$ extends a distance of $v_1$ in the direction of $\e_1$ and a distance of $v_2$ in the direction of $\e_2$, then $T(\v)$ extends the same amounts in the directions of $T(\e_1)$ and $T(\e_2)$, respectively. \\

This also tells us one of the most important facts to know about linear transformations:

\horlines{5}
% They are completely determined by the vectors T(\e_1), T(\e_2), \ldots, T(\e_n): if we know what T does to the standard basis vectors, then we know everything about T.

\exx[6]{Suppose $T : \R^2 \rightarrow \R^2$ is a linear transformation for which $T(\e_1) = (1,1)$ and $T(\e_2) = (-1,1)$. Compute $T(2,3)$ and then find a general formula for $T(v_1,v_2)$}
% (2,3) = 2\e_1 + 3\e_2$, so T(2,3) = T(2\e_1+3\e_2) = 2T(\e_1) + 3T(\e_2) = 2(1,1) + 3(-1,1) = (-1,5).
% We can mimic the computation from before to get a general formula: (v_1,v_2) = v_1\e_1 + v_2\e_2, so T(v_1,v_2) = T(v_1\e_1 + v_2\e_2) = v_1T(\e_1) + v_2T(\e_2) = v_1(1,1) + v_2(-1,1) = (v_1-v_2,v_1+v_2).


\newpage


One of the earlier examples showed that if $A \in \M_{m,n}$ is a matrix, then the function $T : \R^m \rightarrow \R^n$ defined by $T(\v) = A\v$ is a linear transformation. Amazingly, the converse is also true: \emph{every} linear transformation can be written as matrix multiplication.

\begin{theorem}[Standard Matrix of a Linear Transformation]\label{thm:linear_transform_represent}
	A function $T : \R^n \rightarrow \R^m$ is a linear transformation if and only if there exists a matrix $[T] \in \M_{m,n}$ such that
	\[
		T(\v) = [T]\v \quad \text{for all} \quad \v \in \R^n.
	\]
	Furthermore, the unique matrix $[T]$ with this property is called the \textbf{standard matrix} of $T$, and it is\\[0.3cm]
	\[
		{}% [T] \defeq \big[ \ T(\e_1) \ {\color{gray}|} \ T(\e_2) \ {\color{gray}|} \ \cdots \ {\color{gray}|} \ T(\e_n) \ \big].
	\]
\end{theorem}

% Make a general note that the proof of this theorem uses many of the ideas we will use repeatedly throughout this course. This is an extremely important theorem. It gives a geometric interpretation to matrices, just like arrows give a geometric interpretation to vectors.

\begin{proof}
	We already proved the ``if'' direction, so we just need to prove the ``only if'' direction. That is, we want to prove that if $T$ is a linear transformation, then $T(\v) = [T]\v$, where the matrix $[T]$ is as defined in the theorem.
	
	\horlines{11}\vspace*{-1.4cm}
	% Also have to prove that no other matrix has this property.
	% To see that $[T]\v = T(\v)$, we use the block matrix multiplication techniques that we learned earlier:
	% [T]\v = [ T(\e_1) \ | \ T(\e_2) \ | \ \cdots \ | \ T(\e_n) ][v_1 \\ v_2 \\ \vdots \\ v_n] = v_1T(\e_1) + v_2T(\e_2) + \cdots + v_nT(\e_n) = T(v_1\e_1 + v_2\e_2 + \cdots + v_n\e_n) = T(\v).
	% To verify that [T] is unique, suppose that $A \in \M_{m,n}$ is any matrix such that $T(\v) = A\v$ for all $\v \in \R^n$. Then $T(\v) = [T]\v$ and $T(\v) = A\v$, so $[T]\v = A\v$ for all $\v \in \R^n$. It follows from (Assignment #2) that $A = [T]$. In other words, $[T]$ is the only matrix satisfying $T(\v) = [T]\v$, which completes the proof.
\end{proof}


\newpage


\exx[17]{Find the standard matrix of the following linear transformations:}
% Just give some random examples of T : R^2 -> R^2 or T : R^2 -> R^3. Does not matter what the coefficients are. Just stick them in a matrix.
% Note that coefficients in the lin transforms end up being read row-wise in the matrix.


\section*{A Catalog of Linear Transformations}

To get more comfortable with the relationship between linear transformations and matrices, let's find the standard matrices of a few linear transformations that come up fairly frequently.


\newpage


\exx[5]{The zero and identity transformations.}
% The two simplest linear transformations that exist are the \textbf{zero transformation} $O : \R^n \rightarrow \R^m$, defined by $O(\v) = \0$ for all $\v \in \R^n$, and the \textbf{identity transformation} $I : \R^n \rightarrow \R^n$, defined by $I(\v) = \v$ for all $\v \in \R^n$. It is perhaps not surprising that the standard matrix of these transformations are the zero matrix and the identity matrix, respectively. To verify this claim, just notice that if $O \in \M_{m,n}$ and $I \in \M_n$ are the zero matrix and the identity matrix, then $O\v = \0$ and $I\v = \v$ for all $\v \in \R^n$ too. Standard matrices are unique.


\exx[9]{Diagonal transformations/matrices.}
% The next simplest type of linear transformation $T : \R^n \rightarrow \R^n$ is one that does not change the direction of the standard basis vectors, but just stretches them by certain (possibly different) amounts (DRAW PICTURE). That is, transformations for which there exist scalars $c_1,c_2,\ldots,c_n \in \R^n$ such that $T(v_1,v_2,\ldots,v_n) = (c_1v_1,c_2v_2,\ldots,c_nv_n)$.
% Standard matrix has columns c_1e_2, c_2e_2, etc, which is the diagonal matrix with c_1, c_2, ..., c_n down the diagonal.

\exx[4]{Projection onto the $x$-axis.}
% Function that sends (v1,v2) to (v1,0). DRAW PICTURE.
% Can easily check that this has standard matrix [1,0;0,0] and is thus linear.


\newpage


\exx[13]{Projection onto a line, $P_{\u} : \R^n \rightarrow \R^n$.}
% More generally, project onto the line in the direction of a unit vector u. Draw picture like Figure 1.18 in the textbook.
% Given any vector $\v$, we can draw a right-angled triangle with $\v$ as the hypotenuse and one of its legs on the line in the direction of $\u$. Then the projection onto this line is the function $P_\u$ that sends $\v$ to this leg of the triangle.
% Not clear apriori that this is linear. But we can explicitly compute P_u(v). $P_\u(\v)$ points a distance of $\|\v\|\cos(\theta)$ in the direction of the unit vector $\u$, so P_u(v) = \|\v\|\cos(\theta)\u$.
% Then recall that cos(theta) = u\cdot v/(\|u\|\|v\|) and \|u\| = 1, so P_u(v) = \|v\|((u\cdot v) / \|v\|)u = (u\cdot v)u = (uu^T)v (last step uses the fact that u \cdot v = u^Tv).
% Thus P_u is linear and has standard matrix uu^T.

\exx[6]{Find the standard matrix of the linear transformation that projects $\R^3$ onto the line in the direction of the vector...}
% First, divide u by its length to get a unit vector: u = (1,2,3) / sqrt(14). Then the standard matrix of $P_{\u}$ is [P_\u] = \u\u^T = [1 \\ 2 \\ 3][1 & 2 & 3]/14 = \frac{1}{14}\begin{bmatrix}1 & 2 & 3 \\ 2 & 4 & 6 \\ 3 & 6 & 9\end{bmatrix}.

%\exx[4]{Reflection in the $x$-axis.}
%% Sends (x,y) to (x,-y) (DRAW PICTURE). Notice that the matrix [1 0;0 -1] has the same effect, so it is linear and this is its standard matrix.
%
%\exx[8]{Reflection through a line, $F_{\u} : \R^n \rightarrow \R^n$.}
%% More generally, reflect through the line in the direction of a unit vector u. Draw picture like Figure 1.19 in the textbook.
%% Note that F_{\u}(\v) = \v + 2(P_{\u}(\v) - \v), as shown in the picture. Simplifying and plugging in the standard matrix of P_u shows the standard matrix of F_u is I + 2uu^T - 2I = 2uu^T - I.
%
%\exx[5]{Find the standard matrix of the linear transformation that reflects $\R^3$ through the line in the direction of the vector $(1,1,1)$.}
%% First, divide u by its length to get a unit vector: u = (1,1,1) / sqrt(3). Then the standard matrix of $F_{\u}$ is [F_\u] = 2\u\u^T - I = \frac{1}{3}\begin{bmatrix}-1 & 2 & 2 \\ 2 & -1 & 2 \\ 2 & 2 & -1\end{bmatrix}.


\newpage


\exx[9]{Rotation counter-clockwise around the origin by $90^\circ$ ($\pi/2$ radians).}
% Since the input and output are orthogonal, (x,y) gets mapped to some multiple of (-y,x), as noted in week 2. Since length is not changed, we see that it is mapped to exactly (-y,x). A matrix that implements this transformation is [0 -1; 1 0], so this rotation is linear and its standard matrix is [0, -1; 1, 0].
% Draw picture.


\exx[10]{Rotation $R^\theta : \R^2 \rightarrow \R^2$ counter-clockwise around the origin by an angle of $\theta$.}
% Note that projection and reflection formulas work in R^n, but we only look at rotations in R^2.
% Draw picture like Figure 1.21 in the textbook, noting where the standard basis vectors go. We skip over the proof that R_theta is indeed linear, but its standard matrix is obtained by sticking R_theta(e1) and R_theta(e2) as column into a matrix. After drawing the picture, we get its standard matrix as [cos(theta), -sin(theta);sin(theta), cos(theta)].


\newpage


\exx[9]{What vector is obtained if we rotate $\v = (1,3)$ by $\pi/4$ radians counterclockwise?}
% Standard matrix is [R_{\pi/4}] = \frac{1}{\sqrt{2}}\begin{bmatrix}1 & -1 \\ 1 & 1\end{bmatrix} (need special triangle to compute sin and cos of pi/4). Thus R(v) = [R]v = [-\sqrt{2},  2\sqrt{2}]. Draw as a sanity check.


\section*{Composing Linear Transformations}

If $T : \mathbb{R}^n \rightarrow \mathbb{R}^m$ and $S : \mathbb{R}^m \rightarrow \mathbb{R}^p$ are linear transformations, then we can consider the function defined by first applying $T$ to a vector, and then applying $S$. This function is called the \textbf{composition} of $T$ and $S$, and is denoted by $S \circ T$.

\horlines{4}
% Draw toy picture with three boxes: Rn, Rm, and Rp. T going from first to second, S from second to third, S \circ T from first to third

% Note to be careful: compositions are read right-to-left.

Formally, the composition $S \circ T$ is defined by $(S \circ T)(\mathbf{v}) = S(T(\mathbf{v}))$ for all vectors $\mathbf{v} \in \mathbb{R}^n$. It turns out that $S \circ T$ is a linear transformation whenever $S$ and $T$ are linear transformations themselves, as shown by the next theorem.


\newpage


\begin{theorem}[Composition of Linear Transformations]\label{thm:linear_transform_represent}
	Suppose $T : \R^n \rightarrow \R^m$ and $S : \R^m \rightarrow \R^p$ are linear transformations with standard matrices $[T] \in \M_{m,n}$ and $[S] \in \M_{p,m}$, respectively. Then $S \circ T : \R^n \rightarrow \R^p$ is a linear transformation, and its standard matrix is $[S \circ T] = [S][T]$.
\end{theorem}

\begin{proof}
	Let $\v \in \R^n$ and compute $(S\circ T)(\v)$:
	
	\horlines{4}\vspace*{-1.3cm}
	% (S \circ T)(v) = S(T(v)) = S([T]v) = [S]([T]v) = ([S][T])v.
	% Thus S \circ T is a matrix transformation (and is thus linear) and has standard matrix [S][T], as claimed.
\end{proof}

The previous theorem shows us that matrix multiplication tells us how the composition of linear transformations behaves. In fact, this is exactly why matrix multiplication is defined the way it is.

\exx[10]{What vector is obtained if we rotate $\v = (4,2)$ $45^\circ$ counter-clockwise around the origin and then project it onto the line $y = 2x$?}
% Unit vector is (1,2)/sqrt(5). Final answer is 14/(5sqrt(2)) * [1, 2].


\newpage


\exx[8]{Find the standard matrix of the linear transformation $T$ that projects $\R^2$ onto the line $y = (4/3)x$ and then stretches it in the $x$-direction by a factor of $2$ and in the $y$-direction by a factor of $3$.}
% Final answer is [18 24;36 48]/25

\exx[11]{Derive the angle-sum formulas for $\sin$ and $\cos$.}
% Argue geometrically that $R_{theta+phi} = R_{\theta} \circ R_{\phi}$. Compute the standard matrix of each of them. Comparing entries of both standard matrices gives
% \sin(\theta+\phi) = \sin(\theta)\cos(\phi)+\cos(\theta)\sin(\phi) and
% \cos(\theta+\phi) = \cos(\theta)\cos(\phi)-\sin(\theta)\sin(\phi)
\end{document}