\subsection{Recap}
Given the linear equation $a_1x_1 +  a_2x_2 + ... + a_nx_n = b$

\begin{enumerate}
  \item $a_1 = a_2 = ... = a_n = b = 0$ zero equation

    Solution: $x_1 = t_1, x_2 = t_2, ... = x_n = t_n$

  \item $a_1 = a_2 = ... = a_n = 0 \neq b$ inconsistent

    No Solution

  \item Not all $a_1 ... a_n$ are zero. 

    Set $n-1$ of $x_i$ as params, solve for last variable
\end{enumerate}

\subsection{Elementary Row Operations Example}

\begin{center}

  \begin{minipage}{.3\linewidth}
    \systeme{x+y+3z = 0, 2x-2y+2z=4, 3x+9y=3}
  \end{minipage}%
  \begin{minipage}{.3\linewidth}
    \begin{equation*}
      \begin{amatrix}{3}
        1 & 1 & 3 & 0 \\
        2 & 2 & 2 & 4 \\
        3 & 9 & 0 & 3
      \end{amatrix}
    \end{equation*}
  \end{minipage}
\end{center}

\subsection{Row Equivalent Matrices}
2 Augmented Matrices are row equivalent if one can be obtained from the other by a series of elementary row operations

Given a augmented matrix $A$, how to find a row equivalent augmented  matrix B of which is of a \textbf{simple} form?

\subsection{Row Echelon Form}

\begin{defn}[Row Echelon Form (Simple)]
  Augmented Matrix is in row-echelon form if
  \begin{itemize}
    \item Zero rows are grouped together at the bottom
    \item For any 2 successive nonzero rows, The first nonzero number in the lower row appears to the right of the first nonzero number on the higher row
      $\begin{amatrix}{4}
        0 & 0 & 1 & 2 & 3 \\
        0 & 0 & 0 & 1 & 2 \\
      \end{amatrix}$
    \item Leading entry if a nonzero row is a \textbf{pivot point}
    \item Column of augmented matrix is called 
      \begin{itemize}
        \item \textbf{Pivot Column} if it contains a pivot point
        \item \textbf{Non Pivot Column} if it contains no pivot point
      \end{itemize} 
    \item Pivot Column contains exactly 1 pivot point

      \# of pivots = \# of leading entries = \# of nonzero rows
  \end{itemize}
\end{defn}

Examples of row echlon form: 

\begin{equation*}
  \begin{amatrix}{2}
    3 & 2 & 1 \\
  \end{amatrix}
  \begin{amatrix}{2}
    1 & -1 & 0 \\
    0 & 1 & 0 \\
  \end{amatrix}
  \begin{amatrix}{2}
    2 & 1 & 0 \\
    0 & 1 & 0 \\
    0 & 0 & 1 \\
  \end{amatrix}
  \begin{amatrix}{3}
    1 & 2 & 3 & 4 \\
    0 & 1 & 1 & 2 \\
    0 & 0 & 2 & 3 \\
  \end{amatrix}
  \begin{amatrix}{4}
    0 & 1 & 2 & 8 & 1 \\
    0 & 0 & 0 & 0 & 3 \\
    0 & 0 & 0 & 0 & 0 \\
    0 & 0 & 0 & 0 & 0 \\
  \end{amatrix}
\end{equation*}

Examples of NON row echlon form: 

\begin{equation*}
  \begin{amatrix}{2}
    0 & \textbf{1} & 0 \\
    \textbf{1} & 0 & 0 \\
  \end{amatrix}
  \begin{amatrix}{2}
    0 & 0 & \textbf{1} \\
    \textbf{1} & -1 & 0 \\
    0 & 0 & 1 \\
  \end{amatrix}
  \begin{amatrix}{3}
    \textbf{1} & 0 & 2 & 1 \\
    0 & \textbf{1} & 0 & 2 \\
    0 & \textbf{1} & 1 & 3 \\
  \end{amatrix}
  \begin{amatrix}{4}
    \textbf{0} & \textbf{0} & \textbf{0} & \textbf{0} & \textbf{0} \\
    1 & 0 & 2 & 0 & 1 \\
    0 & 0 & 0 & 1 & 3 \\
    0 & 0 & 0 & 0 & 0 \\
  \end{amatrix}
\end{equation*}
\subsection{Reduced Row-Echelon Form}

\begin{defn}[Reduced Row-Echelon Form]
  Suppose an augmented matrix is in row-echelon form. It is in \textbf{reduced row-echelon form} if
  \begin{itemize}
    \item Leading entry of every nonzero row is 1
      \subitem Every pivot point is one
    \item In each pivot column, except the pivot point, all other entries are 0.
  \end{itemize}
\end{defn}

Examples of reduced row-echelon form: 

\begin{equation*}
  \begin{amatrix}{2}
    1 & 2 & 3 \\
  \end{amatrix}
  \begin{amatrix}{2}
    0 & 0 & 0 \\
    0 & 0 & 0 \\
  \end{amatrix}
  \begin{amatrix}{2}
    1 & 0 & 0 \\
    0 & 1 & 0 \\
    0 & 0 & 1 \\
  \end{amatrix}
  \begin{amatrix}{3}
    1 & 0 & 0 & 1 \\
    0 & 1 & 0 & 2 \\
    0 & 0 & 1 & 3 \\
  \end{amatrix}
  \begin{amatrix}{4}
    0 & 1 & 2 & 0 & 1 \\
    0 & 0 & 0 & 1 & 3 \\
    0 & 0 & 0 & 0 & 0 \\
    0 & 0 & 0 & 0 & 0 \\
  \end{amatrix}
\end{equation*}

Examples of row-echelon form but not reduced: (pivot point is not 1 / all other elements \textbf{in pivot column} must be zero)

\begin{equation*}
  \begin{amatrix}{2}
    \textbf{3} & 2 & 1 \\
  \end{amatrix}
  \begin{amatrix}{2}
    1 & \textbf{-1} & 0 \\
    0 & 1 & 0 \\
  \end{amatrix}
  \begin{amatrix}{2}
    \textbf{2} & 0 & 0 \\
    0 & 1 & 0 \\
    0 & 0 & 1 \\
  \end{amatrix}
  \begin{amatrix}{3}
    \textbf{-1} & 2 & 3 & 4 \\
    0 & 1 & 1 & 2 \\
    0 & 0 & 2 & 3 \\
  \end{amatrix}
  \begin{amatrix}{4}
    0 & 1 & 2 & \textbf{8} & 1 \\
    0 & 0 & 0 & \textbf{4} & 3 \\
    0 & 0 & 0 & 0 & 0 \\
    0 & 0 & 0 & 0 & 0 \\
  \end{amatrix}
\end{equation*}

To note: 2nd matrix has -1 in the pivot column, but 5th matrix has 2 in a non-pivot column so its fine

\subsection{Solving Linear System}

If Augmented Matrix is in reduced row-echelon form, then solving it is easy

\begin{equation*}
  \begin{amatrix}{3}
    1 & 0 & 0 & 1 \\
    0 & 1 & 0 & 2 \\
    0 & 0 & 1 & 3 \\
  \end{amatrix}
  \text{then } x_1 = 1, x_2 = 2, x_3 = 3
\end{equation*}

\begin{note}
  \begin{itemize}
    \item If any equations in the system is inconsistent, the whole system is inconsistent
  \end{itemize}
\end{note}

\subsubsection{Examples}

Augmented Matrix: $\begin{amatrix}{4}
  1 & -1 & 0 & 3 & -2 \\
  0 & 0 & 1 & 2 & 5 \\
  0 & 0 & 0 & 0 & 0 \\
\end{amatrix}$

\begin{itemize}
  \item The zero row can be ignored. 
    \systeme{x_1 - x_2 + 3x_4 = -2, x_3 + 2x_4 = 5}
  \item Degree of freedom(\# cols): 4, number of restrictions (\# pivot cols): 2, arbitrary vars(\# non pivot cols): 4-2 = 2. Set this to the non-pivot cols
\end{itemize}
\begin{enumerate}
  \item Let $x_4 = t$ and sub into 2nd eqn
    \subitem $x_3 + 2t = 5 \Rightarrow x_3 = 5-2t$
  \item sub $x_4 = t$ into 1st eqn
    \subitem $x_1 - x_2 + 3t = -2$
    \subitem Let $x_2 = s$. Then $x_1 = -2 + s - 3t$
  \item Infinitely many sols with ($s$ and $t$ as arbitrary params)
    \subitem $x_1 = -2 + s - 3t, x_2 = s, x_3 = 5-2t, x_4 = t$

\end{enumerate}

Augmented Matrix: $\begin{amatrix}{5}
  0 & 2 & 2 & 1 & -2 & 2 \\
  0 & 0 & 1 & 1 & 1 & 3 \\
  0 & 0 & 0 & 0 & 2 & 4 \\
\end{amatrix}$
\begin{itemize}
  \item \systeme{0x_1 + 2x_2 + 2x_3 + 1x_4 -2x_5 = 2,x_3 + x_4 +x_5 = 3,2x_5 = 4}
  \item Degree of freedom: 5, number of restrictions: 3, arbitrary vars: 5-3 = 2
\end{itemize}

\begin{enumerate}
  \item by 3rd eqn, $2x_5 = 4 \Rightarrow x_5 = 2$
  \item sub $x_5 = 2$ into 2nd eqn
    \subitem $x_3 + x_4 + 2 = 3 \Rightarrow x_3 + x_4 = 1$
    \subitem let $x_4 = t$. Then $x_3 = 1-t$
  \item sub $x_5 = 2, x_3 = 1-t, x_4 = t$ into 1st eqn
    \subitem $2x_2 + 2(1-t) + t - 2(2) = 2 \Rightarrow 2x_2 -t = 4 \Rightarrow x_2 = \frac{t}{2} + 2$
  \item system has inf many solns: $x_1 = s, x_2 = \frac{t}{2} + 2, x_3 = 1-t, x_4 = t, x_5 = 2$ where $s$ and $t$ are arbitrary
\end{enumerate}

\subsubsection{Algorithm}
Given the augmented matrix is in row-echelon form.
\begin{enumerate}
  \item Set variables corresponding to non-pivot columns to be arbitrary parameters
  \item Solve variables corresponding to pivot columns by back substitution (from last eqn to first)
\end{enumerate}


\subsection{Gaussian Eliminiation}

\begin{defn}[Gaussian Elimination]\ \\
  \begin{enumerate}
    \item Find the left most column which is not entirely zero
    \item If top entry of such column is 0, replace with nonzero number by swapping rows
    \item For each row below top row, add multiple of top row so that leading entry becomes 0
    \item Cover top row and repeat to remaining matrix
  \end{enumerate}
\end{defn}

\begin{note}[Algorithm with Example]\ \\
  $\begin{amatrix}{6}
    0 & 0 & 0 & 2 & 4 & 2 & 8 \\
    0 & 1 & 2 & 4 & 5 & 3 &-9 \\
    0 &-2 &-4 &-5 &-4 & 3 & 6 \\
  \end{amatrix}$
  \begin{enumerate}
    \item Find the left most column which is not all zero (2nd column)
    \item Check top entry of the selection. If its zero, replace it by a nonzero number by interchanging the top row with another row below
      \subitem $\begin{amatrix}{6}
        0 & 1 & 2 & 4 & 5 & 3 &-9 \\
        0 & 0 & 0 & 2 & 4 & 2 & 8 \\
        0 &-2 &-4 &-5 &-4 & 3 & 6 \\
      \end{amatrix}$
    \item For each row below the top row, adda suitable multiple of top row so that leading entry becomes 0.
      \subitem $2R_1 + R_3$ will ensure that the -2 turns to 0
      \subitem $\begin{amatrix}{6}
        0 & 1 & 2 & 4 & 5 & 3 &-9 \\
        0 & 0 & 0 & 2 & 4 & 2 & 8 \\
        0 & 0 & 0 & 3 & 6 & 9 &-12\\
      \end{amatrix}$
    \item Cover top row and repeat procedure to the remaining matrix
      \subitem $\begin{amatrix}{6}
        0 & 1 & 2 & 4 & 5 & 3 &-9 \\
        \hline
        0 & 0 & 0 & 2 & 4 & 2 & 8 \\
        0 & 0 & 0 & 3 & 6 & 9 &-12\\
      \end{amatrix}$
      \subitem Look at $C_4$. $R_3 \times -1.5R_2$ will set $R_3C_4$ to zero.
      \subitem $\begin{amatrix}{6}
        0 & 1 & 2 & 4 & 5 & 3 &-9 \\
        \hline
        0 & 0 & 0 & 2 & 4 & 2 & 8 \\
        0 & 0 & 0 & 0 & 0 & 6 & -24\\
      \end{amatrix}$
      \subitem This is now in row echelon form.
  \end{enumerate}
      Only use $R_i \Leftrightarrow R_j or R_i + CR_j$ in this method.
\end{note}

\subsection{Gauss-Jordan Elimination}
\begin{defn}[Gauss Joran Elimination]\ \\
  \begin{enumerate}
    \item[1-4.] Use Gaussian Eliminiation to get row-echelon form
      \setcounter{enumi}{4}
    \item For each nonzero row, multiply a suitable constant so pivot point becomes 1
    \item Begin with last nonzero row and work backwords
      \subitem Add suitable multiple of each row to the rows above to introduce 0 above pivot point
  \end{enumerate}
  \begin{itemize}
    \item Every matrix has a unique reduced row-echelon form.
    \item Every nonzero matrix has infinitely many row-echelon ofrm
  \end{itemize}
\end{defn}
\begin{note}[Gauss Jordan Elimination Example] Suppose an augmented matrix is in row-echelon form. 
  $\begin{amatrix}{5}
    1 & 2 & 4 & 5 & 3 & -9 \\
    0 & 0 & 2 & 4 & 2 & 8 \\
    0 & 0 & 0 & 0 & 6 & -24 \\
  \end{amatrix}$
  \begin{enumerate}
    \item All pivot points must be 1
      \subitem multiply $R_2$ by $\frac{1}{2}$ and $R_3$ by $\frac{1}{6}$
      \subitem $\begin{amatrix}{5}
        1 & 2 & 4 & 5 & 3 & -9 \\
        0 & 0 & 1 & 2 & 1 & 4 \\
        0 & 0 & 0 & 0 & 1 & -4 \\
      \end{amatrix}$
    \item In each pivot col, all entries other than pivot point must be 0. Work backwards
      \subitem $R_1 + -3R_1$, $R_2 + -R_1$
      \subitem $\begin{amatrix}{5}
        1 & 2 & 4 & 5 & 0 & 3 \\
        0 & 0 & 1 & 2 & 0 & 8 \\
        0 & 0 & 0 & 0 & 1 & -4 \\
      \end{amatrix}$
      \subitem $R_1 + -4R_2$
      \subitem $\begin{amatrix}{5}
        1 & 2 & 0 & -3 & 0 & -29 \\
        0 & 0 & 1 & 2 & 0 & 8 \\
        0 & 0 & 0 & 0 & 1 & -4 \\
      \end{amatrix}$

  \end{enumerate}
\end{note}


