\documentclass[a4paper]{article}

\usepackage{fancyhdr}
\usepackage{extramarks}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage[plain]{algorithm}
\usepackage{algpseudocode}
\usepackage{enumitem}

\graphicspath{ {./images/} }

\usetikzlibrary{automata,positioning}

%
% Basic Document Settings
%

\topmargin=-0.45in
\evensidemargin=0in
\oddsidemargin=0in
\textwidth=6.5in
\textheight=9.0in
\headsep=0.25in

\linespread{1.1}

\pagestyle{fancy}
\lhead{\hmwkAuthorName}
\chead{\hmwkClass\ : \hmwkTitle}
\rhead{\firstxmark}
\lfoot{\lastxmark}
\cfoot{\thepage}

\renewcommand\headrulewidth{0.4pt}
\renewcommand\footrulewidth{0.4pt}

\setlength\parindent{0pt}

%
% Create Problem Sections
%

\newcommand{\enterProblemHeader}[1]{
    \nobreak\extramarks{}{Question \arabic{#1} continued on next page\ldots}\nobreak{}
    \nobreak\extramarks{Question \arabic{#1} (continued)}{Question \arabic{#1} continued on next page\ldots}\nobreak{}
}

\newcommand{\exitProblemHeader}[1]{
    \nobreak\extramarks{Question \arabic{#1} (continued)}{Question \arabic{#1} continued on next page\ldots}\nobreak{}
    \stepcounter{#1}
    \nobreak\extramarks{Question \arabic{#1}}{}\nobreak{}
}

\setcounter{secnumdepth}{0}
\newcounter{partCounter}
\newcounter{homeworkProblemCounter}
\setcounter{homeworkProblemCounter}{1}
\nobreak\extramarks{Question \arabic{homeworkProblemCounter}}{}\nobreak{}

\newenvironment{homeworkProblem}[1][-1]{
    \ifnum#1>0
        \setcounter{homeworkProblemCounter}{#1}
    \fi
    \section{Question \arabic{homeworkProblemCounter}}
    \setcounter{partCounter}{1}
    \enterProblemHeader{homeworkProblemCounter}
}{
    \exitProblemHeader{homeworkProblemCounter}
}

\newcommand{\hmwkClass}{INF 1004 Mathematics 2}
\newcommand{\hmwkTitle}{Tutorial\ \#7 Solution}
\newcommand{\hmwkAuthorName}{\textbf{Woon Jun Wei}}
\newcommand{\hmwkStudentID}{\textbf{2200624}}

\title{
    \vspace{2in}
    \textmd{\textbf{\hmwkClass \\ \hmwkTitle}}\\
    \vspace{3in}
}

\author{\hmwkAuthorName \\ \hmwkStudentID}
\date{\today}

\renewcommand{\part}[1]{\textbf{\large Part \arabic{partCounter}}\stepcounter{partCounter}\\}

%
% Various Helper Commands
%

% Useful for algorithms
\newcommand{\alg}[1]{\textsc{\bfseries \footnotesize #1}}

% For derivatives
\newcommand{\deriv}[1]{\frac{\mathrm{d}}{\mathrm{d}x} (#1)}

% For partial derivatives
\newcommand{\pderiv}[2]{\frac{\partial}{\partial #1} (#2)}

% Integral dx
\newcommand{\dx}{\mathrm{d}x}

% Alias for the Solution section header
\newcommand{\solution}{\textbf{\large My Solution\\}}
\newcommand{\answer}{\textbf{\large Sample Solutions\\}}

% Probability commands: Expectation, Variance, Covariance, Bias
\newcommand{\E}{\mathrm{E}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}
\newcommand{\Bias}{\mathrm{Bias}}

\begin{document}

\maketitle
\pagebreak

\begin{homeworkProblem}
    Compute the euclidean vector norm for vectors
$$
\begin{bmatrix}
    1,0,2
\end{bmatrix}
,
\begin{bmatrix}
    3,4
\end{bmatrix}
,
\begin{bmatrix}
    -7,2,-4, \sqrt{12}
\end{bmatrix}
$$

\solution

\part

$$\lVert [1,0,2] \rVert_2 = \sqrt{1^2 + 0^2 + 2^2} = \boxed{\sqrt{5}}$$

\part

$$\lVert [3,4] \rVert_2 = \sqrt{3^2 + 4^2} = \sqrt{25} = \boxed{5}$$

\part

$$
\begin{align*}
    \lVert [-7,2,-4, \sqrt{12}] \rVert_2 &= \sqrt{(-7)^2 + 2^2 + (-4)^2 + \sqrt{12}^2} \\
                                         &= \sqrt{49 + 4 + 16 + 12} \\
                                         &= \sqrt{81}\\
                                         &= \boxed{9}
\end{align*}
$$
\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
Compute the corresponding unit length vector for these:
$$
\begin{bmatrix}
    3,4
\end{bmatrix}
,
\begin{bmatrix}
    -1,-2,3
\end{bmatrix}
,
\begin{bmatrix}
    -7,2,-4, \sqrt{12}
\end{bmatrix}
$$

\solution

$$
\lVert v \rVert_2 = 1
$$
$$
v \neq 0 \implies \frac{v}{\lVert v \rVert_2}
$$

\part

$$
\begin{align*}
    \frac{[3,4]}{\lVert [3,4] \rVert_2} &= \frac{[3,4]}{5} \\
                                        &= \frac{1}{5} \begin{bmatrix} 3,4 \end{bmatrix} \\
                                        &= \boxed{\begin{bmatrix} \frac{3}{5}, \frac{4}{5} \end{bmatrix}}
\end{align*}
$$

\part

$$
\begin{align*}
    \frac{[-1,-2,3]}{\lVert [-1,-2,3] \rVert_2} &= \frac{[-1,-2,3]}{\sqrt{1^2 + 4^2 + 9^2}} \\
                                                &= \frac{1}{\sqrt{14}} \begin{bmatrix} -1,-2,3 \end{bmatrix} \\
                                                &= \boxed{\begin{bmatrix} -\frac{1}{\sqrt{14}}, -\frac{2}{\sqrt{14}}, \frac{3}{\sqrt{14}} \end{bmatrix}}
\end{align*}
$$

\part

$$
\begin{align*}
    \frac{[-7,2,-4, \sqrt{12}]}{\lVert [-7,2,-4, \sqrt{12}] \rVert_2} &= \frac{[-7,2,-4, \sqrt{12}]}{\sqrt{(-7)^2 + 2^2 + (-4)^2 + \sqrt{12}^2}} \\
                                                                    &= \frac{1}{\sqrt{81}} \begin{bmatrix} -7,2,-4, \sqrt{12} \end{bmatrix} \\
                                                                    &= \frac{1}{9} \begin{bmatrix} -7,2,-4,\sqrt{12}\end{bmatrix}\\
                                                                    &= \boxed{\begin{bmatrix} -\frac{7}{9}, \frac{2}{9}, -\frac{4}{9}, \frac{\sqrt{12}}{9} \end{bmatrix}}
\end{align*}
$$
\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
    Compute the inner product between these vectors and their angle in degrees:
$$
\begin{bmatrix}
    3,-2,2
\end{bmatrix}
,
\begin{bmatrix}
1,2,2
\end{bmatrix}
$$

Compute the inner product between these vectors and their angle in degrees:
$$
\begin{bmatrix}
1,0,1
\end{bmatrix}
,
\begin{bmatrix}
    2,1,-2
\end{bmatrix}
,
\begin{bmatrix}
    \frac{1}{2\sqrt{2}}
    , -\frac{\sqrt{3}}{2}
    , \frac{1}{2\sqrt{2}}}
\end{bmatrix}
$$

\answer

    $$\frac{u}{\lVert u \rVert_2} \cdot \frac{v}{\lVert v \rVert_2} = \cos(\angle (u,v))$$

\part

$$
\begin{align*}
    \langle [3,-2,2], [1,2,2] \rangle &= 3 \cdot 1 + (-2) \cdot 2 + 2 \cdot 2 \\
                                      &= 3 + (-4) + 4 \\
                                      &= \boxed{3}
\end{align*}
$$

Angle:\\

Let $u$ be $\begin{bmatrix}3,-2,2\end{bmatrix}$ and $v$ be $\begin{bmatrix}1,2,2\end{bmatrix}$\\

$$
\begin{align*}
    \cos(\angle (u,v)) &= \frac{\langle u,v \rangle}{\lVert u \rVert_2 \cdot \lVert v \rVert_2} \\
                       &= \frac{\begin{bmatrix}3,-2,2\end{bmatrix} \cdot \begin{bmatrix}1,2,2\end{bmatrix}}{\lVert \begin{bmatrix}3,-2,2\end{bmatrix} \rVert_2 \cdot \lVert \begin{bmatrix}1,2,2\end{bmatrix} \rVert_2} \\
                       &= \frac{3}{\sqrt{17}\cdot\sqrt{9}} \\
                       &= \frac{3}{\sqrt{153}} \\
                       &= \frac{1}{\sqrt{17}}\\
           \angle (u,v) &= \cos^{-1}(\frac{3}{\sqrt{153}}) \\
                        &= \boxed{75.96^{\circ}} \text{ \textbf{OR}}\\
                        &= 360^{\circ} - 75.96^{\circ}\\
                        &= \boxed{284.04^{\circ}}
\end{align*}
$$

\pagebreak

\part

$$
\begin{align*}
    \langle [1,0,1], [2,1,-2] \rangle &= 1 \cdot 2 + 0 \cdot 1 + 1 \cdot (-2) \\
                                      &= 2 + 0 + (-2) \\
                                      &= \boxed{0}
\end{align*}
$$

Angle:\\

Let $u$ be $\begin{bmatrix}1,0,1\end{bmatrix}$ and $v$ be $\begin{bmatrix}2,1,-2\end{bmatrix}$ and w be $\begin{bmatrix}\frac{1}{2\sqrt{2}}, -\frac{\sqrt{3}}{2}, \frac{1}{2\sqrt{2}}\end{bmatrix}$\\

$$
\begin{align*}
    \cos(\angle (u,v)) &= \frac{\langle u,v \rangle}{\lVert u \rVert_2 \cdot \lVert v \rVert_2} \\ &= \frac{\begin{bmatrix}1,0,1\end{bmatrix} \cdot \begin{bmatrix}2,1,-2\end{bmatrix}}{\lVert \begin{bmatrix}1,0,1\end{bmatrix} \rVert_2 \cdot \lVert \begin{bmatrix}2,1,-2\end{bmatrix} \rVert_2} \\
                       &= \frac{0}{\sqrt{2}\cdot\sqrt{6}} \\
                       &= 0 \\\\
           \angle (u,v) &= \cos^{-1}(0) \\
                        &= \boxed{90^{\circ}} \text{ \textbf{OR}}\\
                        &= 360^{\circ} - 90^{\circ}\\
                        &= \boxed{270^{\circ}}
\end{align*}
$$

\part

$$
\left \langle [1,0,1] \cdot \left[ \frac{1}{2\sqrt{2}}, -\frac{\sqrt{3}}{2}, \frac{1}{2\sqrt{2}} \right] \right \rangle = \frac{1}{\sqrt{2}}
$$\\

$$
\left\lVert \left [\frac{1}{2\sqrt{2}}, -\frac{\sqrt{3}}{2}, \frac{1}{2\sqrt{2}} \right] \right \rVert = \sqrt{\frac{1}{4\cdot 2} + \frac{3}{4} + \frac{1}{4 \cdot 2}} = 1
$$

$$
\begin{align}
\cos \angle(u,w) &= \frac{1}{\sqrt{2}} \cdot\frac{1}{\sqrt{2}}\cdot \frac{1}{1} \\
                 &= \frac{1}{2}\\
\angle(u,w) &= \cos^{-1}(\frac{1}{2}) \\
            &= 60^{\circ} \text{ \textbf{OR}}\\
\angle(u,w) &= 360^{\circ} - 60^{\circ} = 300^{\circ}
\end{align}
$$

\pagebreak

\part

$$
\begin{align}
    [2,1,-2] \cdot \left[\frac{1}{2\sqrt{2}},-\frac{\sqrt{3}}{2},\frac{1}{2\sqrt{2}}\right] &= \frac{1}{2\sqrt{2}} \cdot 2 + \frac{\sqrt{3}}{2} \cdot 1 + \frac{1}{2\sqrt{2}} \cdot (-2) \\
                                                                                            &= - \frac{\sqrt{3}}{2}\\\\
    \cos \angle(v,w) &= -\frac{\sqrt{3}}{2} \cdot \frac{1}{3} \cdot \frac{1}{1} \\
                     &= -\frac{1}{2\sqrt{3}}\\
        \angle(v,w) &= \cos^{-1}(-\frac{1}{2\sqrt{3}}) \\
                    &= 106.74^{\circ} \text{ \textbf{OR}}\\
        \angle(v,w) &= 360^{\circ} - 106.74^{\circ} = 253.26^{\circ}
\end{align}
$$

\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
    \begin{itemize}
        \item What is the projection of $\begin{bmatrix}5,2 \end{bmatrix}$ onto the subspace spanned by vector $\begin{bmatrix} 1,1 \end{bmatrix}$?
        \item What is the projection of $\begin{bmatrix}0,2,1 \end{bmatrix}$ onto the subspace spanned by vector $\begin{bmatrix} 1,-1,-1 \end{bmatrix}$?
        \item Project $\begin{bmatrix} 5,2 \end{bmatrix}$ onto the subspace spanned by vectors $\begin{bmatrix} 2,3 \end{bmatrix}$, $\begin{bmatrix}1,1 \end{bmatrix}$
        \item What is the projection of $\begin{bmatrix} 1,-1,1 \end{bmatrix}$ onto the subspace spanned by vector $\begin{bmatrix} 1,1,1 \end{bmatrix}$ onto the subspace spanned by vectors  $\begin{bmatrix} 0,0,-1 \end{bmatrix}, \begin{bmatrix} 2,0,1 \end{bmatrix}$? Hint: this one is more tricky. Reason: $\begin{bmatrix} 0,-1,-1 \end{bmatrix} \cdot \begin{bmatrix}2,0,1\end{bmatrix} \neq 0$
    \end{itemize}

    \solution

    $$ x_{\parallel} v = \frac{x\cdot v}{v\cdot v}v =\left(x\cdot \frac{v}{\lVert v \rVert_2}\right) \frac{v}{\lVert v \rVert_2} $$

    \part

    $$
    \begin{align*}
        \frac{\begin{bmatrix} 5,2 \end{bmatrix} \cdot \begin{bmatrix} 1,1 \end{bmatrix}}{2} \begin{bmatrix} 1,1 \end{bmatrix} &= \frac{7}{2} \begin{bmatrix}1,1\end{bmatrix}\\
                                                                                                                              &= \left [3.5, 3.5 \right]
    \end{align*}
    $$

    \part

    $$
    \begin{align*}
        \frac{\begin{bmatrix} 0,2,1 \end{bmatrix} \cdot \begin{bmatrix} 1,-1,-1 \end{bmatrix}}{3} \begin{bmatrix} 1,-1,-1 \end{bmatrix} &= \frac{-3}{3} \begin{bmatrix}1,-1,-1\end{bmatrix}\\
                                                                                                                                        &= \begin{bmatrix}-1,1,1\end{bmatrix}
    \end{align*}
    $$

    \part

    Use Gran Schmidts to get 2 orthogonal Vectors $\tilde{v}^{\{0\}}$ and $\tilde{v}^{\{1\}}$ \\
    Project $\begin{bmatrix}5,2\end{bmatrix}$ onto the subspace spanned by $\tilde{v}^{\{0\}}$ and $\tilde{v}^{\{1\}}$ and sum up projections
    $$
    \begin{align*}
        \tilde{v}^{\{0\}} &= \begin{bmatrix}1,1\end{bmatrix}\\
        \tilde{v}^{\{1\}} &= \begin{bmatrix}2,3\end{bmatrix}\\
        \tilde{v}^{\{1\}} &= \begin{bmatrix}2,3\end{bmatrix} - \frac{\begin{bmatrix}2,3\end{bmatrix} \cdot \begin{bmatrix}1,1\end{bmatrix}}{\begin{bmatrix}1,1\end{bmatrix} \cdot \begin{bmatrix}1,1\end{bmatrix}} \begin{bmatrix}1,1\end{bmatrix}\\
                          &= \begin{bmatrix}2,3\end{bmatrix} - \frac{5}{2} \begin{bmatrix}1,1\end{bmatrix}\\
                          &= \begin{bmatrix}-\frac{1}{2},\frac{1}{2}\end{bmatrix}\\
    \end{align*}
    $$

    \textbf{Projection:}\\
    $$
    \begin{align*}
        \frac{\begin{bmatrix}5,2\end{bmatrix} \cdot \begin{bmatrix}1,1\end{bmatrix}}{2} \begin{bmatrix}1,1\end{bmatrix} + \frac{\begin{bmatrix}5,2\end{bmatrix} \cdot \begin{bmatrix}-\frac{1}{2},\frac{1}{2}\end{bmatrix}}{\begin{bmatrix}-\frac{1}{2}, -\frac{1}{2}\end{bmatrix}} \begin{bmatrix}-\frac{1}{2}, \frac{1}{2}\end{bmatrix} &= \frac{7}{2} \begin{bmatrix}1,1\end{bmatrix} + \frac{-\frac{3}{2}}{\frac{1}{2}} \begin{bmatrix}-\frac{1}{2}, \frac{1}{2}\end{bmatrix}\\
                                                                                                                                                                                                                   &= \begin{bmatrix}3.5, 3.5\end{bmatrix} + \begin{bmatrix}-\frac{3}{2}, \frac{3}{2}\end{bmatrix}\\
                                                                                                                                                                                                                   &= \begin{bmatrix}3.5 -\frac{3}{2}, 3.5 + \frac{3}{2}\end{bmatrix}\\
                                                                                                                                                                                                                   &= \begin{bmatrix}5,2\end{bmatrix}\\
    \end{align*}
    $$

    It must be $\begin{bmatrix}5,2\end{bmatrix}$.\\
    Reason: $\begin{bmatrix}2,3\end{bmatrix} \cdot \begin{bmatrix}1,1\end{bmatrix}$ are 2 
    independent vectors $\mathbb{R}^2$ span the whole vector space.\\

    2 independent vectors a,b, therefore dimension of subspace spanned by a and b is $\mathbb{R}^2$\\
    $\begin{bmatrix}5,2\end{bmatrix}$ projected onto $\mathbb{R}^2$ is $\begin{bmatrix}5,2\end{bmatrix}$
\\\\
    \part
\\\\
    let
    $
    \begin{cases}
        v^{\{0\}} = \begin{bmatrix}0,0,-1\end{bmatrix}\\\\
        v^{\{1\}} = \begin{bmatrix}2,0,1\end{bmatrix}
    \end{cases}
    $

    $$
    \begin{align}
    v^{\{1\}} &= \begin{bmatrix}2,0,1\end{bmatrix} - \frac{\begin{bmatrix}2,0,1\end{bmatrix} \cdot \begin{bmatrix}0,0,-1\end{bmatrix}}{\begin{bmatrix}0,0,-1\end{bmatrix} \cdot \begin{bmatrix}0,0,-1\end{bmatrix}} \begin{bmatrix}0,0,-1\end{bmatrix}\\
              &= \begin{bmatrix}2,0,1\end{bmatrix} - \frac{1}{1} \begin{bmatrix}0,0,-1\end{bmatrix}\\
              &= \begin{bmatrix}2,0,1\end{bmatrix} - \begin{bmatrix}0,0,-1\end{bmatrix}\\
              &= \begin{bmatrix}2,0,0\end{bmatrix}\\
    \end{align}
    $$
        
    Now project $\begin{bmatrix}1,-1,1\end{bmatrix}$ onto the subspace spanned by $v^{\{0\}}$ and $v^{\{1\}}$\\

    $$
    \begin{align}
        x_{\parallel v} &= \frac{\begin{bmatrix}1,-1,1\end{bmatrix} \cdot \begin{bmatrix}0,0,-1\end{bmatrix}}{\begin{bmatrix}0,0,-1\end{bmatrix} \cdot \begin{bmatrix}0,0,-1\end{bmatrix}} \begin{bmatrix}0,0,-1\end{bmatrix} + \frac{\begin{bmatrix}1,-1,1\end{bmatrix} \cdot \begin{bmatrix}2,0,0\end{bmatrix}}{\begin{bmatrix}2,0,0\end{bmatrix} \cdot \begin{bmatrix}2,0,0\end{bmatrix}} \begin{bmatrix}2,0,0\end{bmatrix}\\
                        &= \frac{-1}{1} \begin{bmatrix}0,0,-1\end{bmatrix} + \frac{2}{4} \begin{bmatrix}2,0,0\end{bmatrix}\\
                        &= \begin{bmatrix}1,0,1\end{bmatrix}
    \end{align}
    $$


    




\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
    Compute these matrix multiplications:
    $$
    \begin{bmatrix}
        2 & 1\\3&-2
    \end{bmatrix}
    \begin{bmatrix}
        -1 &0\\-4&-2
    \end{bmatrix}
    $$
    \\
    $$
    \begin{bmatrix}
        -3\\2\\1
    \end{bmatrix}
    \begin{bmatrix}
        2&4&-2
    \end{bmatrix}
    $$
    \\
    Question: Do you need more of them to practice? If so, you can do at home:\\
    $$
    \begin{bmatrix}
        1&2\\2&4
    \end{bmatrix}
    \begin{bmatrix}
        3&0&1\\0&1&2
    \end{bmatrix}
    $$
    \\
    $$
    \begin{bmatrix}
        0.5&2.5\\-3.5&1.5
    \end{bmatrix}
    \begin{bmatrix}
        6\\4
    \end{bmatrix}
    $$

    \solution

    \part

    $$
    \begin{bmatrix}
        2 & 1\\3&-2
    \end{bmatrix}
    \begin{bmatrix}
        -1 &0\\-4&-2
    \end{bmatrix}
    =
    \begin{bmatrix}
        2\cdot(-1)+1\cdot(-4) & 2\cdot0+1\cdot(-2)\\3\cdot(-1)+(-2)\cdot(-4) & 3\cdot0+(-2)\cdot(-2)
    \end{bmatrix}
    =
    \begin{bmatrix}
        -6 & -2\\5 & 4
    \end{bmatrix}
    $$
    \\
    $$
    \begin{bmatrix}
        -3\\2\\1
    \end{bmatrix}
    \begin{bmatrix}
        2&4&-2
    \end{bmatrix}
    =
    \begin{bmatrix}
        -3\cdot2 & -3\cdot4 & -3\cdot(-2)\\2\cdot2 & 2\cdot4 & 2\cdot(-2)\\1\cdot2 & 1\cdot4 & 1\cdot(-2)
    \end{bmatrix}
    =
    \begin{bmatrix}
        -6 & -12 & 6\\4 & 8 & -4\\2 & 4 & -2
    \end{bmatrix}
    $$

    \part

    $$
    \begin{bmatrix}
        1&2\\2&4
    \end{bmatrix}
    \begin{bmatrix}
        3&0&1\\0&1&2
    \end{bmatrix}
    =
    \begin{bmatrix}
        1\cdot3+2\cdot0 & 1\cdot0+2\cdot1 & 1\cdot1+2\cdot2\\2\cdot3+4\cdot0 & 2\cdot0+4\cdot1 & 2\cdot1+4\cdot2
    \end{bmatrix}
    =
    \begin{bmatrix}
        3 & 2 & 5\\6 & 4 & 10
    \end{bmatrix}
    $$
    \\
    $$
    \begin{bmatrix}
        0.5&2.5\\-3.5&1.5
    \end{bmatrix}
    \begin{bmatrix}
        6\\4
    \end{bmatrix}
    =
    \begin{bmatrix}
        0.5\cdot5+2.5\cdot4 \\ 0.5\cdot4+2.5\cdot6
    \end{bmatrix}
    =
    \begin{bmatrix}
        13 \\ -15
    \end{bmatrix}
    $$


\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}

    \begin{itemize}
        \item Project $\begin{bmatrix} 5,2 \end{bmatrix}$ onto the orthogonal space of vector $\begin{bmatrix} 2,-3 \end{bmatrix}$
        \item Project $\begin{bmatrix} 1,-1,3 \end{bmatrix}$ onto the orthogonal space of vector $\begin{bmatrix} -3,1,1\end{bmatrix}$
        \item Project $\begin{bmatrix} 1,-1,3,1 \end{bmatrix}$ onto the orthogonal space of vector $\begin{bmatrix} -2,2,0,0\end{bmatrix}$, $\begin{bmatrix} 0,0,\sqrt{2}, \sqrt{2}\end{bmatrix}$
    \end{itemize}

    \solution

    \part

    $$
    \begin{align*}
        x_{\perp v} &= \begin{bmatrix} 5,2 \end{bmatrix} - \frac{\begin{bmatrix} 5,2 \end{bmatrix}\cdot\begin{bmatrix} 2,-3 \end{bmatrix}}{\begin{bmatrix} 2,-3 \end{bmatrix}\cdot\begin{bmatrix} 2,-3 \end{bmatrix}}\begin{bmatrix} 2,-3 \end{bmatrix}\\
                    &= \begin{bmatrix} 5,2 \end{bmatrix} - \frac{5\cdot2+2\cdot(-3)}{2\cdot2+(-3)\cdot(-3)}\begin{bmatrix} 2,-3 \end{bmatrix}\\
                    &= \begin{bmatrix} 5,2 \end{bmatrix} - \frac{4}{13}\begin{bmatrix} 2,-3 \end{bmatrix}\\
                    &= \begin{bmatrix} 5-\frac{8}{13},2+\frac{12}{13} \end{bmatrix}\\
                    &= \begin{bmatrix} \frac{57}{13},\frac{38}{13} \end{bmatrix}
    \end{align*}
    $$
    \\
    Verify:\\
    $$
    \begin{bmatrix}5-\frac{8}{13},2+\frac{12}{13}\end{bmatrix}\cdot\begin{bmatrix}2,-3\end{bmatrix} = 0
    $$

    \part

    $$
    \begin{align*}
        x_{\perp v} &= \begin{bmatrix} 1,-1,3 \end{bmatrix} - \frac{\begin{bmatrix} 1,-1,3 \end{bmatrix}\cdot\begin{bmatrix} -3,1,1\end{bmatrix}}{\begin{bmatrix} -3,1,1\end{bmatrix}\cdot\begin{bmatrix} -3,1,1\end{bmatrix}}\begin{bmatrix} -3,1,1\end{bmatrix}\\
                    &= \begin{bmatrix} 1,-1,3 \end{bmatrix} - \frac{1\cdot(-3)+(-1)\cdot1+3\cdot1}{(-3)\cdot(-3)+1\cdot1+1\cdot1}\begin{bmatrix} -3,1,1\end{bmatrix}\\
                    &= \begin{bmatrix} 1,-1,3 \end{bmatrix} - \frac{-1}{11}\begin{bmatrix} -3,1,1\end{bmatrix}\\
                    &= \begin{bmatrix} 1-\frac{3}{11},-1+\frac{1}{11},3+\frac{1}{11} \end{bmatrix}\\
                    &= \left[ \frac{8}{11},-\frac{10}{11},\frac{34}{11} \right ]
    \end{align*}
    $$
    \\
    Verify:\\
    $$
    \begin{bmatrix}1-\frac{3}{11},-1+\frac{1}{11},3+\frac{1}{11}\end{bmatrix}\cdot\begin{bmatrix}-3,1,1\end{bmatrix} = 0
    $$

    \pagebreak

    \part

    $$
    \begin{bmatrix}-2,2,0,0\end{bmatrix}\cdot\begin{bmatrix}0,0,\sqrt{2},\sqrt{2}\end{bmatrix} = 0 \text{, thus:}\\
    $$

    $$
    \begin{align*}
        x_{\perp v} &= \begin{bmatrix}1,-1,3,1\end{bmatrix}-\frac{\begin{bmatrix}1,-1,3,1\end{bmatrix}\cdot\begin{bmatrix}-2,2,0,0\end{bmatrix}}{\begin{bmatrix}-2,2,0,0\end{bmatrix}\cdot\begin{bmatrix}-2,2,0,0\end{bmatrix}}\begin{bmatrix}-2,2,0,0\end{bmatrix} - \frac{\begin{bmatrix}1,-1,3,1\end{bmatrix}\cdot\begin{bmatrix}0,0,\sqrt{2},\sqrt{2}\end{bmatrix}}{\begin{bmatrix}0,0,\sqrt{2},\sqrt{2}\end{bmatrix}\cdot\begin{bmatrix}0,0,\sqrt{2},\sqrt{2}\end{bmatrix}}\begin{bmatrix}0,0,\sqrt{2},\sqrt{2}\end{bmatrix}\\
                    &= \begin{bmatrix}1,-1,3,1 \end{bmatrix} - \frac{-4}{8}\begin{bmatrix}-2,2,0,0\end{bmatrix} - \frac{0}{2}\begin{bmatrix}0,0,\sqrt{2},\sqrt{2}\end{bmatrix}\\
                    &= \begin{bmatrix}1,-1,3,1 \end{bmatrix} - \begin{bmatrix}-1,1,0,0\end{bmatrix} - \begin{bmatrix}0,0,2,2\end{bmatrix}\\
                    &= \begin{bmatrix}0,0,1,-1 \end{bmatrix}
    \end{align*}
    $$

    Verify:\\
    Verify that $\begin{bmatrix}0,0,1,-1\end{bmatrix}\cdot\begin{bmatrix}-2,2,0,0\end{bmatrix} = 0$ and $\begin{bmatrix}0,0,1,-1\end{bmatrix}\cdot\begin{bmatrix}0,0,\sqrt{2},\sqrt{2}\end{bmatrix} = 0$.

\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
    Run Gram-Schmid-orthogonalization on the vectors
    $$\begin{bmatrix} 12,12,6 \end{bmatrix}, \begin{bmatrix} 2,-2,4 \end{bmatrix}, \begin{bmatrix} -2,-2,1 \end{bmatrix}$$

    \solution

    \part

    $$
    \begin{align*}
        \tilde{v}^{\{0\}} &= \begin{bmatrix} 12,12,6 \end{bmatrix}\\\\
        \tilde{v}^{\{1\}} &= \begin{bmatrix}2,-2,4\end{bmatrix}-\frac{\begin{bmatrix}2,-2,4\end{bmatrix}\cdot\begin{bmatrix}12,12,6\end{bmatrix}}{\begin{bmatrix}12,12,6\end{bmatrix}\cdot\begin{bmatrix}12,12,6\end{bmatrix}}\begin{bmatrix}12,12,6\end{bmatrix}\\
                          &= \begin{bmatrix}2,-2,4\end{bmatrix}-\frac{2\cdot12+(-2)\cdot12+4\cdot6}{12\cdot12+12\cdot12+6\cdot6}\begin{bmatrix}12,12,6\end{bmatrix}\\
                          &= \begin{bmatrix}2,-2,4\end{bmatrix}-\frac{24}{288+36}\begin{bmatrix}12,12,6\end{bmatrix}\\
                          &= \begin{bmatrix}2,-2,4\end{bmatrix}-\left[ \frac{12 \cdot 24}{9 \cdot 36},\frac{12 \cdot 24}{9 \cdot 36},\frac{6 \cdot 24}{9 \cdot 36}\right]\\
                          &= \begin{bmatrix}2,-2,4\end{bmatrix}-\left[ \frac{288}{324},\frac{288}{324},\frac{144}{324}\right]\\
                          &= \left [2-\frac{8}{9},-2-\frac{8}{9},4-\frac{4}{9}\right]\\\\
        \tilde{v}^{\{2\}} &= \begin{bmatrix}-2,-2,1\end{bmatrix}\\
                          &-\frac{\begin{bmatrix}-2,-2,1\end{bmatrix}\cdot\begin{bmatrix}12,12,6\end{bmatrix}}{\begin{bmatrix}12,12,6\end{bmatrix}\cdot\begin{bmatrix}12,12,6\end{bmatrix}}\begin{bmatrix}12,12,6\end{bmatrix}\\
                          &-\frac{\begin{bmatrix}-2,-2,1\end{bmatrix}\cdot\left [2-\frac{8}{9},-2-\frac{8}{9},4-\frac{4}{9}\right]}{\left [2-\frac{8}{9},-2-\frac{8}{9},4-\frac{4}{9}\right]\cdot\left [2-\frac{8}{9},-2-\frac{8}{9},4-\frac{4}{9}\right]}\left [2-\frac{8}{9},-2-\frac{8}{9},4-\frac{4}{9}\right]\\
                          &= \begin{bmatrix}-2,-2,1\end{bmatrix}-\frac{(-2)\cdot12+(-2)\cdot12+1\cdot6}{12\cdot12+12\cdot12+6\cdot6}\begin{bmatrix}12,12,6\end{bmatrix}\\
                          &-\frac{(-2)\cdot2+(-2)\cdot(-2)+1\cdot4}{2\cdot2+(-2)\cdot(-2)+4\cdot4}\left [2-\frac{8}{9},-2-\frac{8}{9},4-\frac{4}{9}\right]\\
                          &= \begin{bmatrix}-2,-2,1\end{bmatrix}-\left[ \frac{14}{9},\frac{14}{9},\frac{7}{9}\right] - \frac{\frac{36+28}{9}}{24+\frac{128}{28}-\frac{32\cdot 9}{81}} \left[2 - \frac{8}{9},-2 - \frac{8}{9},4 - \frac{4}{9}\right]\\
    \end{align*}
    $$

\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
{\large \textbf{Understanding Distances coming from $\ell_p$-norms}}\\

    Coding: plot in python or similar the set of points $x \in \mathbb{R}^2$ usuch that $\lVert x \rVert_p = 1$ for
    \begin{itemize}
        \item $p = 0.2$
        \item $p = 0.5$
        \item $p = 1$
        \item $p = 1.5$
        \item $p = 2$
        \item $p = 4$
        \item $p = 8$
        \item $p = 16$
    \end{itemize}
    Hint: in 2 dimensions for $p=2$ the solution is given by
    $$x(t) = \left(\cos(t), \sin(t)\right)$$
    due to $\cos^2(t) + \sin^2(t) = 1$.

you can use the same idea with different powers. You can start by considering $(\cos^r(t), \sin^r(t))$. One thing to node: $\cos(t)^r + \sin(t)^r$ is not always defined for negative values and certain $r$.\\

For $p \neq 2$, you can consider this, thich deals with the signs:
$$x(t) = (sign(\cos(t))|\cos(t)|^r, sign(\sin(t))|\sin(t)|^r)$$
for the right choice of r. Find out which $r$ is suitable for a general $p > 0$ such that $\lVert x \rVert_p = 1$. Then plot it in python.\\

    \solution
\begin{tikzpicture}[>=Stealth]
   \foreach \i in {0,...,3}{
     \begin{scope}[xshift=\i*4.5cm]
      \draw [<->] (-1.2,0)--(2.5,0);
      \draw [<->] (0,-1.2)--(0,1.7);
      \draw[shorten <=-1cm, shorten >=-3mm] (0,1)--(2,0) node [midway, above] {$A$};
    \end{scope}
   }
   \begin{scope}[draw=blue, densely dashed]
     \draw [] (-1,0)--(0,1)--(1,0)--(0,-1)--cycle;
     \draw [](4.5,0) circle (0.88cm);
     \draw [xshift=9cm] (-.66,-.66) rectangle (.66,.66);
     \begin{scope}[xshift=13.5cm]
       \draw [domain=0:90,samples=100,smooth,variable=\t] plot({-1*cos(\t)^(3)},{1*sin(\t)^(3)});
       \draw [domain=0:90,samples=100,smooth,variable=\t] plot({-1*cos(\t)^(3)},{-1*sin(\t)^(3)});
       \draw [domain=0:90,samples=100,smooth,variable=\t] plot({1*cos(\t)^(3)},{-1*sin(\t)^(3)});
       \draw [domain=0:90,samples=100,smooth,variable=\t] plot({1*cos(\t)^(3)},{1*sin(\t)^(3)});
     \end{scope}
     \foreach \i [count=\j from 0] in {(0,1),(.39,.79),(.66,.66),(0,1)} \scoped [xshift=\j*4.5cm] { \draw [{Circle[width=3pt, length=3pt, fill=black, black]}-{Circle[width=3pt, length=3pt, fill=black, black]}, shorten <=-1.5pt, shorten >=-1.5pt] (0,0) node [below left] {$x$} -- \i node [above right] {$\hat x$} ; };
   \end{scope}
   \foreach \i [count=\j from 0] in {1,2,\infty,\frac{1}{2}} \scoped [xshift=\j*4.5cm] { \node [anchor=mid west] at (0,-1.5) {$p=\i$}; };
\end{tikzpicture}
\end{homeworkProblem}
\end{document}
