# Difference between revisions of "Assignment 2 - 2010 - Solution/Question 1"

 Back to all questions Next step: Question 2 →

# Question 1 [1]

The Gauss elimination method is an effective algorithm for solving a set of linear equations, $$Ax = b$$. Solve this set of equations by hand, showing the steps taken.

$\begin{split}\left\{\begin{array}{r} x_1 + x_2 + x_3 + x_4 = 0\hphantom{-}\\ x_1 - 2x_2 - 2x_3 - 2x_4 = 4\hphantom{-}\\ x_1 + 4x_2 - 4x_3 + x_4 = 2\hphantom{-}\\ x_1 - 5x_2 - 5x_3 - 3x_4 = -4\\ \end{array}\right.\\\end{split}$

## Solution

We start by converting the system of equations to the form $$Ax = b$$.

$\begin{split}\begin{array}{ccccccccc} x_{1} & + & x_{2} & + & x_{3} & + & x_{4} & = & 0\hphantom{-}\\ x_{1} & - & 2x_{2} & - & 2x_{3} & - & 2x_{4} & = & 4\hphantom{-}\\ x_{1} & + & 4x_{2} & - & 4x_{3} & + & x_{4} & = & 2\hphantom{-}\\ x_{1} & - & 5x_{2} & - & 5x_{3} & - & 3x_{4} & = & -4\\ \end{array} \;\; \Longrightarrow \;\; \left[\begin{array}{cccc} 1 & 1 & 1 & 1\\ 1 & -2 & -2 & -2\\ 1 & 4 & -4 & 1\\ 1 & -5 & -5 & -3\\ \end{array} \right] \left[\begin{array}{c} x_{1}\\ x_{2}\\ x_{3}\\ x_{4}\\ \end{array} \right] = \left[\begin{array}{c} 0\\ 4\\ 2\\ -4\\ \end{array} \right]\end{split}$

Forward elimination

Recall that the basic algorithm for the forward elimination step of naive Gauss elimination is:

1. Divide the current row $$i$$ by the $$i\text{th}$$ diagonal element.
2. Eliminate all elements in the $$i\text{th}$$ column below the $$i\text{th}$$ diagonal element (i.e. rows $$j$$ > $$i$$) by subtracting $$n$$ times the $$i\text{th}$$ row from the $$j\text{th}$$ row (where $$n$$ is the current value of value in the $$i\text{th}$$ column of the $$j\text{th}$$ row, i.e. element ( $$i$$ , $$j$$ )). Do not forget to subtract the $$b$$ vector elements as well.
3. Move to the next row.
4. Repeat steps 1 - 3 until the A matrix is upper triangular (i.e. you have eliminated all elements below the diagonal).

Therefore our first step is to divide row 1 by the it's diagonal element (in this case the first value), which is equal to 1 (easy enough)

$\begin{split}\left[\begin{array}{rrrr} \frac{1}{(1)} & \frac{1}{(1)} & \frac{1}{(1)} & \frac{1}{(1)}\\ 1 & -2 & -2 & -2\\ 1 & 4 & -4 & 1\\ 1 & -5 & -5 & -3\\ \end{array} \right] \left[\begin{array}{r} x_{1}\\ x_{2}\\ x_{3}\\ x_{4}\\ \end{array} \right] = \left[\begin{array}{r} \frac{0}{(1)}\\ 4\\ 2\\ -4\\ \end{array} \right] \;\; \Longrightarrow \;\; \left[\begin{array}{rrrr} 1 & 1 & 1 & 1\\ 1 & -2 & -2 & -2\\ 1 & 4 & -4 & 1\\ 1 & -5 & -5 & -3\\ \end{array} \right] \left[\begin{array}{r} x_{1}\\ x_{2}\\ x_{3}\\ x_{4}\\ \end{array} \right] = \left[\begin{array}{r} 0\\ 4\\ 2\\ -4\\ \end{array} \right]\end{split}$

Next we subtract row 1 from rows 2, 3, and 4 using $$n$$ values equal to the coefficients in the first column of each row. In thise case the all the column coefficients are equal to 1, which makes our lives easy again.

$\begin{split}\left[\begin{array}{rrrr} 1 & 1 & 1 & 1\\ 1 - (1)(1) & -2 - (1)(1) & -2 - (1)(1) & -2 - (1)(1)\\ 1 - (1)(1) & 4 - (1)(1) & -4 - (1)(1) & 1 - (1)(1)\\ 1 - (1)(1) & -5 - (1)(1) & -5 - (1)(1) & -3 - (1)(1)\\ \end{array} \right] \left[\begin{array}{r} x_{1}\\ x_{2}\\ x_{3}\\ x_{4}\\ \end{array} \right] = \left[\begin{array}{r} 0\\ 4 - (1)(0)\\ 2 - (1)(0)\\ -4 - (1)(0)\\ \end{array} \right] \;\; \Longrightarrow \;\; \left[\begin{array}{rrrr} 1 & 1 & 1 & 1\\ 0 & -3 & -3 & -3\\ 0 & 3 & -5 & 0\\ 0 & -6 & -6 & -4\\ \end{array} \right] \left[\begin{array}{r} x_{1}\\ x_{2}\\ x_{3}\\ x_{4}\\ \end{array} \right] = \left[\begin{array}{r} 0\\ 4\\ 2\\ -4\\ \end{array} \right]\end{split}$

Having eliminated all elements in the first column, we move to the second row/column. Once again we start by dividing the current row (row 2) by its diagonal element.

$\begin{split}\left[\begin{array}{rrrr} 1 & 1 & 1 & 1\\ 0 & \frac{-3}{(-3)} & \frac{-3}{(-3)} & \frac{-3}{(-3)}\\ 0 & 3 & -5 & 0\\ 0 & -6 & -6 & -4\\ \end{array} \right] \left[\begin{array}{r} x_{1}\\ x_{2}\\ x_{3}\\ x_{4}\\ \end{array} \right] = \left[\begin{array}{r} 0\\ \frac{4}{(-3)}\\ 2\\ -4\\ \end{array} \right] \;\; \Longrightarrow \;\; \left[\begin{array}{rrrr} 1 & 1 & 1 & 1\\ 0 & 1 & 1 & 1\\ 0 & 3 & -5 & 0\\ 0 & -6 & -6 & -4\\ \end{array} \right] \left[\begin{array}{r} x_{1}\\ x_{2}\\ x_{3}\\ x_{4}\\ \end{array} \right] = \left[\begin{array}{r} 0\\ -4/3\\ 2\\ -4\\ \end{array} \right]\end{split}$

Next we eliminate all elements below row 2 in column 2 by subtracting 3 times row 2 from row 3 and (-6) times row 2 from row 4.

$\begin{split}\left[\begin{array}{rrrr} 1 & 1 & 1 & 1\\ 0 & 1 & 1 & 1\\ 0 & 3 - (3)(1) & -5 - (3)(1) & 0 - (3)(1)\\ 0 & -6 - (-6)(1) & -6 - (-6)(1) & -4 - (-6)(1)\\ \end{array} \right] \left[\begin{array}{r} x_{1}\\ x_{2}\\ x_{3}\\ x_{4}\\ \end{array} \right] = \left[\begin{array}{r} 0\\ -4/3\\ 2 - (3)(-4/3)\\ -4 - (-6)(-4/3)\\ \end{array} \right] \;\; \Longrightarrow \;\; \left[\begin{array}{rrrr} 1 & 1 & 1 & 1\\ 0 & 1 & 1 & 1\\ 0 & 0 & -8 & -3\\ 0 & 0 & 0 & 2\\ \end{array} \right] \left[\begin{array}{r} x_{1}\\ x_{2}\\ x_{3}\\ x_{4}\\ \end{array} \right] = \left[\begin{array}{r} 0\\ -4/3\\ 6\\ -12\\ \end{array} \right]\end{split}$

Moving to row 3 we notice that the previous elimination step removed all values below the 3rd column diagonal. Therefore all we do is divide row 3 by its diagonal element and move on.

$\begin{split}\left[\begin{array}{rrrr} 1 & 1 & 1 & 1\\ 0 & 1 & 1 & 1\\ 0 & 0 & \frac{-8}{(-8)} & \frac{-3}{(-8)}\\ 0 & 0 & 0 & 2\\ \end{array} \right] \left[\begin{array}{r} x_{1}\\ x_{2}\\ x_{3}\\ x_{4}\\ \end{array} \right] = \left[\begin{array}{r} 0\\ -4/3\\ \frac{6}{(-8)}\\ -12\\ \end{array} \right] \;\; \Longrightarrow \;\; \left[\begin{array}{rrrr} 1 & 1 & 1 & 1\\ 0 & 1 & 1 & 1\\ 0 & 0 & 1 & 3/8\\ 0 & 0 & 0 & 2\\ \end{array} \right] \left[\begin{array}{r} x_{1}\\ x_{2}\\ x_{3}\\ x_{4}\\ \end{array} \right] = \left[\begin{array}{r} 0\\ -4/3\\ -3/4\\ -12\\ \end{array} \right]\end{split}$

Similarly, since row 4 is the final row of our matrix, there exist no elements under the diagonal to eliminate so we simply divide through by the row diagonal element and then move on to perform backwards substitution.

$\begin{split}\left[\begin{array}{rrrr} 1 & 1 & 1 & 1\\ 0 & 1 & 1 & 1\\ 0 & 0 & 1 & 3/8\\ 0 & 0 & 0 & \frac{2}{(2)}\\ \end{array} \right] \left[\begin{array}{r} x_{1}\\ x_{2}\\ x_{3}\\ x_{4}\\ \end{array} \right] = \left[\begin{array}{r} 0\\ -4/3\\ -3/4\\ \frac{-12}{(2)}\\ \end{array} \right] \;\; \Longrightarrow \;\; \left[\begin{array}{rrrr} 1 & 1 & 1 & 1\\ 0 & 1 & 1 & 1\\ 0 & 0 & 1 & 3/8\\ 0 & 0 & 0 & 1\\ \end{array} \right] \left[\begin{array}{r} x_{1}\\ x_{2}\\ x_{3}\\ x_{4}\\ \end{array} \right] = \left[\begin{array}{r} 0\\ -4/3\\ -3/4\\ -6\\ \end{array} \right]\end{split}$

Backward substitution

Recall that the basic algorithm for the backwards substitution step of naive Gauss elimination is:

1. Eliminate all elements in the $$i\text{th}$$ column above the $$i\text{th}$$ diagonal element (i.e. rows $$j$$ < $$i$$) by subtracting $$n$$ times the $$i\text{th}$$ row from the $$j\text{th}$$ row (where $$n$$ is the current value of value in the $$i\text{th}$$ column of the $$j\text{th}$$ row, i.e. element ( $$i$$ , $$j$$ )). Do not forget to subtract the $$b$$ vector elements as well.
2. Move to the next row.
3. Repeat steps 1 - 2 until the A matrix becomes the identity matrix (i.e. you have eliminated all elements above the diagonal).

Therefore we start by subtracting 1 times row 4 from row 1, 1 times row 4 from row 2, and (3/8) times row 4 from row 3.

$\begin{split}\left[\begin{array}{rrrr} 1 & 1 & 1 & 1 - (1)(1)\\ 0 & 1 & 1 & 1 - (1)(1)\\ 0 & 0 & 1 & 3/8 - (3/8)(1)\\ 0 & 0 & 0 & 1\\ \end{array} \right] \left[\begin{array}{r} x_{1}\\ x_{2}\\ x_{3}\\ x_{4}\\ \end{array} \right] = \left[\begin{array}{r} 0 - (1)(-6)\\ -4/3 - (1)(-6)\\ -3/4 - (3/8)(-6)\\ -6\\ \end{array} \right] \;\; \Longrightarrow \;\; \left[\begin{array}{rrrr} 1 & 1 & 1 & 0\\ 0 & 1 & 1 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 1\\ \end{array} \right] \left[\begin{array}{r} x_{1}\\ x_{2}\\ x_{3}\\ x_{4}\\ \end{array} \right] = \left[\begin{array}{r} 6\\ 14/3\\ 3/2\\ -6\\ \end{array} \right]\end{split}$

Moving to next row, in order to eliminate all elements above the 3rd diagonal element we subtract 1 times row 3 from row 1 and 1 times row 3 from row 2.

$\begin{split}\left[\begin{array}{rrrr} 1 & 1 & 1 - (1)(1) & 0\\ 0 & 1 & 1 - (1)(1) & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 1\\ \end{array} \right] \left[\begin{array}{r} x_{1}\\ x_{2}\\ x_{3}\\ x_{4}\\ \end{array} \right] = \left[\begin{array}{r} 6 - (1)(3/2)\\ 14/3 - (1)(3/2)\\ 3/2\\ -6\\ \end{array} \right] \;\; \Longrightarrow \;\; \left[\begin{array}{rrrr} 1 & 1 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 1\\ \end{array} \right] \left[\begin{array}{r} x_{1}\\ x_{2}\\ x_{3}\\ x_{4}\\ \end{array} \right] = \left[\begin{array}{r} 9/2\\ 19/6\\ 3/2\\ -6\\ \end{array} \right]\end{split}$

Finally, we move to row 2 and eliminate all elements above the 2nd diagonal element by subtracting 1 times row 2 from row 1.

$\begin{split}\left[\begin{array}{rrrr} 1 & 1 - (1)(1) & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 1\\ \end{array} \right] \left[\begin{array}{r} x_{1}\\ x_{2}\\ x_{3}\\ x_{4}\\ \end{array} \right] = \left[\begin{array}{r} 9/2 - (1)(19/6)\\ 19/6\\ 3/2\\ -6\\ \end{array} \right] \;\; \Longrightarrow \;\; \left[\begin{array}{rrrr} 1 & 1 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 1\\ \end{array} \right] \left[\begin{array}{r} x_{1}\\ x_{2}\\ x_{3}\\ x_{4}\\ \end{array} \right] = \left[\begin{array}{r} 4/3\\ 19/6\\ 3/2\\ -6\\ \end{array} \right]\end{split}$

Therefore the solution, arrived at using naive Gauss elimination, is:

$\begin{split}\left[\begin{array}{r} x_{1}\\ x_{2}\\ x_{3}\\ x_{4}\\ \end{array} \right] = \left[\begin{array}{r} 4/3\\ 19/6\\ 3/2\\ -6\\ \end{array} \right]\end{split}$

 Back to all questions Next step: Question 2 →