diff --git a/Advanced/Linear Algebra 101/main.tex b/Advanced/Linear Algebra 101/main.tex index ad3d890..4a743e8 100755 --- a/Advanced/Linear Algebra 101/main.tex +++ b/Advanced/Linear Algebra 101/main.tex @@ -9,7 +9,16 @@ %\usepackage{lua-visual-debug} \usepackage{tikz-3dplot} -\usetikzlibrary{quotes,angles} +\usetikzlibrary{ + quotes, + angles, + matrix, + decorations.pathreplacing, + calc, + positioning, + fit +} +\input{tikzset} \begin{document} @@ -24,97 +33,10 @@ \input{parts/0 notation} \input{parts/1 vectors} - - \section{Dot Products} - - \definition{} - We can also define the \textit{dot product} of two vectors.\footnotemark{} \\ - The dot product maps two elements of $\mathbb{R}^n$ to one element of $\mathbb{R}$: - - \footnotetext{ - \textbf{Bonus content. Feel free to skip.} - - Formally, we would say that the dot product is a map from $\mathbb{R}^n \times \mathbb{R}^n$ to $\mathbb{R}$. Why is this reasonable? - - \vspace{2mm} - - It's also worth noting that a function $f$ from $X$ to $Y$ can defined as a subset of $X \times Y$, where for all $x \in X$ there exists a unique $y \in Y$ so that $(x, y) \in f$. Try to make sense of this definition. - } - - $$ - a \cdot b = \sum_{i = 1}^n a_ib_i = a_1b_1 + a_2b_2 + ... + a_nb_n - $$ - - \problem{} - Compute $[2, 3, 4, 1] \cdot [2, 4, 10, 12]$ - - \vfill - - \problem{} - Show that the dot product is - \begin{itemize} - \item Commutative - \item Distributive - \item Homogeneic: $x(a \cdot b) = xa \cdot b = a \cdot xb$ - \item Positive definite: $a \cdot a \geq 0$, with equality iff $a = 0$ - \end{itemize} + \input{parts/2 dotprod} + \input{parts/3 matrices} - \vfill - \pagebreak - - - - - \problem{} - Say you have two vectors, $a$ and $b$. Show that $\langle a, b \rangle$ = $||a||~||b||\cos(\alpha)$ \\ - \hint{What is $c$ in terms of $a$ and $b$?} - \hint{The law of cosines is $a^2 + b^2 - 2ab\cos(\alpha) = c^2$} - \hint{The length of $a$ is $||a||$} - - - \begin{center} - \begin{tikzpicture}[scale=1] - - \draw[->] - (0,0) coordinate (o) -- node[above left] {$a$} - (1,2) coordinate (a) - ; - - \draw[->] - (o) -- node[below] {$b$} - (3,0.5) coordinate (b) - ; - - \draw[ - draw = gray, - text = gray, - - - ] (a) -- node[above] {$c$} (b); - - \draw - pic[ - "$\alpha$", - draw = orange, - text = orange, - <->, - angle eccentricity = 1.2, - angle radius = 1cm - ] - { angle = b--o--a } - ; - - \end{tikzpicture} - \end{center} - - \vfill - - \problem{} - If $a$ and $b$ are perpendicular, what must $\langle a, b \rangle$ be? Is the converse true? - - - \vfill - \pagebreak \section{Bonus} diff --git a/Advanced/Linear Algebra 101/parts/2 dotprod.tex b/Advanced/Linear Algebra 101/parts/2 dotprod.tex new file mode 100644 index 0000000..34c9b00 --- /dev/null +++ b/Advanced/Linear Algebra 101/parts/2 dotprod.tex @@ -0,0 +1,90 @@ +\section{Dot Products} + +\definition{} +We can also define the \textit{dot product} of two vectors.\footnotemark{} \\ +The dot product maps two elements of $\mathbb{R}^n$ to one element of $\mathbb{R}$: + +\footnotetext{ + \textbf{Bonus content. Feel free to skip.} + + Formally, we would say that the dot product is a map from $\mathbb{R}^n \times \mathbb{R}^n$ to $\mathbb{R}$. Why is this reasonable? + + \vspace{2mm} + + It's also worth noting that a function $f$ from $X$ to $Y$ can defined as a subset of $X \times Y$, where for all $x \in X$ there exists a unique $y \in Y$ so that $(x, y) \in f$. Try to make sense of this definition. +} + +$$ + a \cdot b = \sum_{i = 1}^n a_ib_i = a_1b_1 + a_2b_2 + ... + a_nb_n +$$ + +\problem{} +Compute $[2, 3, 4, 1] \cdot [2, 4, 10, 12]$ + +\vfill + +\problem{} +Show that the dot product is +\begin{itemize} + \item Commutative + \item Distributive + \item Homogeneic: $x(a \cdot b) = xa \cdot b = a \cdot xb$ + \item Positive definite: $a \cdot a \geq 0$, with equality iff $a = 0$ +\end{itemize} + + +\vfill +\pagebreak + + + + +\problem{} +Say you have two vectors, $a$ and $b$. Show that $\langle a, b \rangle$ = $||a||~||b||\cos(\alpha)$ \\ +\hint{What is $c$ in terms of $a$ and $b$?} +\hint{The law of cosines is $a^2 + b^2 - 2ab\cos(\alpha) = c^2$} +\hint{The length of $a$ is $||a||$} + + +\begin{center} +\begin{tikzpicture}[scale=1] + + \draw[->] + (0,0) coordinate (o) -- node[above left] {$a$} + (1,2) coordinate (a) + ; + + \draw[->] + (o) -- node[below] {$b$} + (3,0.5) coordinate (b) + ; + + \draw[ + draw = gray, + text = gray, + - + ] (a) -- node[above] {$c$} (b); + + \draw + pic[ + "$\alpha$", + draw = orange, + text = orange, + <->, + angle eccentricity = 1.2, + angle radius = 1cm + ] + { angle = b--o--a } + ; + +\end{tikzpicture} +\end{center} + +\vfill + +\problem{} +If $a$ and $b$ are perpendicular, what must $\langle a, b \rangle$ be? Is the converse true? + + +\vfill +\pagebreak \ No newline at end of file diff --git a/Advanced/Linear Algebra 101/parts/3 matrices.tex b/Advanced/Linear Algebra 101/parts/3 matrices.tex new file mode 100644 index 0000000..be611a3 --- /dev/null +++ b/Advanced/Linear Algebra 101/parts/3 matrices.tex @@ -0,0 +1,219 @@ +\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. + +\definition{} +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{---} a_1 \text{---} \\ + \text{---} a_2 \text{---} +\end{bmatrix} +\begin{bmatrix} + | \\ + v \\ + | \\ +\end{bmatrix} += +\begin{bmatrix} + r_1v \\ + r_2v +\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{} +Say you multiply a size-$m$ vector by an $m \times n$ matrix. What is the size of your result? + +\vfill + + +\problem{} +Compute the following: + +$$ +\begin{bmatrix} + 1 & 2 \\ + 3 & 4 \\ + 5 & 6 +\end{bmatrix} +\begin{bmatrix} + 5 \\ 3 +\end{bmatrix} +$$ + +\vfill +\pagebreak + +\definition{} +We 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{---} a_1 \text{---} \\ + \text{---} a_2 \text{---} +\end{bmatrix} +\begin{bmatrix} + | & | \\ + v_1 & v_2 \\ + | & | \\ +\end{bmatrix} += +\begin{bmatrix} + r_1v_1 & r_1v_2 \\ + r_2v_1 & r_2vm_2 \\ +\end{bmatrix} +$$ + +\begin{center} +\begin{tikzpicture}[>=stealth,thick,baseline] + + \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=3mm]A-1-1) rectangle ([xshift=2mm,yshift=-3mm]A-2-1) {}; + + \draw[rounded corners,fill=black!30!white,draw=none] ([xshift=-3mm,yshift=2mm]B-1-1) rectangle ([xshift=3mm,yshift=-2mm]B-1-2) {}; + + \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=3mm]A-1-2) rectangle ([xshift=2mm,yshift=-3mm]A-2-2) {}; + + \draw[rounded corners] ([xshift=-3mm,yshift=2mm]B-2-1) 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{} +Consider the following matrix product. \\ +Compute it 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{} +Look back to \ref{matvec}. \\ +Convince yourself that vectors are matrices. \\ + +Can you multiply a matrix by a vector, as in $vA$? \\ +How does the dot prouduct relate to matrix multiplication? (transpose) + +\vfill +\pagebreak \ No newline at end of file diff --git a/Advanced/Linear Algebra 101/tikzset.tex b/Advanced/Linear Algebra 101/tikzset.tex new file mode 100644 index 0000000..ffbdd51 --- /dev/null +++ b/Advanced/Linear Algebra 101/tikzset.tex @@ -0,0 +1,36 @@ +\usetikzlibrary{arrows.meta} +\usetikzlibrary{shapes.geometric} +\usetikzlibrary{patterns} + +% We put nodes in a separate layer, so we can +% slightly overlap with paths for a perfect fit +\pgfdeclarelayer{nodes} +\pgfdeclarelayer{path} +\pgfsetlayers{main,nodes} + +% Layer settings +\tikzset{ + % Layer hack, lets us write + % later = * in scopes. + layer/.style = { + execute at begin scope={\pgfonlayer{#1}}, + execute at end scope={\endpgfonlayer} + }, + % + % Nodes + main/.style = { + draw, + circle, + fill = white + }, + % + % Paths + path/.style = { + line width = 4mm, + draw = black, + % Lengthen paths so they're + % completely under nodes. + line cap = rect, + opacity = 0.3 + } +} \ No newline at end of file