## Solving linear systems using Cramers Rule

#### What is Cramers rule

Cramers rule is a technique to solve systems of linear equations where there are the same amount of unknowns as equations in the system. The technique consists on a set of equations involving determinants and ratios in order to obtain the unique set of solutions for a linear system.

Throughout this lesson we will focus on explaining the method for solving a system that we will call Cramers rule 3x3 and Cramers rule 2x2, this means that we will focus on the cases where we have a system of equations with 3 equations for 3 unknowns (n=3) or a system with 2 equations for 2 unknowns (n=2). The reason for it is that Cramers rule is not practical when a system is of higher order than 3, other methods, such as

solving a linear system with matrices using Gaussian elimination, or simply

solving systems of linear equations by substitution are much more computationally effective to work through a linear system. Still Cramers rule is an important piece of linear algebra to be considered due its mathematical rigor and the deep understanding of the transcription of linear systems into matrices, and viceversa, when such systems have unique solutions.

#### How to use Cramers rule

But what is Cramers rule perse? Instead of reciting a Cramers rule definition, let us showcase the technique a little better by going through its steps in detail.

__Steps to follow when using Cramers rule linear algebra:__
1. $\enspace$ For a linear system of three equations and three unknowns and for a linear system of two equations and two unknowns, as the ones represented below:

$ax+ by + cz = m \quad \quad \quad \quad \quad \quad \quad$
$dx+ey+fz=n \quad \quad ax+by=m$
$gz+hy+iz=o \quad \quad cx+dy=n$
Equation 1: Systems of linear equations. 3 equations for 3 unknowns on the left, 2 equations for 2 unknowns on the right
2. $\enspace$ The system of linear equations has to be converted into and augmented matrix.

- From the augmented matrix, the elements in the left hand side of the vertical line which represents the equal sign conform a square coefficient matrix. This square coefficient matrix will be used to obtain a series of determinants in our next step.
- From the augmented matrix, the elements on the column vector on the right hand side of the equal sign will be used as replacement for certain elements when obtaining the set of determinants in the next step.
- The augmented matrices for the system with three equations and 3 unknowns and the system of two equations and two unknowns represented in equation 1 look as follows:

Equation 2: Augmented matrices from the systems of linear equations

- Take into account that Cramers rule can be used with any system of n equations for n unknowns (as long as there are as many equations as unknowns, it doesnt matter the quantity). We have picked to represent the cases in which $\, n = 3\,$ and $\, n = 2 \,$ since those are usually the ones used before we decide to continue our calculations with a different and more convenient technique.

3. $\enspace$ Then we need to calculate $\, n+1 \,$ determinants.

- In other words, for the case in which $\, n=3 \,$, we will be calculating 4 determinants. For the case in which $\, n = 2 \,$, we will calculate 3 determinants.
- The determinants are all named based in the variables contained in the system of linear equations in question. For example, for the case in which the system has three unknowns, you have variables $x$, $y$, $z$, therefore, the determinants are: $D_x$, $D_y$, $D_z$. For the case in which the system has two unknowns, you have the variables $x$, $y$, therefore, the determinants are: $D_x$, $D_y$. Besides, in each case, there is always an extra determinant we just call $D$.
- The determinant $D$, is always the determinant of the square coefficient matrix (which we called $C$) from the left hand side of the augmented matrix. For the systems where $\, n= 3 \,$ and $\, n=2 \,$. The determinant $D$ would be as follows:

Equation 3: Determinant D

- The determinants $D_x$, $D_y$, $D_z ...$ are obtained by replacing the column vector b from equation 2, into the corresponding column on the square coefficient matrix.

Equation 4: Formulating the determinants D_{x}, D_{y}, D_{z}
4. $\enspace$ Once the determinants have been calculated, we just follow the next ratio equations in order to obtain the values of the variables from the systems of equations:

$\large x= \frac{D_x}{D} \quad \quad \quad \quad \quad$
$\large y= \frac{D_y}{D} \quad \quad x= \frac{D_x}{D}$
$\large z= \frac{D_z}{D} \quad \quad y= \frac{D_y}{D}$
Equation 5: Finding the variables solutions for the systems of linear equations. 3 equations for 3 unknowns on the left, 2 equations for 2 unknowns on the right
In general, each equation for each variable, as shown in equation 5, is what we call the Cramers rule formula. Many books and published materials refer to this simply as Cramers rule, when in reality the technique requires multiple equations. For that same reason, sometimes you may see this technique called the matrix Cramers rule (usually referring to the augmented matrix from equation 2 or the set of determinants from equations 3 and 4).

As you can see, solving systems of equations using Cramers rule becomes very tedious very fast, and this is why this method is usually left on the side and people prefer to use techniques such as row reduction through gaussian elimination. If we compare such two methods, we can clearly see that as the system increases in number of equations, and thus unknowns, the Cramers rule matrices get bigger and the method longer since it requires n+1 amount of determinants to be solved; not only that, the determinants become bigger as n increases too.

Therefore, we are going to focus on solving systems of linear equations with up to 3 equations for 3 unknowns on this lesson, higher n values are suggested to be solved with other techniques for solving systems of linear equations.

#### Cramers rule to solve system of equations

Having explained the steps on how to do Cramers rule, let us learn how to use it while solving systems of linear equations.

We will divide this section in two parts, one dedicated to solve a system of 2 equations for 2 unknowns (

$n=2$) and the other one dedicated to solve a system with 3 equations for 3 unknowns.

Use Cramers rule to solve the system of 2 linear equations for 2 unknowns as shown below:

$x+2y=3$
$2x+3y=1$
Equation 6: System of 2 linear equations for 2 unknowns
We convert the system into an augmented matrix:

Equation 7: Augmented matrix for the 2x2 system
And then we calculate the 3 required determinants (remember that step 3 of our method dictates that we need to compute

$\, n+1 \,$ determinants. For this case we have a system of 2 unknowns, thus

$\, n=2 \,$, therefore

$\, n+1 = 2+1 =3\,$, and so, 3 determinants to be solved).

Following equation 3, we solve the Cramers rule determinant D first:

Equation 8: Cramers rule determinant D
Notice how this determinant

$D$ is just the determinant of the square coefficient matrix from the left hand side of the augmented matrix in equation 7.

Now, to solve the determinants related to each of the variables in the equations from the system we need to substitute the column related to each variable in the square coefficient matrix, by the column coming from the right hand side of the augmented matrix. Thus, the determinants

$D_x$,

$D_y$ are:

Equation 9: Cramers rule determinants related to each variable
To finally find the unique solution for each variable in the equations, we now solve the Cramers rule equation for each of them:

$\large x = \frac{D_x}{D} = \frac{7}{-1} = -7$
$\large y = \frac{D_y}{D} = \frac{-5}{-1} = 5$
Equation 10: Solution to the variables x and y
And so, the system has been solved! The solutions for the variables

$x$ and

$y$ are:

$x=-7, y=5$.

Now let us take a look at the process on how to do the Cramers rule 3x3!

Use Cramers rule to solve the system of equations for 3 unknowns as shown below:

$x+4y+3z=1$
$x+2y+9z=1$
$x+6y+6z=1$
Equation 11: System of 3 linear equations for 3 unknowns
We convert the system into an augmented matrix:

Equation 12: Augmented matrix for the 3x3 system
And then we calculate the 4 required determinants. Starting with determinant

$D$:

Equation 13: Cramers rule determinant D
This determinant

$D$ is just the determinant of the square coefficient matrix from the left hand side of the augmented matrix in equation 12.

Now, to solve the determinants related to each of the variables in the equations from the system we substitute the column related to each variable in the square coefficient matrix by the column coming from the right hand side of the augmented matrix. And so, the determinants

$D_x$,

$D_y$,

$D_z$ are:

Equation 14: Cramers rule determinants related to each variable
Solving for the variables

$x$,

$y$ and

$z$:

$\large x = \frac{D_x}{D} = \frac{-18}{-18} = 1$
$\large y = \frac{D_y}{D} = \frac{0}{-18} = 0$
$\large z = \frac{D_z}{D} = \frac{0}{-18} = 0$
Equation 15: Solution to the variables x and y
And so, the system has been solved!

$x=1, y=0, z=0$
In summary, in order to use Cramers rule for solving linear equations we: rewrite the system into an augmented matrix, use the left hand side of this matrix as a square coefficient matrix, and the right hand side as a substitution for the solumns related to each variable in the coefficient matrix, set up the n+1 determinants for the system, evaluate determinants and apply Cramers rule equations to find the unique solutions to the variables.

Remember, if you are not completely content with this technique you can always work through a Cramers rule proof by solving the system using any of the other techniques you already know to solve linear systems of equations.

#### Cramers rule examples

On this section we add a few other examples exercises where we use Cramers rule to solve systems of equations. We start with a few examples of 2x2 systems and end up with a 3x3 problem.

__Example 1__

Solve the following linear system using Cramers rule:

$5x+3y=1$
$x+y=2$
Equation 16: System of 2 linear equations for 2 unknowns
We convert the system into an augmented matrix:

Equation 17: Augmented matrix for the 2x2 system
And then we calculate the 3 required determinants:

Equation 18: Cramers rule determinants
Now use

$D$,

$D_x$,

$D_y$ to finally find the unique solution for each variable in the equations:

$\large x = \frac{D_x}{D} = \frac{-5}{2} = -2.5$
$\large y = \frac{D_y}{D} = \frac{9}{2} = 4.5$
Equation 19: Solution to the variables x and y
So, the solutions for the variables

$x$ and

$y$ are:

$x=-2.5, y=4.5$
__Example 2__

Solve the following linear system using Cramers rule:

$y=3x+5$
$y=4x-2$
Equation 20: System of 2 linear equation for 2 unknowns
We convert the system given above to the standard notation so we can transform it into the augmented matrix later:

$y=3x+5 \quad$→$\quad -3x+y=5$
$y=4x-2 \quad$→$\quad -4x+y=-2$
Equation 21: System of 2 linear equations for 2 unknowns
We convert the system into an augmented matrix:

Equation 22: Augmented matrix for the 2x2 system
And then we calculate the 3 required determinants:

Equation 23: Cramers rule determinants
Now use

$D$,

$D_x$,

$D_y$ to finally find the unique solution for each variable in the equations:

$\large x = \frac{D_x}{D} = \frac{7}{1} = 7$
$\large y = \frac{D_y}{D} = \frac{26}{1} = 26$
Equation 24: Solution to the variables x and y
So, the solutions for the variables

$x$ and

$y$ are:

$x=7, y=26$
__Example 3__

Solve the following linear system using Cramers rule:

$2x+4y=3$
$4x+8y=6$
Equation 25: System of 2 linear equations for 2 unknowns
We convert the system into the Cramers rule matrix (augmented matrix):

Equation 26: Augmented matrix for the 2x2 system
And then we calculate the 3 required determinants:

Equation 27: Cramers rule determinants
Now use

$D$,

$D_x$,

$D_y$ to finally find the unique solution for each variable in the equations:

$\large x = \frac{D_x}{D} = \frac{0}{0} = 0$
$\large y = \frac{D_y}{y} = \frac{0}{0} = 0$
Equation 28: Solution to the variables x and y
So, the solutions for the variables

$x$ and

$y$ are:

$x=0, y=0$
__Example 4__

For the final Cramers rule example, we will be solving a system of 3 equations for 3 unknowns:

$x+3y+4z=4$
$-x+3y+2z=2$
$3x+9y+6z=-6$
Equation 29: System of 3 linear equations for 3 unknowns
We convert the system into an augmented matrix:

Equation 30: Augmented matrix for the 3x3 system
And then we calculate the 4 required determinants:

Equation 31: Cramers rule determinants
Now use

$D$,

$D_x$,

$D_y$ to finally find the unique solution for each variable in the equations:

$\large x = \frac{D_x}{D} = \frac{72}{-36} = -2$
$\large y = \frac{D_y}{D} = \frac{72}{-36} = -2$
$\large y = \frac{D_z}{D} = \frac{-108}{-36} = 3$
Equation 32: Solution to the variables x, y and z
And the system is solved! The solutions for the variables

$x$,

$y$ and

$z$ are:

$x=-2, y=-2, z=3$
For this last exercise we would like to work on a proof of Cramers rule by solving the system from equation 24 using another method and check for the result.

Thus, we use substitution to solve the system:

starting up with the three equations:
$x \, + \, 3y \, + \, 4z=4 \quad \quad \quad -x \, + \, 3y \, + \, 2z=2 \quad \quad \quad 3x \, + \, 9y \, + \, 6z=-6$
solve for$x$in the 1st equation, and substitute it in the 3rd:
$x =4-3y-4z$
$3(4-3y-4z) \, + \, 9y \, + \, 6z=-6 \;$→$\; -6z \, + \, 12=-6$
$-6z=-18 \;$→$\; z=3$
Equation 33: Solving the 3x3 system by substitution (part 1)
Now we continue the substitution technique by substituting the found value of the variable

$z$ into the first and second equations and obtain a new simplified system of 2 equations for 2 unknowns:

$x \, + \, 3y \, + \, 4z = 4 \;$→$\; x \, + \, 3y \, + \, 4(3)= 4 \;$→$\; x \, + \, 3y=-8$
$-x \, + \, 3y \, + \, 2z = 2 \;$→$\;-x \, + \, 3y \, + \, 2(3)= 2 \;$→$\; - x \, + \, 3y=-4$
The new equations are:
$x \, + \, 3y=-8 \quad \quad \quad -x \, + \, 3y=-4$
Equation 34: Solving the 3x3 system by substitution (part 2)
Using these new expressions found in equation 29, solve for x in the second equation and substitute it in the first equation to find

$y$:

$3y \, + \, 4=x \;$→$\; (3y \, + \, 4) \, + \, 3y=-8$
$6y \, + \, 4 = -8 \;$→$\; 6y= -12$
$y=-2$
Equation 35: Solving the 3x3 system by substitution (part 3)
And we finalize this by substituting the found value of y into the second expression from equation 29:

$-x \, + \, 3y=-4 \;$→$\; -x \, + \, 3(-2)=-4$
$-x-6=-4 \;$→$\; -x=2$
$x=-2$
Equation 36: Solving the 3x3 system by substitution (part 4)
The final found values for the variables

$x$,

$y$ and

$z$ are:

$x=-2, y=-2, z=3$
Therefore, the unique solutions for the variables in the linear system of equations match with the answers found using Cramers rule for matrices! And you can clearly see that both approaches are good for us to use when solving systems.

To finalize our lesson of today, as always, we have a few recommendations for your further studies. First, this detailed article in which you can find an example of

using Cramers rule to solve two equations with two unknowns. And then, this link on the

inverse matrix and Cramers rule where you can find an example of a 3x3 system in the bottom.

This is it for this lesson, see you in the next one!