CEMC Banner

Grade 7/8 Math Circles
Solving Systems of Equations Using Matrices

Systems of Equations

A variable is a placeholder for an unknown numerical value in an equation. Usually, a variable is represented by a letter in the English alphabet, like \(x\), or Greek alphabet, like \(\phi\).

A coefficient is a numerical or constant quantity that multiplies a variable. Normally, we forgo writing the multiplication symbol and place the coefficient right in front of a variable (i.e. \(4 \times x = 4x\)).

A system of equations is two or more equations that share the same variables. For example,

\(x + y = 3\)
\(y = 2x + 3\)

is a system of equations.

Systems of equations are useful because they allow us to solve for the values of multiple variables, that would be impossible with only one equation.

Example 1

What are the values of \(x\) and \(y\) in the equation \(x + y = 3\)?

Solution 1

We see that the values \(x = 3\) and \(y = 0\) give \(x + y = 3\), as desired. But, we see that \(x = 0\) and \(y = 3\) also gives \(x + y = 3\). The table below gives a few more values of \(x\) and \(y\) for the equation \(x + y = 3\):

\(x\) \(0\) \(1\) \(2\) \(3\) \(4\) \(5\) \(\dots\)
\(y\) \(3\) \(2\) \(1\) \(0\) \(-1\) \(-2\) \(\dots\)

Thus, we have that there are an infinite number of possible values of \(x\) and \(y\) in the equation \(x + y = 3\).

Here a few changes in notation that will be used in this lesson:

We have the following definitions for the types of systems of equations:

Example 1 is the case of an underdetermined system of equations, since there are \(2\) variables and only \(1\) equation. In order to determine a unique solution to a system of equations, we must make sure that there is at least as many equations as there are variables.

Our initial strategy for solving systems of equations will be substitution, which follows these steps:

  1. Isolate one of the variables in one equation.

  2. Take the expression for the variable from step \(1\), and substitute it into the other equation(s).

  3. Repeat steps \(1\) and \(2\) until one variable remains and determine the value of that variable.

  4. Use the result from step \(3\) to solve for the rest of the variables.

Example 2

Determine the values of \(x\) and \(y\) in the system of equations:

\(x + y = 3\)
\(y = 2x + 3\)

Solution 2

We see that our first step is already done in the second equation with \(y = 2x + 3\). We then substitute this value of \(y\) into the first equation, which gives:

\[\begin{aligned} x + y &= 3 \\ x + 2x + 3 &= 3 & \text{(substitute $y = 2x + 3$ into equation)}\\ 3x + 3 &= 3 & \text{(collect $x$ terms)}\\ 3x + 3 - 3 &= 3 - 3 & \text{(subtract $3$ from both sides)}\\ 3x &= 0 & \\ \frac{3x}{3} &= \frac{0}{3} & \text{(divide both sides by $3$)}\\ x &= 0\end{aligned}\] We can now substitute the value \(x = 0\) into the second equation to get the value of \(y\):

\[\begin{aligned} y &= 2x + 3 \\ y &= 2(0) + 3 \\ y &= 0 + 3 \\ y &= 3\end{aligned}\]

Thus, we have \(x = 0\) and \(y = 3\) is the unique solution to the system of equations. We know that this is the unique system to the problem because no other values of \(x\) and \(y\) satisfy both equations.

Activity 1

Use the steps above to determine a unique solution to the system of equations:

\(2x + y = 4\)
\(x - y = 5\)

Activity 1 Solution

Following step 1, we see that we can rewrite \(x - y = 5\) as \(x = 5 + y\). We then substitute this into the first equations, which gives:

\[\begin{aligned} 2x + y &= 4 \\ 2(5 + y) + y &= 4 \\ 2(5) + 2(y) + y &= 4 \\ 10 + 2y + y &= 4 \\ 2y + y &= 4 - 10 \\ 3y &= -6 \\ y &= -2\end{aligned}\]

We can now substitute the values \(y = -2\) into the second equation to get the value of \(x\):

\[\begin{aligned} x &= 5 + y \\ &= 5 + (-2) \\ &= 5 - 2 \\ &= 3\end{aligned}\]

Thus, the unique solution to the system is \(x = 3\) and \(y = -2\).

Our strategy above will only truly work if the system of equations has a unique solution. If the system is underdetermined, step \(3\) may or may not produce a value for a variable, but step \(4\) will never produce values for the all the rest of the variables. If there are a no solutions, there will be many contradictions of the values of variables throughout the steps. The strategy can also work for systems of any number of variables and equations.

Activity 2

Observe the two systems of equations below:

System \((1)\) \[\begin{aligned} x + y &= 1 \\ x - y &= 2 \\ x + 2y &= 3 \end{aligned}\]

System \((2)\) \[\begin{aligned} x + y + z &= 8\\ 2x - z &= 18 - y\\ 3z + 2y - x &= 1\end{aligned}\]

  1. Determine if each system is underdetermined, overdetermined, or balanced. Explain.

  2. Is there a unique solution to (1)? If so, state the solution. If not, how many solutions are there? Show your work.

  3. Is there a unique solution to (2)? If so, state the solution. If not, how many solutions are there? Show your work.

Activity 2 Solution

  1. For system (1), there are 2 variables and 3 equations. Thus, since there are more equations that there are variables, the system is overdetermined.
    For system (2), there are 3 variables and 3 equations. Thus, since there are the same number of equations and variables, the system is balanced.

  2. From part (a), the system (1) is overdetermined, so there are either infinitely many solutions, one solution, or no solutions. To determine which of these is true for this system, we follow the four steps above.
    We can rewrite the first equation to get \(x = 1 - y\). We can this substitute this into the second equation to get: \[\begin{aligned} x - y &= 2 \\ 1 - y - y &= 2 \\ 1 - 2y &= 2 \\ -2y &= 2 - 1 \\ -2y &= 1 \\ y &= -\frac{1}{2}\end{aligned}\] We can substitute the value \(y = -\frac{1}{2}\) back into the first equation to get the value of \(x\): \[\begin{aligned} x &= 1 - y \\ &= 1 - (-\frac{1}{2}) \\ &= 1 + \frac{1}{2} \\ &= \frac{2}{2} + \frac{1}{2} \\ &= \frac{2 + 1}{2} \\ &= \frac{3}{2}\end{aligned}\]

    Thus, we have the solution \(x = \frac{3}{2}\) and \(y = -\frac{1}{2}\), which is unique for the first two equations. Now, we just have to make sure it is also a solution for the third equation. We can do this by substituting the values of \(x\) and \(y\) into the left side of the equation, and making sure the result is 3. So, \[\begin{aligned} x + 2y &= \frac{3}{2} + 2(-\frac{1}{2}) \\ &= \frac{3}{2} + (-1) \\ &= \frac{3}{2} - 1 \\ &= \frac{3}{2} - \frac{2}{2} \\ &= \frac{3 - 2}{2} \\ &= \frac{1}{2}\end{aligned}\] Since the result is \(\frac{1}{2}\), and not 3, this means that \(x = \frac{3}{2}\) and \(y = -\frac{1}{2}\) cannot be solution to the third equation. And, since \(x = \frac{3}{2}\) and \(y = -\frac{1}{2}\) are unique solutions to the first two equations, there are no other solutions for the first two equations. Thus, the system (1) has no solutions.

  3. From part (a), the system (2) is balanced, so there are either infinitely many solutions, one solution, or no solutions. To determine which of these is true for this system, we follow the four steps above.

    We can rewrite the third equation to get \(x = 2y + 3z - 1\). We can this substitute this into the second equation to get: \[\begin{aligned} 2x - z &= 18 - y \\ 2(2y + 3z - 1) - z &= 18 - y \\ 2(2y) + 2(3z) + 2(-1) - z &= 18 - y \\ 4y + 6z - 2 - z &= 18 - y \\ 4y + 5z + y &= 18 + 2 \\ 5y + 5z &= 20 \\ y + z &= 4\end{aligned}\]

    Once again, we can rewrite this equation as \(y = 4 - z\). We can substitute this, and the equation \(x = 2y + 3z - 1\), into the first equation to get:

    \[\begin{aligned} x + y + z &= 8 \\ 2y + 3z - 1 + 4 - z + z &= 8 \\ 2(4 - z) + 3z - 1 + 4 - z + z &= 8 \\ 8 - 2z + 3z - 1 + 4 - z + z &= 8 \\ z + 11 &= 8 \\ z &= 8 - 11 \\ z &= -3\end{aligned}\]

    We can now substitute \(z = -3\) into \(y = 4 - z\) to get:

    \[\begin{aligned} y &= 4 - z \\ &= 4 - (-3) \\ &= 4 + 3 \\ &= 7\end{aligned}\]

    Finally, we substitute both \(z = -3\) and \(y = 7\) into \(x = 2y + 3z - 1\) to get:

    \[\begin{aligned} x &= 2y + 3z - 1 \\ &= 2(7) + 3(-3) - 1 \\ &= 14 + (-9) - 1 \\ &= 14 - 9 - 1 \\ &= 4\end{aligned}\]

    Thus, we have the unique solution for the system to be \(x = 4\), \(y = 7\) and \(z = -3\).

Additionally, sometimes systems of equations are not explicitly stated, and instead have to be created based on information given in the question. This is very common in questions that use systems of equations in real-life situations. The following example will show you how to work through these kinds of problems.

Example 3

Suppose a jar contains marbles of the colours: blue, green, yellow, and red. We are given the following information about the number of marbles:

How many marbles are there of each colour?

Solution 3

We start by defining a variable to represent the number of marbles for each colour. We have \(b\) for blue, \(g\) for green, \(y\) for yellow, and \(r\) for red. We then use the information above to create equations to represent the situation. This gives us the following four equations:

(1) \(b + r = 38\)
(2) \(g + r = 44\)
(3) \(y + r = 52\)
(4) \(b + g + y + r = 100\)

We see that the first three equations can all be rewritten in the following ways:

(1) \(b = 38 - r\)
(2) \(g = 44 - r\)
(3) \(y = 52 - r\)

We can then substitute all three of these equations into the last equation to get:

\[\begin{aligned} b + g + y + r &= 100 \\ (38 - r) + (44 - r) + (52 - r) + r &= 100 \\ 134 - 2r &= 100 \\ -2r &= -34 \\ r &= 17\end{aligned}\]

Finally, we substitute in the value \(r = 17\) into the remaining equations to get:

(1) \(b = 38 - 17 = 21\)
(2) \(g = 44 - 17 = 27\)
(3) \(y = 52 - 17 = 35\)

Thus, there are 21 blue marbles, 27 green marbles, 35 yellow marbles, and 17 red marbles in the jar.

Matrices

A matrix, or matrices (plural), is a rectangular array of numbers, symbols, or expressions, arranged in rows and columns. Matrices have many applications that are very useful in advanced mathematics, but we will focus on their applications for systems of linear equations. Below is an example of a matrix with 2 rows and 3 columns:

\[\left[\begin{array}{ccc} 3 & 2 & 8 \\ 1 & 7 & 4 \end{array}\right]\]

Elementary Row Operations

The elementary row operations, or EROs, are the three operations that can be performed on any one matrix.

Performing any of these operations on a matrix does not change the matrix; it remains equivalent to the original matrix.

Example 4

\(\left[\begin{array}{ccc} 2 & 3 \\ 4 & 7 \end{array}\right] \substack{\xrightarrow[R_1 \leftrightarrow R_2]{}\\[2mm] \xrightarrow[]{R_2 \leftrightarrow R_1}} \left[\begin{array}{ccc} 4 & 7 \\ 2 & 3 \end{array}\right]~~ \text{(Row 1 and Row 2 swap places)}\)

\(\left[\begin{array}{ccc} 2 & 3 \\ 4 & 7 \end{array}\right] \substack{\xrightarrow[]{2 \times R_1}\\[2mm] \xrightarrow[]{}} \left[\begin{array}{ccc} 4 & 6 \\ 4 & 7 \end{array}\right] ~~ \text{(multiply the elements in Row 1 by 2)}\)

\(\left[\begin{array}{ccc} 2 & 3 \\ 4 & 7 \end{array}\right]f \substack{\xrightarrow[]{}\\[2mm] \xrightarrow[]{R_2 - R_1}} \left[\begin{array}{ccc} 2 & 3 \\ 2 & 4 \end{array}\right] ~~ \text{(subtract the elements in R2 by the elements in R1)}\)

Reduced Row Echelon Form

The reduced row echelon form, or RREF, of a matrix is the simplest form of a matrix, similar to a fraction reduced to lowest terms. A matrix is only considered to be in RREF if all of the following are true:

  1. The first non-zero element in each row is 1 (called a leading 1).

  2. Each leading 1 is in a column to the right of the leading 1 in the previous row.

  3. Any rows with all 0 elements, are at the bottom of the matrix.

  4. If a column has a leading 1, then all other elements in that column are 0.

Some examples of matrices in RREF are:

\(\left[\begin{array}{cc} 1 & 0 \\ 0 & 1 \end{array}\right] \hspace{8mm} \left[\begin{array}{ccc} 1 & 0 & 2 \\ 0 & 1 & 1 \end{array}\right] \hspace{8mm} \left[\begin{array}{cc} 1 & 0 \\ 0 & 0 \\ 0 & 0 \end{array}\right] \hspace{8mm} \left[\begin{array}{ccc} 1 & 0 & 2 \\ 0 & 1 & 1 \\ 0 & 0 & 0 \end{array}\right]\)

and some examples of matrices not in RREF are:

\(\left[\begin{array}{ccc} 1 & 3 & 2 \\ 0 & 1 & 1 \\ 0 & 0 & 0 \end{array}\right] \hspace{8mm} \left[\begin{array}{cc} 0 & 0 \\ 1 & 0 \\ 0 & 0 \end{array}\right] \hspace{8mm} \left[\begin{array}{cc} 1 & 0 \\ 0 & 2 \end{array}\right] \hspace{8mm} \left[\begin{array}{ccc} 0 & 1 & 2 \\ 1 & 0 & 1 \end{array}\right]\)

Activity 3

For each of the four matrices above that are not in RREF, determine which of the four conditions of a matrix in RREF are not true.

Activity 3 Solution

For the first matrix, the fourth condition is not true because there is a 3 in the same column as the leading 1 in the second row.
For the second matrix, the third condition is not true because there is a row with all 0 elements above a row with a non-zero element.
For the third matrix, the first condition is not true because the first element in the second row is 2, not a leading 1.
For the fourth matrix, the second condition is not true because the leading in the second row is in a column to the left of the leading 1 in the first row.

Example 5

What is the RREF of the matrix \(\begin{bmatrix} 2 & 7 \\ 1 & 1 \end{bmatrix}\)?

Solution 5

Our strategy is to first establish a leading 1 in Row 1

\(\begin{bmatrix} 2 & 7 \\ 1 & 1 \end{bmatrix} \substack{\xrightarrow[R_1 \leftrightarrow R_2]{}\\[2mm] \xrightarrow[]{R_2 \leftrightarrow R_1}} \begin{bmatrix} 1 & 1 \\ 2 & 7 \end{bmatrix} \substack{\xrightarrow[]{}\\[2mm] \xrightarrow[]{R_2 - 2 \times R_1}} \begin{bmatrix} 1 & 1 \\ 0 & 5 \end{bmatrix} \substack{\xrightarrow[]{}\\[2mm] \xrightarrow[]{\frac{1}{5} \times R_2}} \begin{bmatrix} 1 & 1 \\ 0 & 1 \end{bmatrix} \substack{\xrightarrow[]{R_1 - R_2}\\[2mm] \xrightarrow[]{}} \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}\)

Thus, we have that \(\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}\) is the RREF of \(\begin{bmatrix} 2 & 7 \\ 1 & 1 \end{bmatrix}\).

Activity 4

Determine the RREF of \(\begin{bmatrix} 2 & 6 & 4 \\ 1 & 2 & 5 \\ 2 & 1 & 1 \end{bmatrix}\) and \(\begin{bmatrix} 1 & 2 & -1 \\ 4 & 1 & 3 \\ 5 & 3 & 2 \end{bmatrix}\) using EROs. Show your work.

Activity 4 Solution

The RREF of the first matrix is determined by the following:

\(\begin{bmatrix} 2 & 6 & 4 \\ 1 & 2 & 5 \\ 2 & 1 & 1 \end{bmatrix} \substack{\xrightarrow[]{\frac{1}{2} \times R_1}\\[2mm] \xrightarrow[]{}\\[2mm] \xrightarrow[]{}} \begin{bmatrix} 1 & 3 & 2 \\ 1 & 2 & 5 \\ 2 & 1 & 1 \end{bmatrix} \substack{\xrightarrow[]{}\\[2mm] \xrightarrow[]{R_2 - R_1}\\[2mm] \xrightarrow[]{R_3 - 2 \times R_1}} \begin{bmatrix} 1 & 3 & 2 \\ 0 & -1 & 3 \\ 0 & -5 & -3 \end{bmatrix} \substack{\xrightarrow[]{}\\[2mm] \xrightarrow[]{-1 \times R_2}\\[2mm] \xrightarrow[]{}} \begin{bmatrix} 1 & 3 & 2 \\ 0 & 1 & -3 \\ 0 & -5 & -3 \end{bmatrix} \substack{\xrightarrow[]{R_1 - 3 \times R_2}\\[2mm] \xrightarrow[]{}\\[2mm] \xrightarrow[]{R_3 + 5 \times R_2}} \linebreak \vspace{4mm} \begin{bmatrix} 1 & 0 & 11 \\ 0 & 1 & -3 \\ 0 & 0 & -18 \end{bmatrix} \substack{\xrightarrow[]{}\\[2mm] \xrightarrow[]{}\\[2mm] \xrightarrow[]{-\frac{1}{18} \times R_3}} \begin{bmatrix} 1 & 0 & 11 \\ 0 & 1 & -3 \\ 0 & 0 & 1 \end{bmatrix} \substack{\xrightarrow[]{R_1 - 11 \times R_3}\\[2mm] \xrightarrow[]{R_2 + 3 \times R_3}\\[2mm] \xrightarrow[]{}} \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}\) Thus \(\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}\) is the RREF of \(\begin{bmatrix} 2 & 6 & 4 \\ 1 & 2 & 5 \\ 2 & 1 & 1 \end{bmatrix}\).

The RREF of the second matrix is given by:

\(\begin{bmatrix} 1 & 2 & -1 \\ 4 & 1 & 3 \\ 5 & 3 & 2 \end{bmatrix} \substack{\xrightarrow[]{}\\[2mm] \xrightarrow[]{R_2 - 4 \times R_1}\\[2mm] \xrightarrow[]{R_3 - 5 \times R_1}} \begin{bmatrix} 1 & 2 & -1 \\ 0 & -7 & 7 \\ 0 & -7 & 7 \end{bmatrix} \substack{\xrightarrow[]{}\\[2mm] \xrightarrow[]{-\frac{1}{7} \times R_2}\\[2mm] \xrightarrow[]{}} \begin{bmatrix} 1 & 2 & -1 \\ 0 & 1 & -1 \\ 0 & -7 & 7 \end{bmatrix} \substack{\xrightarrow[]{R_1 - 2 \times R_2}\\[2mm] \xrightarrow[]{}\\[2mm] \xrightarrow[]{R_3 + 7 \times R_2}} \begin{bmatrix} 1 & 0 & 1 \\ 0 & 1 & -1 \\ 0 & 0 & 0 \end{bmatrix}\)

Thus, \(\begin{bmatrix} 1 & 0 & 1 \\ 0 & 1 & -1 \\ 0 & 0 & 0 \end{bmatrix}\) is the RREF of \(\begin{bmatrix} 1 & 2 & -1 \\ 4 & 1 & 3 \\ 5 & 3 & 2 \end{bmatrix}\).

Solving Systems of Equations

Another method of solving systems of equations is by using matrices. This can be done by rewriting the system of equations as a special kind of matrix called an augmented matrix. For example, the system of equations:

\(2x - y = 3\)
\(-4x + 7y = 5\)

can be written as

\(\left[\begin{array}{cc|c} 2 & -1 & 3 \\ -4 & 7 & 5 \end{array}\right]\)

Here, the line between the second and third columns represents the ‘=’ in the equations. Each column on the left side of the line represents a variable, and the column on the right side of the line represents a constant value. Each row represents an equation. The elements of the matrix are coefficients of each variable in each equation. For example, the top left element of the matrix is the coefficient of \(x\) in the first equation, which we can see is \(2\).

In general, for a system of equations:

\(a_{11}x_1 + a_{12}x_2 + \dots + a_{1n}x_n = c_1\)
\(a_{21}x_1 + a_{22}x_2 + \dots + a_{2n}x_n = c_2\)

\(a_{m1}x_1 + a_{m2}x_2 + \dots + a_{mn}x_n = c_m\)

where \(x_1\), \(x_2\), …, \(x_n\) are the variables, \(a_{11}\), \(a_{12}\), …, \(a_{mn}\) are the coefficients, \(c_1\), \(c_2\), …, \(c_m\) are the constants, \(m\) is the number of equations, and \(n\) is the number of variables. This can be rewritten as the augmented matrix:
\(x_1\) \(x_2\)\(x_n\)

\(\left[\begin{array}{cccc|c} a_{11} & a_{12} & \dots & a_{1n} & c_1 \\ a_{21} & a_{22} & \dots & a_{2n} & c_2 \\ & & \vdots & & \\ a_{m1} & a_{m2} & \dots & a_{mn} & c_m \end{array}\right]\)

The variables are written above to indicate which column corresponds to each.

If the system of equations is underdetermined, the left side of the augmented matrix will have more columns than rows. If the system of equations is overdetermined, the left side of the augmented matrix will have more rows than columns. If the system of equations is balanced, the left side of the matrix will have the same number of rows and columns.

Once we have our system of equations written as an augmented matrix, all we need to do to solve the system is to transform the matrix into its RREF using the same steps as before. The only difference is that the last column does not need a leading 1.

Once the augmented matrix is in RREF, we can determine the number of solutions.

Example 6

Solve the problem from Example 3 using matrices.

Solution 6

Once again, we define variables to represent the number of marbles for each colour: \(b\) for blue, \(g\) for green, \(y\) for yellow, and \(r\) for red; which gives the following equations:

(1) \(b + r = 38\)
(2) \(g + r = 44\)
(3) \(y + r = 52\)
(4) \(b + g + y + r = 100\)

Now, we use the general form above to create the following augmented matrix:

\[\left[\begin{array}{cccc|c} 1 & 0 & 0 & 1 & 38 \\ 0 & 1 & 0 & 1 & 44 \\ 0 & 0 & 1 & 1 & 52 \\ 1 & 1 & 1 & 1 & 100 \end{array}\right]\]

The first column corresponds to the variable \(b\), the second to the variable \(g\), the third to \(y\) and the fourth to \(r\).

Now we transform the augmented matrix to RREF using the same strategy as before.

\(\left[\begin{array}{cccc|c} 1 & 0 & 0 & 1 & 38 \\ 0 & 1 & 0 & 1 & 44 \\ 0 & 0 & 1 & 1 & 52 \\ 1 & 1 & 1 & 1 & 100 \end{array}\right] \substack{\xrightarrow[]{}\\[1mm] \xrightarrow[]{} \\[1mm] \xrightarrow[]{}\\[1mm] \xrightarrow[]{R_4 - R_1}} \left[\begin{array}{cccc|c} 1 & 0 & 0 & 1 & 38 \\ 0 & 1 & 0 & 1 & 44 \\ 0 & 0 & 1 & 1 & 52 \\ 0 & 1 & 1 & 0 & 62 \end{array}\right] \substack{\xrightarrow[]{}\\[1mm] \xrightarrow[]{} \\[1mm] \xrightarrow[]{}\\[1mm] \xrightarrow[]{R_4 - R_2}} \left[\begin{array}{cccc|c} 1 & 0 & 0 & 1 & 38 \\ 0 & 1 & 0 & 1 & 44 \\ 0 & 0 & 1 & 1 & 52 \\ 0 & 0 & 1 & -1 & 18 \end{array}\right] \substack{\xrightarrow[]{}\\[1mm] \xrightarrow[]{} \\[1mm] \xrightarrow[]{}\\[1mm] \xrightarrow[]{R_4 - R_3}}\)

\(\left[\begin{array}{cccc|c} 1 & 0 & 0 & 1 & 38 \\ 0 & 1 & 0 & 1 & 44 \\ 0 & 0 & 1 & 1 & 52 \\ 0 & 0 & 0 & -2 & -34 \end{array}\right] \substack{\xrightarrow[]{}\\[1mm] \xrightarrow[]{} \\[1mm] \xrightarrow[]{}\\[1mm] \xrightarrow[]{-2 \times R_4}} \left[\begin{array}{cccc|c} 1 & 0 & 0 & 1 & 38 \\ 0 & 1 & 0 & 1 & 44 \\ 0 & 0 & 1 & 1 & 52 \\ 0 & 0 & 0 & 1 & 17 \end{array}\right] \substack{\xrightarrow[]{R_1 - R_4}\\[1mm] \xrightarrow[]{R_2 - R_4} \\[1mm] \xrightarrow[]{R_3 - R_4}\\[1mm] \xrightarrow[]{}} \left[\begin{array}{cccc|c} 1 & 0 & 0 & 0 & 21 \\ 0 & 1 & 0 & 0 & 27 \\ 0 & 0 & 1 & 0 & 35 \\ 0 & 0 & 0 & 1 & 17 \end{array}\right]\)

Thus, we have \(b = 21\), \(g = 27\), \(y = 35\) and \(r = 17\). So, there are 21 blue marbles, 27 green marbles, 35 yellow marbles, and 17 red marbles in the jar.