## Solving a System of Linear Equations Using Matrices

We have seen how to write a system of equations with an augmented matrix, and then how to use row operations and back-substitution to obtain row-echelon form. Now, we will take row-echelon form a step farther to solve a 3 by 3 system of linear equations. The general idea is to eliminate all but one variable using row operations and then back-substitute to solve for the other variables.

### Example 6: Solving a System of Linear Equations Using Matrices

Solve the system of linear equations using matrices.

$\begin{array}{c}\begin{array}{l}\hfill \\ \hfill \\ x-y+z=8\hfill \end{array}\\ 2x+3y-z=-2\\ 3x - 2y - 9z=9\end{array}$

### Solution

First, we write the augmented matrix.

$\left[\begin{array}{rrr}\hfill 1& \hfill -1& \hfill 1\\ \hfill 2& \hfill 3& \hfill -1\\ \hfill 3& \hfill -2& \hfill -9\end{array}\text{ }|\text{ }\begin{array}{r}\hfill 8\\ \hfill -2\\ \hfill 9\end{array}\right]$

Next, we perform row operations to obtain row-echelon form.

$\begin{array}{rrrrr}\hfill -2{R}_{1}+{R}_{2}={R}_{2}\to \left[\begin{array}{rrrrrr}\hfill 1& \hfill & \hfill -1& \hfill & \hfill 1& \hfill \\ \hfill 0& \hfill & \hfill 5& \hfill & \hfill -3& \hfill \\ \hfill 3& \hfill & \hfill -2& \hfill & \hfill -9& \hfill \end{array}|\begin{array}{rr}\hfill & \hfill 8\\ \hfill & \hfill -18\\ \hfill & \hfill 9\end{array}\right]& \hfill & \hfill & \hfill & \hfill -3{R}_{1}+{R}_{3}={R}_{3}\to \left[\begin{array}{rrrrrr}\hfill 1& \hfill & \hfill -1& \hfill & \hfill 1& \hfill \\ \hfill 0& \hfill & \hfill 5& \hfill & \hfill -3& \hfill \\ \hfill 0& \hfill & \hfill 1& \hfill & \hfill -12& \hfill \end{array}|\begin{array}{rr}\hfill & \hfill 8\\ \hfill & \hfill -18\\ \hfill & \hfill -15\end{array}\right]\end{array}$

The easiest way to obtain a 1 in row 2 of column 1 is to interchange ${R}_{2}$ and ${R}_{3}$.

$\text{Interchange}{R}_{2}\text{and}{R}_{3}\to \left[\begin{array}{rrrrrrr}\hfill 1& \hfill & \hfill -1& \hfill & \hfill 1& \hfill & \hfill 8\\ \hfill 0& \hfill & \hfill 1& \hfill & \hfill -12& \hfill & \hfill -15\\ \hfill 0& \hfill & \hfill 5& \hfill & \hfill -3& \hfill & \hfill -18\end{array}\right]$

Then

$\begin{array}{l}\\ \begin{array}{rrrrr}\hfill -5{R}_{2}+{R}_{3}={R}_{3}\to \left[\begin{array}{rrrrrr}\hfill 1& \hfill & \hfill -1& \hfill & \hfill 1& \hfill \\ \hfill 0& \hfill & \hfill 1& \hfill & \hfill -12& \hfill \\ \hfill 0& \hfill & \hfill 0& \hfill & \hfill 57& \hfill \end{array}|\begin{array}{rr}\hfill & \hfill 8\\ \hfill & \hfill -15\\ \hfill & \hfill 57\end{array}\right]& \hfill & \hfill & \hfill & \hfill -\frac{1}{57}{R}_{3}={R}_{3}\to \left[\begin{array}{rrrrrr}\hfill 1& \hfill & \hfill -1& \hfill & \hfill 1& \hfill \\ \hfill 0& \hfill & \hfill 1& \hfill & \hfill -12& \hfill \\ \hfill 0& \hfill & \hfill 0& \hfill & \hfill 1& \hfill \end{array}|\begin{array}{rr}\hfill & \hfill 8\\ \hfill & \hfill -15\\ \hfill & \hfill 1\end{array}\right]\end{array}\end{array}$

The last matrix represents the equivalent system.

$\begin{array}{l}\text{ }x-y+z=8\hfill \\ \text{ }y - 12z=-15\hfill \\ \text{ }z=1\hfill \end{array}$

Using back-substitution, we obtain the solution as $\left(4,-3,1\right)$.

### Example 7: Solving a Dependent System of Linear Equations Using Matrices

Solve the following system of linear equations using matrices.

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

### Solution

Write the augmented matrix.

$\left[\begin{array}{rrr}\hfill -1& \hfill -2& \hfill 1\\ \hfill 2& \hfill 3& \hfill 0\\ \hfill 0& \hfill 1& \hfill -2\end{array}\text{ }|\text{ }\begin{array}{r}\hfill -1\\ \hfill 2\\ \hfill 0\end{array}\right]$

First, multiply row 1 by $-1$ to get a 1 in row 1, column 1. Then, perform row operations to obtain row-echelon form.

$-{R}_{1}\to \left[\begin{array}{rrrrrrr}\hfill 1& \hfill & \hfill 2& \hfill & \hfill -1& \hfill & \hfill 1\\ \hfill 2& \hfill & \hfill 3& \hfill & \hfill 0& \hfill & \hfill 2\\ \hfill 0& \hfill & \hfill 1& \hfill & \hfill -2& \hfill & \hfill 0\end{array}\right]$
${R}_{2}\leftrightarrow {R}_{3}\to \left[\begin{array}{rrrrr}\hfill 1& \hfill & \hfill 2& \hfill & \hfill -1\\ \hfill 0& \hfill & \hfill 1& \hfill & \hfill -2\\ \hfill 2& \hfill & \hfill 3& \hfill & \hfill 0\end{array}\text{ }|\begin{array}{rr}\hfill & \hfill 1\\ \hfill & \hfill 0\\ \hfill & \hfill 2\end{array}\right]$
$-2{R}_{1}+{R}_{3}={R}_{3}\to \left[\begin{array}{rrrrrr}\hfill 1& \hfill & \hfill 2& \hfill & \hfill -1& \hfill \\ \hfill 0& \hfill & \hfill 1& \hfill & \hfill -2& \hfill \\ \hfill 0& \hfill & \hfill -1& \hfill & \hfill 2& \hfill \end{array}|\begin{array}{rr}\hfill & \hfill 1\\ \hfill & \hfill 0\\ \hfill & \hfill 0\end{array}\right]$
${R}_{2}+{R}_{3}={R}_{3}\to \left[\begin{array}{rrrrrr}\hfill 1& \hfill & \hfill 2& \hfill & \hfill -1& \hfill \\ \hfill 0& \hfill & \hfill 1& \hfill & \hfill -2& \hfill \\ \hfill 0& \hfill & \hfill 0& \hfill & \hfill 0& \hfill \end{array}|\begin{array}{rr}\hfill & \hfill 2\\ \hfill & \hfill 1\\ \hfill & \hfill 0\end{array}\right]$

The last matrix represents the following system.

$\begin{array}{l}\text{ }x+2y-z=1\hfill \\ \text{ }y - 2z=0\hfill \\ \text{ }0=0\hfill \end{array}$

We see by the identity $0=0$ that this is a dependent system with an infinite number of solutions. We then find the generic solution. By solving the second equation for $y$ and substituting it into the first equation we can solve for $z$ in terms of $x$.

$\begin{array}{l}\text{ }x+2y-z=1\hfill \\ \text{ }y=2z\hfill \\ \hfill \\ x+2\left(2z\right)-z=1\hfill \\ \text{ }x+3z=1\hfill \\ \text{ }z=\frac{1-x}{3}\hfill \end{array}$

Now we substitute the expression for $z$ into the second equation to solve for $y$ in terms of $x$.

$\begin{array}{l}\text{ }y - 2z=0\hfill \\ \text{ }z=\frac{1-x}{3}\hfill \\ \hfill \\ y - 2\left(\frac{1-x}{3}\right)=0\hfill \\ \text{ }y=\frac{2 - 2x}{3}\hfill \end{array}$

The generic solution is $\left(x,\frac{2 - 2x}{3},\frac{1-x}{3}\right)$.

### Try It 5

Solve the system using matrices.

$\begin{array}{c}x+4y-z=4\\ 2x+5y+8z=15\\ x+3y - 3z=1\end{array}$

### Can any system of linear equations be solved by Gaussian elimination?

Yes, a system of linear equations of any size can be solved by Gaussian elimination.

### How To: Given a system of equations, solve with matrices using a calculator.

1. Save the augmented matrix as a matrix variable $\left[A\right],\left[B\right],\left[C\right]\text{,} \dots$.
2. Use the ref( function in the calculator, calling up each matrix variable as needed.

### Example 8: Solving Systems of Equations with Matrices Using a Calculator

Solve the system of equations.

$\begin{array}{r}\hfill 5x+3y+9z=-1\\ \hfill -2x+3y-z=-2\\ \hfill -x - 4y+5z=1\end{array}$

### Solution

Write the augmented matrix for the system of equations.

$\left[\begin{array}{rrr}\hfill 5& \hfill 3& \hfill 9\\ \hfill -2& \hfill 3& \hfill -1\\ \hfill -1& \hfill -4& \hfill 5\end{array}\text{ }|\text{ }\begin{array}{r}\hfill 5\\ \hfill -2\\ \hfill -1\end{array}\right]$

On the matrix page of the calculator, enter the augmented matrix above as the matrix variable $\left[A\right]$.

$\left[A\right]=\left[\begin{array}{rrrrrrr}\hfill 5& \hfill & \hfill 3& \hfill & \hfill 9& \hfill & \hfill -1\\ \hfill -2& \hfill & \hfill 3& \hfill & \hfill -1& \hfill & \hfill -2\\ \hfill -1& \hfill & \hfill -4& \hfill & \hfill 5& \hfill & \hfill 1\end{array}\right]$

Use the ref( function in the calculator, calling up the matrix variable $\left[A\right]$.

$\text{ref}\left(\left[A\right]\right)$

Evaluate.

$\begin{array}{l}\hfill \\ \left[\begin{array}{rrrr}\hfill 1& \hfill \frac{3}{5}& \hfill \frac{9}{5}& \hfill \frac{1}{5}\\ \hfill 0& \hfill 1& \hfill \frac{13}{21}& \hfill -\frac{4}{7}\\ \hfill 0& \hfill 0& \hfill 1& \hfill -\frac{24}{187}\end{array}\right]\to \begin{array}{l}x+\frac{3}{5}y+\frac{9}{5}z=-\frac{1}{5}\hfill \\ \text{ }y+\frac{13}{21}z=-\frac{4}{7}\hfill \\ \text{ }z=-\frac{24}{187}\hfill \end{array}\hfill \end{array}$

Using back-substitution, the solution is $\left(\frac{61}{187},-\frac{92}{187},-\frac{24}{187}\right)$.

### Example 9: Applying 2 × 2 Matrices to Finance

Carolyn invests a total of $12,000 in two municipal bonds, one paying 10.5% interest and the other paying 12% interest. The annual interest earned on the two investments last year was$1,335. How much was invested at each rate?

### Solution

We have a system of two equations in two variables. Let $x=$ the amount invested at 10.5% interest, and $y=$ the amount invested at 12% interest.

$\begin{array}{l}\text{ }x+y=12,000\hfill \\ 0.105x+0.12y=1,335\hfill \end{array}$

As a matrix, we have

$\left[\begin{array}{rr}\hfill 1& \hfill 1\\ \hfill 0.105& \hfill 0.12\end{array}\text{ }|\text{ }\begin{array}{r}\hfill 12,000\\ \hfill 1,335\end{array}\right]$

Multiply row 1 by $-0.105$ and add the result to row 2.

$\left[\begin{array}{rr}\hfill 1& \hfill 1\\ \hfill 0& \hfill 0.015\end{array}\text{ }|\text{ }\begin{array}{r}\hfill 12,000\\ \hfill 75\end{array}\right]$

Then,

$\begin{array}{l}0.015y=75\hfill \\ \text{ }y=5,000\hfill \end{array}$

So $12,000 - 5,000=7,000$.

Thus, $5,000 was invested at 12% interest and$7,000 at 10.5% interest.

### Example 10: Applying 3 × 3 Matrices to Finance

Ava invests a total of $10,000 in three accounts, one paying 5% interest, another paying 8% interest, and the third paying 9% interest. The annual interest earned on the three investments last year was$770. The amount invested at 9% was twice the amount invested at 5%. How much was invested at each rate?

### Solution

We have a system of three equations in three variables. Let $x$ be the amount invested at 5% interest, let $y$ be the amount invested at 8% interest, and let $z$ be the amount invested at 9% interest. Thus,

$\begin{array}{l}\text{ }x+y+z=10,000\hfill \\ 0.05x+0.08y+0.09z=770\hfill \\ \text{ }2x-z=0\hfill \end{array}$

As a matrix, we have

$\left[\begin{array}{rrr}\hfill 1& \hfill 1& \hfill 1\\ \hfill 0.05& \hfill 0.08& \hfill 0.09\\ \hfill 2& \hfill 0& \hfill -1\end{array}\text{ }|\text{ }\begin{array}{r}\hfill 10,000\\ \hfill 770\\ \hfill 0\end{array}\right]$

Now, we perform Gaussian elimination to achieve row-echelon form.

$\begin{array}{l}\begin{array}{l}\hfill \\ -0.05{R}_{1}+{R}_{2}={R}_{2}\to \left[\begin{array}{rrrrrr}\hfill 1& \hfill & \hfill 1& \hfill & \hfill 1& \hfill \\ \hfill 0& \hfill & \hfill 0.03& \hfill & \hfill 0.04& \hfill \\ \hfill 2& \hfill & \hfill 0& \hfill & \hfill -1& \hfill \end{array}|\begin{array}{rr}\hfill & \hfill 10,000\\ \hfill & \hfill 270\\ \hfill & \hfill 0\end{array}\right]\hfill \end{array}\hfill \\ -2{R}_{1}+{R}_{3}={R}_{3}\to \left[\begin{array}{rrrrrr}\hfill 1& \hfill & \hfill 1& \hfill & \hfill 1& \hfill \\ \hfill 0& \hfill & \hfill 0.03& \hfill & \hfill 0.04& \hfill \\ \hfill 0& \hfill & \hfill -2& \hfill & \hfill -3& \hfill \end{array}|\begin{array}{rr}\hfill & \hfill 10,000\\ \hfill & \hfill 270\\ \hfill & \hfill -20,000\end{array}\right]\hfill \\ \frac{1}{0.03}{R}_{2}={R}_{2}\to \left[\begin{array}{rrrrrr}\hfill 0& \hfill & \hfill 1& \hfill & \hfill 1& \hfill \\ \hfill 0& \hfill & \hfill 1& \hfill & \hfill \frac{4}{3}& \hfill \\ \hfill 0& \hfill & \hfill -2& \hfill & \hfill -3& \hfill \end{array}|\begin{array}{rr}\hfill & \hfill 10,000\\ \hfill & \hfill 9,000\\ \hfill & \hfill -20,000\end{array}\right]\hfill \\ 2{R}_{2}+{R}_{3}={R}_{3}\to \left[\begin{array}{rrrrrr}\hfill 1& \hfill & \hfill 1& \hfill & \hfill 1& \hfill \\ \hfill 0& \hfill & \hfill 1& \hfill & \hfill \frac{4}{3}& \hfill \\ \hfill 0& \hfill & \hfill 0& \hfill & \hfill -\frac{1}{3}& \hfill \end{array}|\begin{array}{rr}\hfill & \hfill 10,000\\ \hfill & \hfill 9,000\\ \hfill & \hfill -2,000\end{array}\right]\hfill \end{array}$

The third row tells us $-\frac{1}{3}z=-2,000$; thus $z=6,000$.

The second row tells us $y+\frac{4}{3}z=9,000$. Substituting $z=6,000$, we get

$\begin{array}{r}\hfill y+\frac{4}{3}\left(6,000\right)=9,000\\ \hfill y+8,000=9,000\\ \hfill y=1,000\end{array}$

The first row tells us $x+y+z=10,000$. Substituting $y=1,000$ and $z=6,000$, we get

$\begin{array}{l}x+1,000+6,000=10,000\hfill \\ \text{ }x=3,000\text{ }\hfill \end{array}$

Solution