% This is lecture no. 6 of MH1200/: Linear Algebra I.

\chapter{Counting Solutions}%
\label{cha:counting_solutions}

If we wish to know how many solutions there are to a system of linear equations, we need only look at a row echelon form of the augmented matrix of the system.

\begin{thrm}
	The Three Possibilities for the Set of Solutions.

	Consider a system of linear equations.
	There are exactly three possibilities for the set of solutions:
	\begin{enumerate}
		\item The system has no solutions. (Inconsistent System)
			\item The system has exactly one solution.
				\item The system has infinitely many solutions.
	\end{enumerate}
\end{thrm}

Consider a system of linear equations and let $M$ denote a row echelon form of its augmented matrix.

\bigbreak
Step 1:
Check whether the system is consistent.
Look at the last non-zero row of $M$.
The system is inconsistent if and only if it is of the following form:
\[
\begin{bmatrix}[ccc|c]
	* & \ldots & * & * \\
	* & \ldots & * & * \\
	0 & \ldots & 0 & \neq 0 \\
	0 & \ldots & 0 & 0 \\
	\vdots & \ddots & \vdots & \vdots \\
	0 & \ldots & 0 & 0 \\
\end{bmatrix}
.\]

Notice that the third row is \textbf{inconsistent}.
Therefore the matrix is inconsistent and has no solutions.
In the event the augmented matrix in row echelon form is not of this form, then the system has solutions because the matrix $M$ is in row echelon form, so back-substitution will definitely provide solutions (even if the result is heavily parameterised).

\bigbreak
Step 2:
Assuming the system is consistent, check whether it has one or infinitely many solutions.
The system will have infinitely many solutions if the following conditions are true:
\begin{itemize}
	\item There is at least one column in $M$ without a leading entry.
		\item There are more variables in the system than non-zero rows in $M$.
\end{itemize}

\begin{exmp}
	If a linear system has the following augmented matrix:
	\[
	\begin{bmatrix}[ccc|c]
		1 & 1 & 2 & 5 \\
		0 & -1/2 & 4 & 0 \\
		0 & 0 & 6 & 1 \\
	\end{bmatrix}
	.\]
	How many solutions does it have?

	\bigbreak
	Last row is consistent, so either one or $\infty$ solutions.
	Non-zero rows are equal to number of columns, therefor only one solution.
\end{exmp}

\bigbreak
\begin{exmp}
	In the system below, the constant $b$ is viewed differently to the system variables $x,y, z$.
	Different choices of $b$ give different linear systems in $x,y,z$ which are the variables we then solve for:
	\begin{align*}
		x + 2y + z & = 1\\
		y + 2z & = 2\\
		(1-b^2)z & = b+1
	\end{align*}
	If we set $b=0$ :
	\begin{align*}
		x + 2y + z & = 1\\
		y + 2z & = 2\\
		z & = 1
	\end{align*}
	The system has one solution.
	If we set $b=-1$ :
	\begin{align*}
		x + 2y + z & = 1\\
		y + 2z & = 2\\
		0z & = 0
	\end{align*}
	The system has $\infty$ solutions.
	Determine the values of the constant $b$ so that the system of linear equations has:
	\begin{enumerate}
		\item No solution,
			\item A unique solution, and
				\item $\infty$ solutions.
	\end{enumerate}
	The system has the following augmented matrix:
	\[
	\begin{bmatrix}[ccc|c]
		1 & 2 & 1 & 1 \\
		0 & 1 & 2 & 2 \\
		0 & 0 & 1-b^2 & b+1 \\
	\end{bmatrix}
	.\]
	The entry:
	\[
	1-b^2
	.\]
	will be 0 if $b=1$ or $b=-1$, and it will be $\neq 0$ otherwise.
	The entry:
	\[
	b+1
	.\]
	will be 0 if $b=-1$, and it will be $\neq 0$ otherwise.
	Now we need to evaluate the key values of $b$.

	\bigbreak
	\noindent
	Case 1: $b=1$ :
	In this case the matrix has the pattern:
	\[
	\begin{bmatrix}[ccc|c]
		1 & 2 & 1 & 1 \\
		0 & 1 & 2 & 2 \\
		0 & 0 & 0 & 2 \\
	\end{bmatrix}
	.\]
	The bottom row is of the inconsistent form so there are no solutions.

	\bigbreak
	\noindent
	Case 2: $b=-1$ :
	In this case the matrix has the pattern:
	\[
	\begin{bmatrix}[ccc|c]
		1 & 2 & 1 & 1 \\
		0 & 1 & 2 & 2 \\
		0 & 0 & 0 & 0 \\
	\end{bmatrix}
	.\]
	There is a column without a leading entry.
	Thus the system has $\infty$ many solutions.

	\bigbreak
	\noindent
	Case 3: $b\neq1,-1$ :
	In this case the matrix has the pattern:
	\[
	\begin{bmatrix}[ccc|c]
		1 & 2 & 1 & 1 \\
		0 & 1 & 2 & 2 \\
		0 & 0 & \neq 0 & \neq 0 \\
	\end{bmatrix}
	.\]
	Every column has a leading entry.
	Thus the system has exactly 1 solution.
\end{exmp}

During the Gaussian elimination, sometimes you have to divide.
Make sure you do not divide by 0.

\bigbreak
\begin{exmp}
	Consider a system depending on some $b$.
	Imagine that somewhere during Gaussian elimination it looks like this:
	\[
	\begin{bmatrix}[cc|c]
		1 & 1 & 1 \\
		0 & b & 2 \\
		0 & b+1 & 0 \\
	\end{bmatrix}
	.\]
	The Gaussian elimination algorithm tell you to remove the $b+1$ term using the $b$-term via this move:
	\[
	\begin{bmatrix}[cc|c]
		1 & 1 & 1 \\
		0 & b & 2 \\
		0 & b+1 & 0 \\
	\end{bmatrix}
	\xrightarrow{R_3 \rightarrow \frac{b+1}{b}R_2}
	\begin{bmatrix}[cc|c]
		1 & 1 & 1 \\
		0 & b & 2 \\
		0 & 0 & \phi \\
	\end{bmatrix}
	.\]
	However, if $b=0$, then we have just divided by 0.
	The solution is to split the computation into two cases at this point:
	\begin{enumerate}
		\item The case where that entry is zero.
			\item The case where it is non-zero.
	\end{enumerate}
\end{exmp}

\bigbreak
\begin{exmp}
	consider the following system of linear equations which depends on two constants $a$ and $b$.
	determine the values of the constants $a$ and $b$ so that the system of linear equations:
	\begin{align*}
		x + y + z & = 5 \\
		ay + z & = 1 \\
		by + z & = 1
	\end{align*}
	has no solutions, a unique solution, and $\infty$ solutions.
	the system of linear equations corresponds to the following augmented matrix:
	\[
	\begin{bmatrix}[ccc|c]
		1 & 1 & 1 & 5 \\
		0 & a & 1 & 1 \\
		0 & b & 1 & 1 \\
	\end{bmatrix}
	.\]
	which is evidently not in row echelon form.
	the temptation is to do the following to achieve row echelon form:
	\[
	\begin{bmatrix}[ccc|c]
		1 & 1 & 1 & 5 \\
		0 & a & 1 & 1 \\
		0 & b & 1 & 1 \\
	\end{bmatrix}
	\xrightarrow{r_3 \rightarrow r_3-\frac{b}{a}r_2}
	\text{some invalid matrix}
	.\]
	the proper was is to evaluate what would happen to the denominator in the operation when it is 0.
	in the case that $a=0$ :
	\[
	\begin{bmatrix}[ccc|c]
		1 & 1 & 1 & 5 \\
		0 & 0 & 1 & 1 \\
		0 & b & 1 & 1 \\
	\end{bmatrix}
	.\]
	We would then do the following:
	\[
	\begin{bmatrix}[ccc|c]
		1 & 1 & 1 & 5 \\
		0 & 0 & 1 & 1 \\
		0 & b & 1 & 1 \\
	\end{bmatrix}
	\xrightarrow{R_2\leftrightarrow R_3}
	\begin{bmatrix}[ccc|c]
		1 & 1 & 1 & 5 \\
		0 & b & 1 & 1 \\
		0 & 0 & 1 & 1 \\
	\end{bmatrix}
	.\]
	In the case that $b=0$, the augmented matrix becomes:
	\[
	\begin{bmatrix}[ccc|c]
		1 & 1 & 1 & 5 \\
		0 & 0 & 1 & 1 \\
		0 & 0 & 1 & 1 \\
	\end{bmatrix}
	.\]
	Which is row equivalent to:
	\[
	\begin{bmatrix}[ccc|c]
		1 & 1 & 1 & 5 \\
		0 & 0 & 1 & 1 \\
		0 & 0 & 0 & 0 \\
	\end{bmatrix}
	.\]
	This matrix is in row echelon form, is consistent, and has a column without a leading entry.
	Therefore, in this case, there are $\infty$ solutions.
	In the case that $b\neq 0$, the augmented matrix becomes:
	\[
	\begin{bmatrix}[ccc|c]
		1 & 1 & 1 & 5 \\
		0 & \neq 0 & 1 & 1 \\
		0 & 0 & 1 & 1 \\
	\end{bmatrix}
	.\]
	This matrix is in row echelon form, is consistent, and every column contains a leading entry.
	Therefore, in this case, there is one solution.
	In the case that $a\neq 0$, the augmented matrix becomes:
	\[
	\begin{bmatrix}[ccc|c]
		1 & 1 & 1 & 5 \\
		0 & \neq 0 & 1 & 1 \\
		0 & b & 1 & 1 \\
	\end{bmatrix}
	.\]
	We then continue the Gaussian elimination algorithm:
	\[
	\begin{bmatrix}[ccc|c]
		1 & 1 & 1 & 5 \\
		0 & \neq 0 & 1 & 1 \\
		0 & b & 1 & 1 \\
	\end{bmatrix}
	\xrightarrow{R_3\rightarrow R_3-\frac{b}{a}R_2}
	\begin{bmatrix}[ccc|c]
		1 & 1 & 1 & 5 \\
		0 & \neq 0 & 1 & 1 \\
		0 & 0 & 1-b/a & 1-b/a\\
	\end{bmatrix}
	.\]
	In the case that $1-\frac{b}{a}=0$ :
	\[
	\begin{bmatrix}[ccc|c]
		1 & 1 & 1 & 5 \\
		0 & \neq 0 & 1 & 1 \\
		0 & 0 & 0 & 0 \\
	\end{bmatrix}
	.\]
	This matrix is in row echelon form, is consistent, and has a column without a leading entry.
	Therefore, in this case, there are $\infty$ solutions.
	In the case that $1-\frac{b}{a}\neq 0$ :
	\[
	\begin{bmatrix}[ccc|c]
		1 & 1 & 1 & 5 \\
		0 & \neq 0 & 1 & 1 \\
		0 & 0 & \neq 0 & \neq 0 \\
	\end{bmatrix}
	.\]
	This matrix is in row echelon form, is consistent, and every column has a leading entry.
	Therefore, in this case, there is 1 solution.

	\bigbreak
	The system of linear equations has solutions no matter what the values of $a$ and $b$ are.
	If $a=b$ then there are $\infty$ solutions.
	If $a\neq b$ then there is exactly one solution.

	\bigbreak
	Alternatively, we are going to do a column swap on the augmented matrix $C_2 \leftrightarrow C_3$ to make this easier to work with.
	We can do this, but we have to remember that it corresponds to the same system but with the variables inn a different order:
	\[
	\begin{bmatrix}[ccc|c]
		1 & 1 & 1 & 5 \\
		0 & a & 1 & 1 \\
		0 & b & 1 & 1 \\
	\end{bmatrix}
	\xrightarrow{C_2\leftrightarrow C_3}
	\begin{bmatrix}[ccc|c]
		1 & 1 & 1 & 5 \\
		0 & 1 & a & 1 \\
		0 & 1 & b & 1 \\
	\end{bmatrix}
	.\]
	We proceed with Gaussian elimination according to the algorithm:
	\[
	\begin{bmatrix}[ccc|c]
		1 & 1 & 1 & 5 \\
		0 & 1 & a & 1 \\
		0 & 1 & b & 1 \\
	\end{bmatrix}
	\xrightarrow{R_3\rightarrow R_3 -R_2}
	\begin{bmatrix}[ccc|c]
		1 & 1 & 1 & 5 \\
		0 & 1 & a & 1 \\
		0 & 0 & b-a & 0 \\
	\end{bmatrix}
	.\]
	there are clearly two cases:
	the case that $a=b$, and $a\neq b$.
	When $a=b$,
	the augmented matrix becomes:
	\[
	\begin{bmatrix}[ccc|c]
		1 & 1 & 1 & 5 \\
		0 & 1 & a & 1 \\
		0 & 0 & 0 & 0 \\
	\end{bmatrix}
	.\]
	And we see that there are infinitely many solutions.
	When $a\neq b$,
	the augmented matrix becomes:
	\[
	\begin{bmatrix}[ccc|c]
		1 & 1 & 1 & 5 \\
		0 & 1 & a & 1 \\
		0 & 0 & \neq 0 & 0 \\
	\end{bmatrix}
	.\]
	And we see that there is exactly one solution.
\end{exmp}
