\documentclass{article}
\usepackage{ifxetex}
\ifxetex
\usepackage{fontspec}
\else
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\fi
\title{Lab 1 Report}
\author{Isaac Shaeffer and Satori Kubo}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{listings}
\begin{document}
\maketitle
\begin{enumerate}
\item
\begin{enumerate}
\item The show() function renders uses formated text or Latex to render output.
\item Changing the ring from QQ to RR forces the data in the matrix $A$ to be treated as floating point values. Changing the ring from QQ to RDF forces the data to take on a single decimal point.
\item $ B \sim \left[\begin{array}{rrr} 1 & 0 & \frac{21}{2} \\ 0 & 1 & -\frac{1}{2} \end{array} \right] $
\item The command \verb|I4 = identity_matrix(4)| assigns the \( \mathbb{R}^4 \) identity matrix to the variable \verb|I4|. Changing the number 4 to some other integer, say n, assigns the identity matrix for $ \mathbb{R}^n $ to a variable.
\end{enumerate}
\item
\begin{enumerate}
\item Assuming we are using the matrices $A$ and $B$ defined in part 1, we can use matrix addition or subtraction if we restrict the number of columns of $B$ to match the number columns in $A$ with the command \verb|matrix_from_columns([0,1])|. Note that in the argument \verb|[0,1]|, the number 0 is referring to the first column of B and 1 is referring to the second column. The following code
\begin{lstlisting}[language=Python]
A = matrix(QQ,[[1, 2],[3,4]])
B = matrix(QQ, [[0, 2, -1],[1, 1, 10]])
C = A + B.matrix_from_columns([0,1])
show(C)
\end{lstlisting}
generates the output $\left[\begin{array}{rr} 1 & 4 \\4 & 5 \end{array}\right].$
\item The command \verb|B.transpose()| creates a new matrix $B^T$ that uses of the rows of B as its columns. That is
$$
B \sim \left[\begin{array}{rrr}
0 & 2 & -1 \\
1 & 1 & 10
\end{array}\right]
\text{ and } B^T \sim
\left[\begin{array}{rr}
0 & 1 \\
2 & 1 \\
-1 & 10
\end{array}\right].
$$
\item
\begin{enumerate}
\item Does $(AB)^T = A^TB^T$ for any two matrices $A, B$ where $AB$ is defined?
No, since there exist two matrices $A, B$ where $AB$ is defined but $(AB)^T \neq A^TB^T$. \par
For example, let $A = \left(\begin{array}{rr}1 & 1 \\1 & 1\end{array}\right) \text{ and } B = \left[\begin{array}{rr}-2 & -3 \\0 & 7\end{array}\right]$. Then
$$
(AB)^T = \left[\begin{array}{rr}
-2 & -2 \\
4 & 4
\end{array}\right]
\text{ and } A^TB^T =
\left[\begin{array}{rr}
-5 & 7 \\
-5 & 7
\end{array}\right].
$$
Thus $(AB)^T \neq A^TB^T$.
\item Does $(A+B)^T =A^T +B^T$ for any two matrices A,B where $A+B$ is defined? \par
Yes, since by Theorem 2.3 part b., we have $(A+B)^T =A^T +B^T$ for any two matrices $A,B$ where $A+B$ is defined.
\item Does $(cA)^T = cA^T$ for any matrix A and scalar c? \par
Yes, since by Theorem 2.3 part c., we have $(rA)^T = rA^T$ for a matrix A and any scalar r.
\end{enumerate}
\item
\begin{enumerate}
\item What happens when you use the inverse command on matrix A from lab task 1? Does it match the formula for a $2 \times 2$ matrix inverses given in section 2.1? \par
Using \verb|A.inverse()| gives us the the matrix $\left[\begin{array}{rr} -2 & 1 \\\ \frac{3}{2} & -\frac{1}{2} \end{array}\right]$. The inverse formula from section 2.1 gives us the same matrix. So the formula matches what we get from the inverse command.
\item What happens when you use the determinant command on matrix A from lab task 1? Does it match the formula for a $2 \times 2$ matrix determinant given in exam 1? \par
Using \verb|A.det()| returns $-2$. Since $det(A) = 4\cdot 1 - 2\cdot 3 = -2$, \verb|A.det()| matches the formula for a $2 \times 2$ matrix given in exam 1.
\item What happens when you use the inverse command on matrix B from lab task 1? Explain what’s happening here? \par
Using \verb|B.inverse()| returns the error message $$\texttt{ArithmeticError: self must be a square matrix}.$$ This error occurs because inverse matrices are only defined for square matrices and $B$ is not a square matrix.
\item Define a $2 \times 2$ matrix whose determinant is zero. What happens when you try to determine the inverse of this matrix in Sage? \par
We have $det(A) = 0$ when $D = \displaystyle \left[\begin{array}{rr} 6 & 3 \\ 4 & 2 \end{array} \right]$. Using \verb|D.inverse()| returns the error $$\texttt{ZeroDivisionError: Matrix is singular}$$
\item Does $(A^T)^{-1} = (A^{-1})^T$, where A is the matrix from lab task 1? In your report, write down the lines of code you used to determine if this is true or not. \par
The relationship $(A^T)^{-1} = (A^{-1})^T$ is true for the matrix $A$ since
\[
(A^T)^{-1} =
\left[\begin{array}{rr}
-2 & \frac{3}{2} \\
1 & -\frac{1}{2}
\end{array}\right]
\text{ and }
(A^{-1})^T =
\left[\begin{array}{rr}
-2 & \frac{3}{2} \\
1 & -\frac{1}{2}
\end{array}\right]
\]
We used the following code in Sage:
\begin{lstlisting}[language=Python]
A = matrix(QQ,[[1, 2],[3,4]])
(A.transpose()).inverse()
(A.inverse()).transpose()
show("$(A^T)^{-1}$ =", (A.transpose()).inverse())
show("$(A^{-1})^T$ =", (A.inverse()).transpose())
\end{lstlisting}
\end{enumerate}
\end{enumerate}
\item Let's explore the geometry of linear transformation $T: \mathbb{R}^2 \to \mathbb{R}^2 $. Use the code below to define $ M = \displaystyle \left[\begin{array}{rr} -1 & 0 \\ 0 & 1 \end{array} \right] $ and the column vectors, $ \vec{e_1} $ and $ \vec{e_2} $ of the $ 2 \times 2 $ identity matrix.
\begin{enumerate}
\item Describe the output of this code. What are the blue arrows compared to the purple arrows? \par
The blue arrows are the vectors, $\vec{e_1}=\verb|[1,0]|$, $\vec{e_2}=\verb|[0,1]|$, $\vec{u_1}=\verb|[1,2]|$, and $\vec{u_2}=\verb|[-2,-1]|$. The purple arrows are the transformed vectors, $M*\vec{e_1}=\verb|[-1,0]|$, $M*\vec{e_2}=\verb|[0,1]|$, $M*\vec{u_1}=\verb|[-1,2]|$, and $M*\vec{u_2}=\verb|[2,-1]|$.
\item Consider $M : \mathbb{R}^2 \to \mathbb{R}^2$ as a linear transformation. Describe how $M$ transforms an input vector $\vec{v}$. \par
The geometry of the transformation is a reflection through the ${x_2}$-axis.
\item Change matrix $M$ in the code to $M1=\displaystyle \left[\begin{array}{rr} 0 & 1 \\ 1 & 0 \end{array} \right]$ and describe how $M1$ transforms vectors in $\mathbb{R}^2$. \par
The geometry of the transformation is a reflection through the line ${x_2}$ = ${x_1}$. \par
\item Change matrix $M$ in the code to $M2=\displaystyle \left[\begin{array}{rr} 0 & -1 \\ -1 & 0 \end{array} \right]$ and describe how $M2$ transforms vectors in $\mathbb{R}^2$. \par
The geometry of the transformation is a reflection through the line ${x_2}$ = $-{x_1}$. \par
\item Change matrix $M$ in the code to $M3=\displaystyle \left[\begin{array}{rr} 1 & 0 \\ 0 & 0 \end{array} \right]$ and describe how $M3$ transforms vectors in $\mathbb{R}^2$. \par
The geometry of the transformation is a projection onto the ${x_1}$-axis. \par
\item Change matrix $M$ in the code to $M4=\displaystyle \left[\begin{array}{rr} 0 & 2 \\ 4 & 0 \end{array} \right]$ and describe how $M4$ transforms vectors in $\mathbb{R}^2$. \par
The geometry of the transformation is a reflection through the line ${x_2}$ = ${x_1}$ and stretching horizontally and vertically by factors of 2 and 4, respectively. \par
\item Change the first two lines in the code to the following. Then change the value of $\theta$ (theta) to see what happens to the vectors. Describe what the transformation $R=\displaystyle \left[\begin{array}{rr} \cos(\theta) & \sin(\theta) \\ -\sin(\theta) & \cos(\theta) \end{array} \right]$ does to vectors in $\mathbb{R}^2$. \par
The geometry of the transformation is a clockwise rotation around the origin by $\theta$ radians.
\item Compute $M2*R$ and describe the transformation it does to vectors in $\mathbb{R}^2$. Then do the same for $R*M2$. \par
The matrix $M2*R = \left[\begin{array}{rr} \sin\left(\theta\right) & -\cos\left(\theta\right) \\ -\cos\left(\theta\right) & -\sin\left(\theta\right) \end{array}\right]$. \par
This transformation rotates a vector clockwise $\theta$ radians about the origin and then reflects the rotated vector through the line $x_2 = -x_1$.
The matrix $R*M2 = \left[\begin{array}{rr} -\sin\left(\theta\right) & -\cos\left(\theta\right) \\ -\cos\left(\theta\right) & \sin\left(\theta\right) \end{array}\right]$. \par
This transformation first reflects a vector through the line $x_2 = -x_1$ and then rotates the reflected vector clockwise $\theta$ radians about the origin.
\item For $\theta=\frac{\pi}{2}$, compute $R^2=R*R$ and describe the transformation it does to vectors in $\mathbb{R}^2$. \par
$R^2=R*R= \left[\begin{array}{rr} 0 & 1 \\ -1 & 0 \end{array}\right] \left[\begin{array}{rr} 0 & 1 \\ -1 & 0 \end{array}\right] = \left [\begin {array}{rr} -1 & 0 \\ 0 & -1 \end {array} \right]$. Therefore, the geometry of the transformation is a reflection through the origin. \par
\end{enumerate}
\item
\begin{enumerate}
\item Let $I_2 = \left[ \vec{e}_1 \text{ } \vec{e}_2\right] = \left[\begin{array}{rr}1 & 0 \\ 0 & 1\end{array}\right]$ , let $T: \mathbb{R}^2 \to \mathbb{R}^2 \text{ be the transformation } T\left( \left[ \begin{array}{r} a \\ b \end{array} \right] \right) = \left[ \begin{array}{r} a - b \\ a+ b \end{array} \right]$ and let $A$ be the standard matrix for T. \par
First, we will show that $T$ is linear. Thus,
\[
\begin{split}
T\left( \left[ \begin{array}{r} a \\ 0 \end{array} \right] + \left[ \begin{array}{r} 0 \\ b \end{array} \right]\right) &= T\left( \left[ \begin{array}{r} a \\ b \end{array} \right] \right) \\
&= \left[ \begin{array}{r} a - b \\ a + b \end{array} \right] \\
&= \left[ \begin{array}{r} a - 0 \\ a + 0 \end{array} \right] + \left[ \begin{array}{r} 0 - b \\ 0 + b \end{array} \right] \\
&= T\left(\left[ \begin{array}{r} a \\ 0 \end{array} \right] \right) + T\left(\left[ \begin{array}{r} 0 \\ b \end{array} \right] \right). \\
\end{split}
\]
Now we will find the standard matrix of T. Thus
\[
\begin{split}
T(\vec{e}_1 )
&= T\left(\left[ \begin{array}{r} 1 \\ 0 \end{array} \right] \right)
= \left[ \begin{array}{r} 1 - 0 \\ 1 + 0 \end{array} \right]
= \left[ \begin{array}{r} 1 \\ 1 \end{array} \right] \text{ and }\\
T(\vec{e}_2)
&= T\left(\left[ \begin{array}{r} 0 \\ 1 \end{array} \right] \right)
= \left[ \begin{array}{r} 0 - 1 \\ 0 + 1 \end{array} \right]
= \left[ \begin{array}{r} -1 \\ 1 \end{array} \right].
\end{split}
\]
So it follows that \[
A
= \left[ T(\vec{e_1}) \text{ } T(\vec{e_2}) \right]
= \left[ \begin{array}{rr} 1 & -1 \\ 1 & 1 \end{array} \right].
\]
\item Evaluating the left side changes the standard matrix to $\left(\begin{array}{rr}1 & 1 \\ -1 & 1\end{array}\right)$.
\end{enumerate}
\item Let $J: \mathbb{R}^2 \to \mathbb{R}^4$ map
$\left[ \begin{array}{r} x_1 \\ x_2 \end{array} \right] = \left[ \begin{array}{cc} 2x_1 -5x_1 \\ 0 \\ x_1 + 4x_2 \\ x_2 \end{array} \right].$ \par
Then the columns of the standard matrix for J are
\[
\begin{split}
&J \left( \left[ \begin{array}{r} 1 \\ 0 \end{array} \right] \right) = \left[ \begin{array}{cc} 2\cdot1 -5\cdot0 \\ 0 \\ 1 + 4\cdot0 \\ 0 \end{array} \right] = \left[ \begin{array}{cc} 2 \\ 0 \\ 1 \\ 0 \end{array} \right] \text{ and } \\
&J \left( \left[ \begin{array}{r} 0 \\1 \end{array} \right] \right) = \left[ \begin{array}{cc} 2\cdot0 -5\cdot1 \\ 0 \\ 0 + 4\cdot1 \\ 1 \end{array} \right] = \left[ \begin{array}{rr} -5 \\ 0 \\ 4 \\ 2 \end{array} \right].
\end{split}
\]
Therefore, the standard matrix for J is $ \left[ \begin{array}{rr} 2 & -5 \\ 0 & 0 \\ 1 & 4 \\ 0 & 1 \end{array}\right]$.
\end{enumerate}
\end{document}