\documentclass[a4paper]{article}

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

\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\ \#9}
\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 $A^\top A$ for
    $$
    \begin{equation*}
        A = \begin{bmatrix}
            2&-3\\
            -6&-9
        \end{bmatrix}
    \end{equation*}

    \begin{equation*}
        A = \begin{bmatrix}
            0&1&-1\\
            2&0&2\\
            4&3&1
        \end{bmatrix}
    \end{equation*}
    $$

    \solution

\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
    Compute the inverse of 
    $$
    \begin{equation*}
        A_0 = \begin{bmatrix}
            -2&-3\\
            -6&-4
        \end{bmatrix}
    \end{equation*}
    $$
    $$
    \begin{equation*}
        A_1 = \begin{bmatrix}
            3&1\\
            -2&2
        \end{bmatrix}
    \end{equation*}
    $$

    Use this inverses to solve

    $$
    \begin{equation*}
        A_0 x = \begin{bmatrix}
            3\\
            1
        \end{bmatrix}
    \end{equation*}
    $$
    $$
    \begin{equation*}
        A_0 x = \begin{bmatrix}
            2\\
            -5
        \end{bmatrix}
    \end{equation*}
    $$

    Note: it is not common to solve $Ax=b$ using matrix inversion.\\

    Reasons:
    \begin{itemize}
        \item $Ax=b$ can be solvable when $A$ is not invertible.
        \item It is often slower / more costly
    \end{itemize}

    \solution
\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
    Compute the determinant of

    $$
    \begin{equation*}
        A = \begin{bmatrix}
            1&2&-1\\
            2&0&2\\
            4&3&1
        \end{bmatrix}
    \end{equation*}
    \begin{equation*}
        A = \begin{bmatrix}
            2&-4&3\\
            1&1&1\\
            3&3&1
        \end{bmatrix}
    \end{equation*}
    \begin{equation*}
        A = \begin{bmatrix}
            1&0&1\\
            2&3&2\\
            -1&3&2
        \end{bmatrix}
    \end{equation*}
    \begin{equation*}
        A = \begin{bmatrix}
            1&2&3\\
            -5&-10&-15\\
            6&12&18
        \end{bmatrix}
    \end{equation*}
    $$

    \begin{itemize}
        \item Are they Invertible?
        \item Which of them has full rank? Which of them has lower rank and which one?
    \end{itemize}

    \solution
\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
    For what value $a$ the matrix is not invertible?

    $$
    \begin{equation*}
        A = \begin{bmatrix}
            1&2&1\\
            2&a&4\\
            -3&1&2
        \end{bmatrix}
    \end{equation*}
    $$

    \solution
\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
    Compute and apply the Householder matrix which makes transforms the first column of
    to a multple of the first one-hot vector $\begin{bmatrix}1\\0\\0\end{bmatrix}$ for

    $$
    \begin{equation*}
        A = \begin{bmatrix}
            1&2&-1\\
            2&0&2\\
            2&3&1
        \end{bmatrix}
    \end{equation*}
    $$

    and for (hint: here subtracting is nicer)

    $$
    \begin{equation*}
        A = \begin{bmatrix}
            1&-4&3\\
            3&1&1\\
            \sqrt{6}&3&1
        \end{bmatrix}
    \end{equation*}
    $$

    \solution

\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
    Verify that

    $$
    \begin{equation*}
        A = \begin{bmatrix}
            1&0&0\\
            0&\cos(\alpha)&-\sin(\alpha)\\
            0&\sin(\alpha)&\cos(\alpha)
        \end{bmatrix}
    \end{equation*}
    $$

    Satisfies being an orthogonal matrix.

    \solution
\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}

    What is the cosine of the angle between

    $$
    \left( 6,-6,-4,\sqrt{12} \right), \left( 6,4,2,\sqrt{25} \right)?
    $$

    \solution
\end{homeworkProblem}

\pagebreak

\begin{homeworkProblem}
    Another $3\times3$ affine system

    \begin{itemize}
        \item show the intermediate result when the first column is the one hot vector $\begin{bmatrix}1&0&0\end{bmatrix}$ for the first time
        \item show that the intermediate result when the matrix has row echelon form for the first time
        \item get the solution
    \end{itemize}

    $$
    \begin{align*}
        2x-3y+2z &=-4\\
        7x+4.5y-1z &=16\\
        4x+3y+z &=2
    \end{align*}
    $$

    \solution
\end{homeworkProblem}


\end{document}
