\documentclass[12pt]{article}

\usepackage{systeme}

\usepackage{amsmath}
\usepackage{amssymb}

%\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{Math 201 Lecture for Monday, Week 1}
\bigskip

\centerline{\bf Solving systems of linear equations}
\medskip


{\bf First goal:} solve systems of linear equations using Gaussian elimination.
\medskip

{\bf Note:} In all of the examples today, we will work over the real numbers.
\medskip

{\bf Example 1.} Solve the following system of two linear equations:
\[
  \sysdelim..
  \systeme{3x+2y=5,2x-y=1.}
\]
{\sc solution:} We find a solution by eliminating variables.  To get rid
of~$y$, multiply the second equation through by~$2$ (which does not change the
set of solutions), and add the equations:
\[
\begin{array}{rl}
  3x+2y&=5\\
  4x-2y&=2\\\hline
  7x\hphantom{ +2yy}&=7
\end{array}
\quad\Rightarrow\quad 
x=1.
\]
Now substitute~$x=1$ back into either of the equations, and solve for~$y$:
\[
  x=1\text{ and }3x+2y=5\quad\Rightarrow\quad y=1.
\]
So there is a unique solution:~$x=y=1$.\hfill~$\Box$

Here is the geometric picture:

\begin{center}
\begin{tikzpicture}[scale=0.8] 
  \begin{axis}[  
      %title style={at={(0.5,0)},anchor=north,yshift=-30}, 
      %title={Solving a system of two linear equations.}, 
      axis lines = middle, 
      axis line style={->}, 
      axis equal image, 
      xtick distance=1,
      ytick distance=1,
      xticklabels={},
      yticklabels={},
      %xmin=-0.4, 
      xmax=6, 
      %ymin=-0.2, 
      %ymax=16, 
    ] 
    %\fill[blue] (axis cs: 1,1) circle (2pt);   
    %\fill[draw=black,fill=white] (axis cs:1,0) circle (2pt);   
    \addplot[domain=-0.4:2,thick, blue] {5/2-3*x/2}; 
    \addplot[domain=-0.4:2,thick, red] {2*x-1}; 
    \node[blue] at (axis cs:2.6,0.5) {$3x+2y=5$};
    \node[red] at (axis cs:2.9,2.5) {$2x-y=1$};
    \draw[<-,dotted,thick] (axis cs:1.2,1.05)--(axis cs: 3,1.5);
    \node at (axis cs:4.4,1.5) {solution: $(1,1)$};
  \end{axis} 
\end{tikzpicture} 
\end{center}

{\bf Remark.} Note that the line given by~$3x+2y=5$ is perpendicular to the
vector~$(3,2)$ and the line given by~$2x-y=1$ is perpendicular to~$(2,-1)$.  Do
you see the relationship between these vectors and the coefficients of the
equations?  We will get back to this latter in the course.
\medskip

\medskip

{\bf Example 2.} System:
\[
  \sysdelim..
  \systeme{-9x-3y=6,3x+y=-2.}
\]
Since the first equation is a scalar multiple of the second, they have the
same solution set.  In this case, the solution set is infinite:
\[
  \left\{ (x,y):y=-3x-2 \right\}.
\]

Geometry:

\begin{center}
\begin{tikzpicture}[scale=0.8] 
  \begin{axis}[  
      %title style={at={(0.5,0)},anchor=north,yshift=-30}, 
      %title={Solving a system of two linear equations.}, 
      axis lines = middle, 
      axis line style={->}, 
      axis equal image, 
      xtick distance=1,
      ytick distance=1,
      xticklabels={},
      yticklabels={},
      %xmin=-0.4, 
      xmax=5.8, 
      %ymin=-0.2, 
      %ymax=16, 
    ] 
    %\fill[blue] (axis cs: 1,1) circle (2pt);   
    %\fill[draw=black,fill=white] (axis cs:1,0) circle (2pt);   
    \addplot[domain=-1.6:1,thick, blue] {-2-3*x}; 
    \node[blue] at (axis cs:2.5,-2.5) {$3x+y=-2$};
    \node[blue] at (axis cs:3.6,-3.3) {(or $-9x-3y=6$)};
    %\node[red] at (axis cs:2.9,2.5) {$2x-y=1$};
  \end{axis} 
\end{tikzpicture} 
\end{center}
\medskip

{\bf Example 3.} System:
\[
  \sysdelim..
  \systeme{-9x-3y=6,3x+y=-1.}
\]
Dividing through by~$-3$, we see that the set of solutions to the first equation
is the same as the set of solutions to the equation
\[
  3x+y=-2.
\]
It is clear, though, that if~$(x,y)$ satisfies~$3x+y=-2$, it cannot also
satisfy the second equation in the system,~$3x+y=1$.  So the two equations in
the system are incompatible, and the solution set is empty.
\medskip

The lines defined by the two equations are parallel:
\begin{center}
\begin{tikzpicture}[scale=0.8] 
  \begin{axis}[  
      %title style={at={(0.5,0)},anchor=north,yshift=-30}, 
      %title={Solving a system of two linear equations.}, 
      axis lines = middle, 
      axis line style={->}, 
      axis equal image, 
      xtick distance=1,
      ytick distance=1,
      xticklabels={},
      yticklabels={},
      xmin=-6, 
      xmax=6, 
      ymin=-5.9, 
      ymax=3.8, 
    ] 
    %\fill[blue] (axis cs: 1,1) circle (2pt);   
    %\fill[draw=black,fill=white] (axis cs:1,0) circle (2pt);   
    \addplot[domain=-2:1.8,thick, blue] {-2-3*x}; 
    \addplot[domain=-2:1.8,thick, red] {-1-3*x}; 
    \node[blue] at (axis cs:-3,-1.5) {$3x+y=-2$};
    \node[red] at (axis cs:2.9,-2.3) {$3x+y=-1$};
  \end{axis} 
\end{tikzpicture} 
\end{center}

{\bf Example 4.} System:
\[
  \sysdelim..
  \systeme{x+2y+z=0,x+z=4,x+y+2z=1.}
\]
We will use this example to illustrate the general method (called {\em Gaussian
  elimination}.

General idea: replace the set of equations with an equivalent set of equations
(i.e., having the same solutions set) but from which the set of solutions is
evident.  We find equivalent sets of equations by using the following:
\bigskip

{\color{blue} Row operations.} 
\begin{enumerate}
  \item\label{01wedrow1} multiply an equation by a nonzero scalar
  \item\label{01wedrow2} swap two equations
  \item\label{01wedrow3} add a multiple of one equation to another.
\end{enumerate}
  
The reader should stop now and convince themselves that the solution set is invariant
under these operations.

The good news is that these operations are all we need to solve any system of
linear equations.  We will illustrate with the system of three equations
displayed above.  We first introduce a convenient way of notating our system:
\[
  \sysdelim..
  \systeme{x+2y+z=0,x+z=4,x+y+2z=1.}
  \quad\rightsquigarrow\quad 
  \left(\begin{array}{ccc|c}
      1&2&1&0\\
      1&0&1&4\\
      1&1&2&1
  \end{array} \right).
\]
The matrix on the right is called the {\em augmented matrix} for our system of
linear equations. At any point in the following string of calculations, one
could convert back from an augmented matrix to its corresponding system of
linear equations, and that system would be equivalent to our orignal system.

In the following calculation,~$r_i$ denotes the~$i$-th row of the augmented
matrix, and we introducing some notation for describing the row operations
leading from one matrix to the next.

\begin{align*}
  &
  \left(\begin{array}{ccc|c}
      1&2&1&0\\
      1&0&1&4\\
      1&1&2&1
  \end{array} \right)
  \xrightarrow[r_3\to r_3-r_1]{r_2\to r_2-r_1}
  \left(\begin{array}{rrr|r}
      1&2&1&0\\
      0&-2&0&4\\
      0&-1&1&1
  \end{array} \right)
  \xrightarrow{r_2\to -\tfrac{1}{2}r_2}
  \left(\begin{array}{rrr|r}
      1&2&1&0\\
      0&1&0&-2\\
      0&-1&1&1
  \end{array} \right)
  \xrightarrow{r_3\to r_3+r_2}
  \\[10pt]
  &
  \left(\begin{array}{rrr|r}
      1&2&1&0\\
      0&1&0&-2\\
      0&0&1&-1
  \end{array} \right)
  \xrightarrow{r_1\to -2r_2+r_1}
  \left(\begin{array}{rrr|r}
      1&0&1&4\\
      0&1&0&-2\\
      0&0&1&-1
  \end{array} \right)
  \xrightarrow{r_1\to -r_3+r_1}
  \left(\begin{array}{rrr|r}
      1&0&0&5\\
      0&1&0&-2\\
      0&0&1&-1
  \end{array} \right).
\end{align*}

The last augmented matrix is in {\em reduced echelon form}.  We will define this
term carefully later.  Translate the lasted augmented matrix back into a system
of equations to get a system that is equivalent to the original system, but from
which the set of solutions is evident:
\begin{align*}
  x&=\hphantom{-}5\\
y&=-2\\
z&=-1.
\end{align*}
So there is a unique solution in this case. 
Now for the most {\bf important step}: check your solution works for the
original system:
\begin{align*}
  5+2(-2)+(-1)&=0\\
  5\hphantom{\  +2(-2)}+(-1)&=4\\
  5+(-2)+2(-1)&=1.
\end{align*}
That works.  (We will suppress checking solutions throughout the result of this
lecture, but in practice, you should always check your solutions.)
\medskip

{\bf Example 5.} The following system is a slight modification of the previous
one:
\[
  \sysdelim..
  \systeme{x+2y+z=0,x+z=4,x+y+z=1.}
\]
Converting to the corresponding augmented matrix and performing a sequence of
row operations similar to those in the previous example gives
\[
  \left(\begin{array}{ccc|c}
      1&2&1&0\\
      1&0&1&4\\
      1&1&1&1
  \end{array} \right)
  \quad\rightsquigarrow\quad 
  \left(\begin{array}{ccc|c}
      1&0&1&4\\
      0&1&0&-2\\
      0&0&0&-1
  \end{array} \right).
\]
Converting back to equations gives the equivalent system:
\begin{align*}
x+z&=4\\
y&=-2\\
0&=-1
\end{align*}
which clearly has no solutions.  Thus, our original system has no solutions.
\medskip

{\bf Example 6.} System:
\[
  \sysdelim..
  \systeme{x+2y+z=0,x+z=4,x+y+z=2.}
\]
Converting to the corresponding augmented matrix and performing a sequence of
row operations similar to those in the previous example gives
\[
  \left(\begin{array}{ccc|c}
      1&2&1&0\\
      1&0&1&4\\
      1&1&1&2
  \end{array} \right)
  \quad\rightsquigarrow\quad 
  \left(\begin{array}{ccc|c}
      1&0&1&4\\
      0&1&0&-2\\
      0&0&0&0
  \end{array} \right).
\]
Equivalent system:
\begin{align*}
x+z&=4\\
y&=-2\\
0&=0
\end{align*}
We now get an infinite set of solutions:
\[
  \left\{ (x,y,z):x+z=4\text{ and }y=-2 \right\}= \left\{ (x,-2,4-x): x\in \R \right\}.
\]
This is a line in~$3$-space.
\begin{figure}[ht]
  \centering
  \includegraphics[height=4.5in]{images/01mon.png}
  \caption{The line $\left\{ (x,-2,4-x): x\in \R \right\}$.}
  \label{fig:line}
\end{figure}
\end{document}


