Gauss elimination method with matrix representation tutorial

Gauss elimination using matrixIn previous sections we’ve talked about Gauss elimination method and considered some examples. Today we have one more systems of linear equations to solve, but this time we’ll apply matrix representation for systems of linear equations:

\left\{\begin{aligned}2x_1+4x_2-3x_3+2x_4=0\\x_1-2x_2+5x_3+2x_4=2\\2x_2-4x_3+5x_4=-1\\-2x_3+x_4=-3 \end{aligned}\right.

Here’s video version of this example, take a look!

Often it’s convenient to make transformations with the system using its matrix. Especially if we have system of order higher than 3. This means that instead of the initial system we work with matrix comprised by its coefficients:

A=\begin {pmatrix} 2&4&-3 &2 \\1& -2&5 &2 \\0& 2&-4 &5 \\0&0&-2 &1 \end {pmatrix}, \vec{b}=\begin{pmatrix}0\\2\\-1\\3\end{pmatrix},\vec{x}=\begin{pmatrix}x_1\\x_2\\x_3\\x_4\end{pmatrix},  \tilde{A}=\begin{pmatrix}2&4&-3 &2&|&0 \\1& -2&5 &2&|&2 \\0& 2&-4 &5&|&-1 \\0&0&-2 &1&|&-3 \end{pmatrix}

Our system is represented then in the following way:

A \vec{x}=\vec{b}

The idea of solving is the same, we intend to obtain our system in triangular (or echelon) form. For convenience we are to transform matrix of the system, which is exactly the same thing, it only involves more compact form of representation. Note, that we can swap rows of matrix, add or subtract them, multiply or divide by real non-zero number.

As we have non-zero right part of the system, i.e. our system is not homogeneous, we ought to transform matrix \tilde{A}  containing non-zero right parts instead of A. This new matrix is called the augmented (or extended) matrix of the given system.

Ok, let’s begin. So we’re now working with this matrix:

\tilde{A}=\begin{pmatrix}2&4&-3 &2&|&0 \\1& -2&5 &2&|&2 \\0& 2&-4 &5&|&-1 \\0&0&-2 &1&|&-3 \end{pmatrix}

First let’s swap the first and the second rows of our matrix in order to obtain x_1 with coefficient 1 in the first row. Thus, we obtain:

\tilde{A}=\begin{pmatrix}1& -2&5 &2&|&2 \\2&4&-3 &2&|&0 \\0& 2&-4 &5&|&-1 \\0&0&-2 &1&|&-3 \end{pmatrix}

Our second step is to eliminate x_1 from all the equations of our systems except the first. In terms of matrix \tilde{A} this means that we need to get zeros in the first column except the first element. Then perform the same thing for other variables to get matrix in echelon form at the end. So first we subtract the first row multiplied by 2 from the second. Altered matrix look like follows:

\tilde{A}=\begin{pmatrix}1& -2&5 &2&|&2 \\0&8 &-13&-2&|&-4 \\0& 2&-4 &5&|&-1 \\0&0&-2 &1&|&-3 \end{pmatrix}

Next subtract the third row multiplied by 4 from the second:

\tilde{A}=\begin{pmatrix}1& -2&5 &2&|&2 \\0&0 &3&-22&|&0 \\0& 2&-4 &5&|&-1 \\0&0&-2 &1&|&-3 \end{pmatrix}

Now let’s swap the third and the second rows:

\tilde{A}=\begin{pmatrix}1& -2&5 &2&|&2  \\0& 2&-4 &5&|&-1\\0&0 &3&-22&|&0 \\0&0&-2 &1&|&-3 \end{pmatrix}

Divide the second row by 2:

\tilde{A}=\begin{pmatrix}1& -2&5 &2&|&2  \\0& 1&-2 &\frac{5}{2}&|&-\frac{1}{2}\\0&0 &3&-22&|&0 \\0&0&-2 &1&|&-3 \end{pmatrix}

Add the last row to the third:

\tilde{A}=\begin{pmatrix}1& -2&5 &2&|&2  \\0& 1&-2 &\frac{5}{2}&|&-\frac{1}{2}\\0&0 &1&-21&|&-3 \\0&0&-2 &1&|&-3 \end{pmatrix}

Add the third row multiplied by 2 to the forth:

\tilde{A}=\begin{pmatrix}1& -2&5 &2&|&2  \\0& 1&-2 &\frac{5}{2}&|&-\frac{1}{2}\\0&0 &1&-21&|&-3 \\0&0&0 &-41&|&-9 \end{pmatrix}

Now we have our augmented matrix (and hence the system) in triangular form. So we can find all unknowns by reverse course of Gauss method.

Let’s for convenience write our system in usual form:

\left\{ \begin{aligned}x_1-2x_2+5x_3+2x_4=2\\x_2-2x_3+\frac{5}{2}x_4=-\frac{1}{2}\\x_3-21x_4=-3\\-41x_4=-9 \end{aligned}\right.

In the last equation we have only x_4 and the free term. Starting from the bottom, we calculate all the unknowns gradually and finally get the answer:

\left\{ \begin{aligned}x_1=-\frac{88}{41}\\x_2=\frac{89}{41}\\x_3=\frac{66}{41}\\x_4=\frac{9}{41} \end{aligned}\right.

Check it by substitution into the initial system. By the way, you can do the checking by applying matrix multiplication. Our system can be represented as follows:

A \vec{x}=\vec{b}


\begin{pmatrix} 2&4&-3 &2 \\1& -2&5 &2 \\0& 2&-4 &5 \\0&0&-2 &1 \end{pmatrix} \cdot \begin{pmatrix} -88/41\\ 89/41\\ 66/41\\ 9/41\end{pmatrix}=\begin{pmatrix}0\\2\\-1\\3 \end{pmatrix}

Simplification gives:

\frac{1}{41} \begin{pmatrix} 2&4&-3 &2 \\1& -2&5 &2 \\0& 2&-4 &5 \\0&0&-2 &1 \end{pmatrix} \cdot \begin{pmatrix} -88\\ 89\\ 66\\ 9\end{pmatrix}=\begin{pmatrix}0\\2\\-1\\3 \end{pmatrix}

All you need to do is to multiply two matrices in the left part and verify if this equality holds. If you’re having troubles with multiplication of matrices go through our tutorial on basic matrix operations. Online math calculators are also very helpful. Perform matrix operations carefully when doing homework and always do the checking, thus you’ll get it all correct.

Filed under Math.
0 0 votes
Article Rating
Inline Feedbacks
View all comments
Brendon Gerhardt
Brendon Gerhardt
7 years ago

hi! you actually helped me out with summer assignment. done it in the last minute with help of this tutorial. thanks guys!

Gaussian elimination method – case of indefinite system
7 years ago

[…] previous sections you can find theoretical background and examples including application of matrix representation and example of linear system having no solutions. As we already said, if you’re solving […]