# Using Matrices to Solve Systems of Equations

## Matrix Equations

Matrices can be used to compactly write and work with systems of multiple linear equations.

### Learning Objectives

Identify how matrices can represent a system of equations

### Key Takeaways

#### Key Points

• If
$A$
is an
$m \times n$
matrix, and
$x$
designates a column vector (i.e.
$n \times 1$
matrix) of
$n$
variables
$x_1, x_2,..., x_n$
, and
$b$
is an
$m \times 1$
column vector, then the matrix equation is:
$Ax=b$
.

#### Key Terms

• matrix: A rectangular arrangement of numbers or terms having various uses such as transforming coordinates in geometry, solving systems of linear equations in linear algebra and representing graphs in graph theory.

Matrices can be used to compactly write and work with systems of equations. As we have learned in previous sections, matrices can be manipulated in any way that a normal equation can be. This is very helpful when we start to work with systems of equations. It is helpful to understand how to organize matrices to solve these systems.

### Writing a System of Equations with Matrices

It is possible to solve this system using the elimination or substitution method, but it is also possible to do it with a matrix operation. Before we start setting up the matrices, it is important to do the following:

• Make sure that all of the equations are written in a similar manner, meaning the variables need to all be in the same order.
• Make sure that one side of the equation is only variables and their coefficients, and the other side is just constants.

Solving a system of linear equations using the inverse of a matrix requires the definition of two new matrices:
$X$
is the matrix representing the variables of the system, and
$B$
is the matrix representing the constants. Using matrix multiplication, we may define a system of equations with the same number of equations as variables as:

$\displaystyle A\cdot X=B$

To solve a system of linear equations using an inverse matrix, let
$A$
be the coefficient matrix, let
$X$
be the variable matrix, and let
$B$
be the constant matrix.

Given the system:

\displaystyle \begin{align} x+8y&=7 \\ 2x-8y&=-3 \end{align}

The coefficient matrix is:

$A=\begin{bmatrix} 1 & 8\\ 2 & -8 \end{bmatrix}$

The variable matrix is:

$\displaystyle X=\begin{bmatrix} x\\ y \end{bmatrix}$

The constant matrix is:

$\displaystyle B=\begin{bmatrix} 7\\ -3 \end{bmatrix}$

Thus, to solve a system
$AX=B$
, for
$X$
, multiply both sides by the inverse of
$A$
and we shall obtain the solution:

$\displaystyle X=(A^{-1})B$

Provided the inverse
$\left( A^{-1} \right)$
exists, this formula will solve the system.

If the coefficient matrix is not invertible, the system could be inconsistent and have no solution, or be dependent and have infinitely many solutions.

## Matrices and Row Operations

Two matrices are row equivalent if one can be changed to the other by a sequence of elementary row operations.

### Learning Objectives

Explain how to use row operations and why they produce equivalent matrices

### Key Takeaways

#### Key Points

• An elementary row operation is any one of the following moves: row switching (swap two rows of a matrix ), row multiplication (multiply a row of a matrix by a non-zero constant ), or row addition (add to one row of a matrix to some multiple of another row).
• If the rows of the matrix represent a system of linear equations, then the row space consists of all linear equations that can be deduced algebraically from those in the system.

#### Key Terms

• row space: The set of all possible linear combinations of its row vectors.
• row equivalent: In linear algebra, when one matrix can be changed to the other by a sequence of elementary row operations.

### Elementary Row Operations (ERO)

In linear algebra, two matrices are row equivalent if one can be changed to the other by a sequence of elementary row operations. Alternatively, two
$m \times n$
matrices are row equivalent if and only if they have the same row space. The row space of a matrix is the set of all possible linear combinations of its row vectors. If the rows of the matrix represent a system of linear equations, then the row space consists of all linear equations that can be deduced algebraically from those in the system. Two matrices of the same size are row equivalent if and only if the corresponding homogeneous systems have the same set of solutions, or equivalently the matrices have the same null space. Because elementary row operations are reversible, row equivalence is an equivalence relation. It is commonly denoted by a tilde (~).

An elementary row operation is any one of the following three moves:

1. Row switching (swap): Swap two rows of a matrix.
2. Row multiplication (scale): Multiply a row of a matrix by a nonzero constant.
3. Row addition (pivot): Add to one row of a matrix some multiple of another row.

### Produce Equivalent Matrices Using Elementary Row Operations

Since the matrix is essentially the coefficients and constants of a linear system, the three row operations preserve the matrix. For example, swapping two rows simply means switching their position within the matrix. Also, when solving a system of linear equations by the elimination method, row multiplication would be the same as multiplying the whole equation by a number to obtain additive inverses so that a variable cancels. Finally, row addition is also the same as the elimination method, when one chooses to add or subtract the like terms of the equations to obtain the variable. Therefore, row operations preserve the matrix and can be used as an alternative method to solve a system of equations.

### Example 1:  Show that these two matrices are row equivalent:

$\displaystyle A=\begin{pmatrix} 1 & -1 & 0 \\ 2 & 1 & 1 \end{pmatrix}\quad B=\begin{pmatrix} 3 & 0 & 1 \\ 0 & 3 & 1 \end{pmatrix}$

$A$
, add the second row to the first:

$\displaystyle A=\begin{pmatrix} 3 & 0 & 1 \\ 2 & 1 & 1 \end{pmatrix}$

Then, multiply the second row by 3 and then subtract the first row from the second:

$\displaystyle A=\begin{pmatrix} 3 & 0 & 1 \\ 3 & 3 & 2 \end{pmatrix}$

Finally, subtract the first row from the second:

$\displaystyle A=\begin{pmatrix} 3 & 0 & 1 \\ 0 & 3 & 1 \end{pmatrix}$

You can see that
$A=B$
, which we achieved through a series of elementary row operations.

### Row Reduction:  Solving a System of Linear Equations

In row reduction, the linear system:

$\displaystyle x+3y-2z=5 \\ 3x+5y+6z=7 \\ 2x+4y+3z=8$

Is represented as an augmented matrix:

$\displaystyle A=\begin{pmatrix} 1 & 3 & -2 & 5 \\ 3 & 5 & 6 & 7 \\ 2 & 4 & 3 & 8 \end{pmatrix}$

This matrix is then modified using elementary row operations until it reaches reduced row echelon form.

Because these operations are reversible, the augmented matrix produced always represents a linear system that is equivalent to the original.

There are several specific algorithms to row-reduce an augmented matrix, the simplest of which are Gaussian elimination and Gauss-Jordan elimination. This computation can be done by hand (using the three types of ERO) or on the calculator under the matrix function 'rref' (reduced row echelon form).

The final matrix is in reduced row echelon form, and represents the system
$x=-15$
,
$y=8$
$z=2$
.

$\displaystyle A=\begin{pmatrix} 1 & 0 & 0 & -15 \\ 0 & 1 & 0 & 8 \\ 0 & 0 & 1 & 2 \end{pmatrix}$

## Simplifying Matrices With Row Operations

Using elementary operations, Gaussian elimination reduces matrices to row echelon form.

### Learning Objectives

Use elementary row operations to put a matrix in simplified form

### Key Takeaways

#### Key Points

• Since elementary row operations preserve the row space of the matrix, the row space of the row echelon form is the same as that of the original matrix.
• There are three types of elementary row operations: swap the positions of two rows, multiply a row by a nonzero scalar, and add to one row a scalar multiple of another.
• In practice, one does not usually deal with the systems in terms of equations but instead makes use of the augmented matrix (which is also suitable for computer manipulations).

#### Key Terms

• augmented matrix: A matrix obtained by appending the columns of two given matrices, usually for the purpose of performing the same elementary row operations on each of the given matrices.

By means of a finite sequence of elementary row operations, called Gaussian elimination, any matrix can be transformed to a row echelon form.  This transformation is necessary for solving a system of linear equations.

Before getting into more detail, there are a couple of key terms that should be mentioned:

• Augmented matrix: an augmented matrix is a matrix obtained by appending the columns of two given matrices, usually for the purpose of performing the same elementary row operations on each of the given matrices.
• Upper triangle form: A square matrix is called upper triangular if all the entries below the main diagonal are zero. A triangular matrix is one that is either lower triangular or upper triangular. A matrix that is both upper and lower triangular is a diagonal matrix.
• Elementary row operations: Swap rows, add rows or multiply rows.

### Gaussian Elimination

1. Write the augmented matrix for the linear equations.
2. Use elementary row operations on the augmented matrix
$[A|b]$
to transform
$A$
to upper triangle form. If a zero is on the diagonal, switch the rows until a nonzero is in its place.
3. Use back substitution to find the solution.

### Example 1:  Solve the system by Gaussian Elimination:

$\displaystyle 2x+y-z=8\\ -3x-y+2z=-11\\ -2x+y+2z=-3$

Write the augmented matrix:

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

Use elementary row operations to reduce the matrix to reduced row echelon form:

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

Using elementary row operations to obtain reduced row echelon form ('rref' in the calculator) the solution to the system is revealed in the last column:
$x=2, y=3, z=-1$
.