\documentclass[12pt]{article}

\usepackage{systeme}

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{fancyvrb}

%\usepackage[color=green!40,textsize=small]{todonotes}
%\setlength{\marginparwidth}{2cm} % <-- fixes margin problem for todonotes

\usepackage{xcolor}

%\usepackage[textheight=8.5in, margin=1.6in]{geometry}
\usepackage[total={6in,8in}]{geometry}

\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
%\tikzstyle{ball} = [circle,shading=ball, ball color=black,
%    minimum size=1mm,inner sep=1.3pt]
%\usetikzlibrary{arrows.meta}
%\tikzset{>={Latex[length=2mm,width=1.5mm]}}

%\usepackage{graphicx}

\usepackage{needspace}  % <-- to prevent bad pagebreak over environment titles
% Use:  \Needspace{3\baselineskip} before opening an environment

\usepackage{enumitem}
%\setlist[enumerate]{leftmargin=*}

\usepackage[colorlinks=true,citecolor=black,linkcolor=black,urlcolor=blue]{hyperref}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}
\newcommand{\Q}{\mathbb{Q}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\C}{\mathbb{C}}
\newcommand{\sn}{\mathfrak{S}}
\newcommand{\ve}{\varepsilon}
\newcommand{\ips}[2]{\langle{#1}, {#2}\rangle}
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\Span}{\mathrm{Span}}
\DeclareMathOperator{\rk}{\mathrm{rank}}
\DeclareMathOperator{\trace}{\mathrm{tr}}
\DeclareMathOperator{\im}{\mathrm{im}}
\DeclareMathOperator{\Sym}{\mathrm{Sym}}
\DeclareMathOperator{\Hom}{\mathrm{Hom}}
\DeclareMathOperator{\diag}{\mathrm{diag}}
\DeclareMathOperator{\glb}{\mathrm{glb}}
\DeclareMathOperator{\lub}{\mathrm{lub}}

\parskip = 0.05in
\parindent = 0.0in

%\pagestyle{empty}

\begin{document}
\centerline{Typesetting row reductions and solution spaces}
\bigskip

\textbf{Matrices.}  The following LateX code
\begin{verbatim}
\[
\left(
\begin{array}{rrr|r}
1 & 1 & -8 & 6 \\
2 & 3 & -21 & 14 \\
-1 & 0 & 4 & -5
\end{array}
\right)
\]
\end{verbatim}
produces the augmented matrix
\[
\left(
\begin{array}{rrr|r}
1 & 1 & -8 & 6 \\
2 & 3 & -21 & 14 \\
-1 & 0 & 4 & -5
\end{array}
\right)
\]
The part of the code that reads \verb+{rrr|r}+ says that the four entries in
each row should be right-justified and that there should be a line between the
third and fourth columns.  To center or left-justify any column, use \texttt{c} or
\texttt{l}, respectively, in  place of any \texttt{r}.

Here are a couple more examples of matrices.  This code
\begin{verbatim}
\[
\left(\begin{array}{rr}
1 & 3 \\
0 & 5 \\
2 & 4
\end{array}\right)
\qquad
\left(\begin{array}{ccc}
x & x^2 + x + 2 & 2 \, x^3 + 5 \, x^2 \\
3+x^{12} & 7 \, x^4 & 4
\end{array}\right)
\]
\end{array}\right)
\end{verbatim}
produces the following:
\[
\left(\begin{array}{rr}
1 & 3 \\
0 & 5 \\
2 & 4
\end{array}\right)
\qquad
\left(\begin{array}{ccc}
x & x^2 + x + 2 & 2 \, x^3 + 5 \, x^2 \\
3+x^{12} & 7 \, x^4 & 4
\end{array}\right)
\]
The \verb+\qquad+ adds horizontal space (other choices are \verb+\quad+ for half
the extra space of \verb+\qquad+ or \verb+\vspace{2cm}+ for 2~centimeters of
space, etc.).
\bigskip

\textbf{The align environment.}  The following code
\begin{verbatim}
\begin{align*} 
2x - 5y &=  8 \\ 
3x + 9y &=  -12\\
4x + 12y&= 7
\end{align*}
\end{verbatim}
results in 
\begin{align*} 
2x - 5y &=  8 \\ 
3x + 9y &=  -12\\
4x + 12y&= 7
\end{align*}
The ampersand gives the point of alignment, and the \verb+\\+ gives a new line.
Note that the last equation in the code does not contain \verb+\\+.

Here is another example of the use of the align environment:
\begin{verbatim}
\begin{align*}
  x +\frac{1}{x} + \frac{x}{1+x} &= \frac{x^2+1}{x} + \frac{x}{1+x}\\[8pt]
  &= \frac{(x^2+1)(1+x)+x^2}{x(x+1)}\\[8pt]
  &= \frac{1+x+2x^2+x^3}{x(x+1)}.
\end{align*}
\end{verbatim}
\begin{align*}
  x +\frac{1}{x} + \frac{x}{1+x} &= \frac{x^2+1}{x} + \frac{x}{1+x}\\[8pt]
  &= \frac{(x^2+1)(1+x)+x^2}{x(x+1)}\\[8pt]
  &= \frac{1+x+2x^2+x^3}{x(x+1)}.
\end{align*}
Here, I have used \verb+\\[8pt]+ instead of \verb+\\+ in order to add 8 points
of space between the lines. (Instead of \verb+pt+, one could use \verb+cm+ or
\verb+mm+ or \verb+in+, etc.)
\bigskip

\textbf{Typesetting row reduction.}  For typesetting row reduction, I use the
align environment along with the \verb+\xrightarrow+ command, as can be seen
below:
\begin{Verbatim}[fontsize=\scriptsize]
\begin{align*}
\left(
\begin{array}{rrr|r}
1 & 1 & -8 & 6 \\
2 & 3 & -21 & 14 \\
-1 & 0 & 4 & -5
\end{array}
\right)
% the alignment point is set here
&\xrightarrow[r_3\to r_3+r_1]{r_2\to r_2-2r_1}
\left(
\begin{array}{rrr|r}
1 & 1 & -8 & 6 \\
0 & 1 & -5 & 2 \\
0 & 1 & -4 & 1
\end{array}
\right)
\xrightarrow{r_3\to r_3-r_2}
\left(
\begin{array}{rrr|r}
1 & 1 & -8 & 6 \\
0 & 1 & -5 & 2 \\
0 & 0 & 1 & -1
\end{array}
\right)
\\[10pt]
&\xrightarrow{r_1\to r_1-r_2}
\left(
\begin{array}{rrr|r}
1 & 0 & -3 & 4 \\
0 & 1 & -5 & 2 \\
0 & 0 & 1 & -1
\end{array}
\right)
\xrightarrow[r_1\to r_1+3r_3]{r_2\to r_2+5r_3}
\left(
\begin{array}{rrr|r}
1 & 0 & 0 & 1 \\
0 & 1 & 0 & -3 \\
0 & 0 & 1 & -1
\end{array}
\right).
\end{align*}
\end{Verbatim}
\begin{align*}
\left(
\begin{array}{rrr|r}
1 & 1 & -8 & 6 \\
2 & 3 & -21 & 14 \\
-1 & 0 & 4 & -5
\end{array}
\right)
% the alignment point is set here
&\xrightarrow[r_3\to r_3+r_1]{r_2\to r_2-2r_1}
\left(
\begin{array}{rrr|r}
1 & 1 & -8 & 6 \\
0 & 1 & -5 & 2 \\
0 & 1 & -4 & 1
\end{array}
\right)
\xrightarrow{r_3\to r_3-r_2}
\left(
\begin{array}{rrr|r}
1 & 1 & -8 & 6 \\
0 & 1 & -5 & 2 \\
0 & 0 & 1 & -1
\end{array}
\right)
\\[10pt]
&\xrightarrow{r_1\to r_1-r_2}
\left(
\begin{array}{rrr|r}
1 & 0 & -3 & 4 \\
0 & 1 & -5 & 2 \\
0 & 0 & 1 & -1
\end{array}
\right)
\xrightarrow[r_1\to r_1+3r_3]{r_2\to r_2+5r_3}
\left(
\begin{array}{rrr|r}
1 & 0 & 0 & 1 \\
0 & 1 & 0 & -3 \\
0 & 0 & 1 & -1
\end{array}
\right).
\end{align*}
\newpage

\textbf{Typesetting solution sets.}  
Consider the linear system of equations
\[
  \sysdelim..
  \systeme{x_1+2x_2=1,x_3+3x_4=0,x_5=3.}
\]
Typesetting for the above is
\begin{verbatim}
\[
  \sysdelim..
  \systeme{x_1+2x_2=1,x_3+3x_4=0,x_5=3.}
\]
\end{verbatim}
which requires 
\begin{verbatim}
\usepackage{systeme}
\end{verbatim}
in the preamble to the LaTeX file.

The matrix corresponding to this system of equations is already in reduced row
echelon form.  So we can just read off the solutions.  First, we solve for the
pivot variables:
\begin{align*}
x_1&= 1-2x_2\\
x_3&= -3x_4\\
x_5&= 3.
\end{align*}
Code:
\begin{verbatim}
\begin{align*}
x_1&= 1-2x_2\\
x_3&= -3x_4\\
x_5&= 3.
\end{align*}
\end{verbatim}

The \emph{parametric form} for the solution space is
\[
  \left\{ (1-2x_2,x_2,-3x_4,x_4,3): x_2,x_4\in\R \right\}.
\]
Code:
\begin{verbatim}
\[
  \left\{ (1-2x_2,x_2,-3x_4,x_4,3): x_2,x_4\in\R \right\}.
\]
\end{verbatim}
The \emph{vector form} for the solution space is
\[
\left\{ 
    \left(\begin{array}{c}
      1\\0\\0\\0\\3
  \end{array} \right)
  +
  x_2
  \left(\begin{array}{r}
    -2\\1\\0\\0\\0 
  \end{array} \right)
  +
  x_4
  \left(\begin{array}{r}
    0\\0\\-3\\1\\0 
  \end{array} \right)
  :
  x_2,x_4\in\R
\right\}.
\]
Code:
\begin{verbatim}
\[
\left\{ 
  \left(\begin{array}{c}
      1\\0\\0\\0\\3
  \end{array} \right)
  +
  x_2
  \left(\begin{array}{r}
    -2\\1\\0\\0\\0 
  \end{array} \right)
  +
  x_4
  \left(\begin{array}{r}
    0\\0\\-3\\1\\0 
  \end{array} \right)
  :
  x_2,x_4\in\R
\right\}.
\]
\end{verbatim}
\end{document}


