## Using a matrix to represent a system

Consider the following system of linear equations: \begin{eqnarray} 2x_1 - x_2 & = & 0 \\ -x_1 + x_2 - 2x_3 & = &4\\ 3x_1 - 2x_2 + x_3 & = &-2 \\ \end{eqnarray}

We can save a lot of handwriting if we use matrices to capture everything we need to know in order to solve a system of linear equations. For example, the following matrix represents the system above: $\left[\begin{array}{ccc|c} 2 & -1 & 0 & 0 \\ -1 & 1 & -2 & 4 \\ 3 & -2 & 1 & -2 \end{array}\right]$ The first column corresponds to the variable $$x_1$$; the entries are the coefficients of $$x_1$$. The second column corresponds to the variable $$x_2$$. The third column correspond to the variable $$x_3$$. The fourth column corresponds to the values on right-hand side of each equation. (The vertical bar separating columns 1 to 3 from column 4 is optional.)

The matrix formed from the coefficients of the variables is called the coefficient matrix. Hence, the coefficient matrix for the system above is $$\left[\begin{array}{ccc} 2 & -1 & 0 \\ -1 & 1 & -2 \\ 3 & -2 & 1 \end{array}\right].$$ The matrix that represents the complete system is called the augmented matrix.

## Elementary row operations

We have seen the elementary operations for solving systems of linear equations. If we choose to work with augmented matrices instead, the elementary operations translate to the following elementary row operations:

1. Multiplying a row by a nonzero constant.

2. Adding a constant multiple of a row to another row.

3. Interchanging the positions of two rows.

### Example

Let $$A =\begin{bmatrix} 1 & 0 & 2 & 3 \\ -1 & 1 & 1 & 2 \\ 3 & -2 & 1 & 0 \end{bmatrix}$$.

• Multiplying the second row of $$A$$ by $$2$$, notated $$R_2 \leftarrow 2 R_2$$, gives the matrix $$\begin{bmatrix} 1 & 0 & 2 & 3 \\ -2 & 2 & 2 & 4 \\ 3 & -2 & 1 & 0 \end{bmatrix}$$.

• Adding $$-1$$ times the third row to the first row of $$A$$, notated $$R_1 \leftarrow R_1 + (-1)R_3$$ (or more simply $$R_1 \leftarrow R_1 -R_3$$), gives the matrix $$\begin{bmatrix} 1-3 & 0-(-2) & 2-1 & 3-0 \\ -1 & 1 & 1 & 2 \\ 3 & -2 & 1 & 0 \end{bmatrix}$$, which is $$\begin{bmatrix} -2 & 2 & 1 & 3 \\ -1 & 1 & 1 & 2 \\ 3 & -2 & 1 & 0 \end{bmatrix}$$.

• Interchanging the first and third rows of $$A$$, notated $$R_1 \leftrightarrow R_3$$ gives the matrix $$\begin{bmatrix} 3 & -2 & 1 & 0 \\ -1 & 1 & 1 & 2 \\ 1 & 0 & 2 & 3 \end{bmatrix}$$.

### Using the augmented matrix

We now see how solving the system at the top using elementary operations corresponds to transforming the augmented matrix using elementary row operations.

At the beginning, the system and the corresponding augmented matrix are:
 \begin{eqnarray} 2x_1 - x_2 & = & 0 \\ -x_1 + x_2 - 2x_3 & = &4\\ 3x_1 - 2x_2 + x_3 & = &-2 \\ \end{eqnarray} $\left[\begin{array}{ccc|c} 2 & -1 & 0 & 0 \\ -1 & 1 & -2 & 4 \\ 3 & -2 & 1 & -2 \end{array}\right]$

Multiplying the first equation by $$\frac{1}{2}$$ corresponds to multiplying the first row of the matrix by $$\frac{1}{2}$$, which is notated by $$R_1 \leftarrow \frac{1}{2} R_1$$. These operations result in:
 \begin{eqnarray} x_1 - \frac{1}{2}x_2 & = & 0 \\ -x_1 + x_2 - 2x_3 & = &4\\ 3x_1 - 2x_2 + x_3 & = &-2 \\ \end{eqnarray} $\left[\begin{array}{ccc|c} 1 & -\frac{1}{2} & 0 & 0 \\ -1 & 1 & -2 & 4 \\ 3 & -2 & 1 & -2 \end{array}\right]$

Then, we add the first equation to the second equation. This corresponds to adding the first row of the matrix to the second row of the matrix, which is notated by $$R_2 \leftarrow R_2 + R_1$$. We obtain
 \begin{eqnarray} x_1 - \frac{1}{2}x_2 & = & 0 \\ \frac{1}{2}x_2 - 2x_3 & = &4\\ 3x_1 - 2x_2 + x_3 & = &-2 \\ \end{eqnarray} $\left[\begin{array}{ccc|c} 1 & -\frac{1}{2} & 0 & 0 \\ 0 & \frac{1}{2} & -2 & 4 \\ 3 & -2 & 1 & -2 \end{array}\right]$

Next, we add $$-3$$ times the first equation to the third equation. This corresponds to adding $$-3$$ times the first row of the matrix to the third row of the matrix, which is notated by $$R_3 \leftarrow R_3 + (-3)R_1$$ or more simply $$R_3 \leftarrow R_3 - 3R_1$$. The result is
 \begin{eqnarray} x_1 - \frac{1}{2}x_2 & = & 0 \\ \frac{1}{2}x_2 - 2x_3 & = &4\\ - \frac{1}{2}x_2 + x_3 & = &-2 \\ \end{eqnarray} $\left[\begin{array}{ccc|c} 1 & -\frac{1}{2} & 0 & 0 \\ 0 & \frac{1}{2} & -2 & 4 \\ 0 & -\frac{1}{2} & 1 & -2 \end{array}\right]$

We continue by adding the second equation to the third equation. This corresponds to adding the second row of the matrix to the third row of the matrix, which is notated by $$R_3 \leftarrow R_3 + R_2$$. We obtain
 \begin{eqnarray} x_1 - \frac{1}{2}x_2 & = & 0 \\ \frac{1}{2}x_2 - 2x_3 & = &4\\ -x_3 & = &2 \\ \end{eqnarray} $\left[\begin{array}{ccc|c} 1 & -\frac{1}{2} & 0 & 0 \\ 0 & \frac{1}{2} & -2 & 4 \\ 0 & 0 & -1 & 2 \end{array}\right]$

Notice that from the third row, we can conclude that $$x_3 = -2$$. Using this fact, the second equation tells us that $$x_2 = 0$$. Now, the first equation tells us that $$x_1 = 0$$ and so we have found the unique solution to the system.

But let's continue the process by multiplying the third equation by $$-1$$. This corresponds to multiplying the third row of the matrix by $$-1$$ (notated by $$R_3 \leftarrow -R_3$$). The resulting matrix is $\left[\begin{array}{ccc|c} 1 & -\frac{1}{2} & 0 & 0 \\ 0 & \frac{1}{2} & -2 & 4 \\ 0 & 0 & 1 & -2 \end{array}\right]$ (What is the corresponding system of equations?)

After performing $$R_2 \leftarrow R_2 + 2 R_3$$, we get $\left[\begin{array}{ccc|c} 1 & -\frac{1}{2} & 0 & 0 \\ 0 & \frac{1}{2} & 0 & 0 \\ 0 & 0 & 1 & -2 \end{array}\right].$

Performing $$R_1 \leftarrow R_1 + R_2$$ gives $\left[\begin{array}{ccc|c} 1 & 0 & 0 & 0 \\ 0 & \frac{1}{2} & 0 & 0 \\ 0 & 0 & 1 & -2 \end{array}\right].$ Finally, performing $$R_2 \leftarrow 2 R_2$$ results in $\left[\begin{array}{ccc|c} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & -2 \end{array}\right].$ Now, this matrix corresponds to the system of linear equations with the first three columns consisting of the coefficients of the variables $$x_1,x_2$$, and $$x_3$$, respectively, and the last column consisting of the right-hand side values. Hence, the matrix represents the system \begin{eqnarray} x_1 & = & 0 \\ x_2 & = & 0 \\ x_3 & = & -2 \end{eqnarray} which basically tells us what the solution is.

Note that the coefficient matrix of this final system has 1's on the diagonal (from top left to bottom right) and 0's everywhere else. Any square matrix in this form is called an identity matrix.

In short, to solve a system of linear equations, one performs a sequence of elementary row operations on the augmented matrix until one obtains something that looks like the final matrix we have above. It turns out that we cannot always have the identity matrix appearing in the columns of the matrix that correspond to the variables. But we can always get the matrix down to a special form that will tell us what the solutions are without having to perform any more computations.

Finally, if $$A$$ and $$B$$ are matrices such that one can transform one to the other using elementary row operations, then $$A$$ and $$B$$ are said to be row equivalent.

## Exercises

1. Give the augmented matrix of the following systems.

1. $$\begin{array}{r} x - y = 1 \\ 2x + y = 5 \end{array}$$

2. $$\begin{array}{r} x - y + z = 1 \\ 2x + y - z = 2 \\ x + 2 y - 2z = 1 \end{array}$$

2. What is the result after performing $$R_2 \leftarrow R_2 + 2 R_1$$ to $$\begin{bmatrix} -1 & -1 & 1 \\ 2 & 1 & 2 \\ \end{bmatrix}$$?