Systems of linear equations — theory with the post-gym shake, Gaussian elimination, Gauss-Jordan and Rouché-Frobenius (and the shake that could not exist)

One afternoon I tried to make my post-gym shake have exactly 15 g of protein and 7 g of fat using only oats and milk, and there was no way to make it add up. I would try an amount and go over on fat; I would lower it and fall short on protein. When I wrote it down as a system of equations I saw it: with oats and milk, protein is always twice the fat, and 15 is not twice 7. The system was inconsistent, and no afternoon of trial and error was going to fix it.

This topic is about exactly that: writing a problem as a system of linear equations, knowing how many solutions it has before solving it, and finding them in an orderly way. We will use everything from topic 1 on matrices and determinants: the augmented matrix, elementary operations, rank and the determinant. The example throughout the article is the shake: how many servings of oats, glasses of milk and bananas you need to hit specific grams of protein, carbohydrates and fat. After the theory comes the guided practice.

In a nutshell: a system of linear equations is a set of first-degree equations in several unknowns, and it can have one solution (consistent with a unique solution), infinitely many (consistent and underdetermined) or none (inconsistent). The Rouché-Frobenius theorem decides which by comparing the rank of the coefficient matrix with that of the augmented matrix, and Gaussian and Gauss-Jordan elimination solve it with elementary operations.

Before you start. For this topic you only need what you saw in topic 1 on matrices: knowing what the augmented matrix is, doing the three elementary row operations, counting the rank as the number of steps left after reducing to echelon form, and computing a 3×3 3 \times 3 determinant with Sarrus’ rule. Nothing else. The topic has three big ideas, in this order: writing a problem as a system (the shake); knowing how many solutions it has before solving it (one, infinitely many or none, with Rouché-Frobenius to decide using ranks); and solving it in an orderly way (Gaussian elimination, Gauss-Jordan and Cramer). If you get lost at any point, go back to the shake: the whole topic can be told with it.

The shake as a system of equations

These are the ingredients, with the rounded values from their labels:

Ingredient (per serving)Protein (g)Carbs (g)Fat (g)
Oats, 30 g4182
Semi-skimmed milk, 200 ml6103
Medium banana1240

Before using letters, let’s make the shake add up in our heads. I want 15 g of protein, 70 g of carbs and 7 g of fat. The question that decides everything is: which nutrient do I start with?

Fat. The banana has no fat, so the fat only depends on the oats and the milk: 2 g per serving of oats and 3 g per glass. And with 7 g in total there are very few ways to get there with whole servings:

I tryFatDoes it work?Why
0 servings of oats7 g missing, and glasses of 3 g cannot make 7no7 is not a multiple of 3
1 serving of oats2 g; 5 missingno5 is not a multiple of 3 either
2 servings of oats4 g; 3 missing, one glass of milkyes4 + 3 = 7 exactly
3 servings of oats6 g; 1 missingnoOne glass is already 3 g: you overshoot

With two servings of oats and one glass of milk I already have 8+6=14 8 + 6 = 14 g of protein. I am 1 g short, and that is exactly one banana. Now the acid test, the carbs: 36+10+24=70 36 + 10 + 24 = 70 . Everything adds up.

Look at what you have just done: you started with the equation with the fewest ingredients, fixed two amounts and used what you knew to get the third. That is exactly the idea behind Gaussian elimination, which you will see further down. With whole servings it worked by eye, but if the targets were 15, 70 and 8 there would be no round numbers and trial and error would not help. That is why you need a method. Now, the same thing with letters:

I want 15 g of protein, 70 g of carbs and 7 g of fat. If I call xx the servings of oats, yy the glasses of milk and zz the bananas, each nutrient gives an equation:

4x+6y+z=15(protein)18x+10y+24z=70(carbs)2x+3y=7(fat) \begin{array}{rcll} 4x + 6y + z & = & 15 & \quad \text{(protein)} \\ 18x + 10y + 24z & = & 70 & \quad \text{(carbs)} \\ 2x + 3y & = & 7 & \quad \text{(fat)} \end{array}

That is a system of linear equations: m=3m = 3 equations in n=3n = 3 unknowns, all of first degree (no x2x^2, no xyxy, no x\sqrt{x}). The numbers multiplying the unknowns are the coefficients, and those on the right are the constant terms. A solution is a set of values that satisfies all the equations at once, and solving the system means finding all its solutions.

Is x=2x = 2, y=1y = 1, z=1z = 1 a solution? I substitute: 8+6+1=158 + 6 + 1 = 15, 36+10+24=7036 + 10 + 24 = 70 and 4+3=74 + 3 = 7. All three hold: two servings of oats, one glass of milk and one banana. What about x=3x = 3, y=0y = 0, z=3z = 3? In the first, 12+0+3=1512 + 0 + 3 = 15, fine; in the second, 54+0+72=126≠7054 + 0 + 72 = 126 \neq 70. It does not work: satisfying one equation is not enough.

One, infinitely many or none: how systems are classified

By their solutions, a system can be (the course uses the Spanish abbreviations in brackets):

  • Consistent with a unique solution (CD, compatible determinado): exactly one solution.
  • Consistent with infinitely many solutions (CI, compatible indeterminado).
  • Inconsistent (I, incompatible): no solution at all.

There is no middle ground: a linear system never has exactly two or three solutions. If it has two different ones, it has infinitely many (all those on the “path” between them).

With two unknowns you can see it by drawing: each equation is a line, and the solutions are the common points. With oats (xx) and banana (zz) for 9 g of protein and 60 g of carbs, the lines 4x+z=94x + z = 9 and 18x+24z=6018x + 24z = 60 cross at one point, (2,1)(2, 1): unique solution. With oats and milk for 15 g of protein and 7 of fat, the lines 4x+6y=154x + 6y = 15 and 2x+3y=72x + 3y = 7 are parallel: inconsistent. And if I ask for 14 g of protein instead of 15, 4x+6y=144x + 6y = 14 is the same line as 2x+3y=72x + 3y = 7 multiplied by 2: infinitely many points.

Two equations, two linesThree graphs: two lines meeting at the point (2, 1), two parallel lines with no common point, and two equations that draw the same line.Unique solutionoats (x) and banana (z)012301234xz4x + z = 918x + 24z = 60No solutionoats (x) and milk (y)012301234xy4x + 6y = 152x + 3y = 7Infinitely manyoats (x) and milk (y)012301234xy4x + 6y = 142x + 3y = 7
Meeting, being parallel or coinciding: there are no other options.

Some clues from the size (mm equations, nn unknowns):

  • With m=nm = n, it can be CD, CI or I.
  • With m<nm < n, it is never CD: there are not enough equations to pin down every unknown, so it is CI or I.
  • With m>nm > n, there are “extra” equations and it is usually I… but not always. If the extra equations are combinations of the others, it can be CD or CI. With oats and milk and the three targets 14, 46 and 7, you get x=2x = 2, y=1y = 1: three equations, two unknowns and one solution.

Saying that a system with more equations than unknowns is always inconsistent. The Campus quiz sets exactly that trap. What decides is the rank, not the number of equations.

Homogeneous systems

A system is homogeneous if all its constant terms are 0. In the shake: is there a mix that gives 0 g of everything?

4x+6y+z=018x+10y+24z=02x+3y=0 \begin{array}{rcl} 4x + 6y + z & = & 0 \\ 18x + 10y + 24z & = & 0 \\ 2x + 3y & = & 0 \end{array}

A homogeneous system is always consistent, because x=y=z=0x = y = z = 0 satisfies every equation: that is the trivial solution. So all that is left is to know whether it is the only one (CD) or whether there are more, and then infinitely many (CI). It is never inconsistent. In the shake, the only solution is the trivial one (you will see it with the rank): the only mix that adds nothing is putting nothing in. More interesting will be the homogeneous system in the practice, with four ingredients, which has infinitely many solutions, each one a “swap” of ingredients that leaves the macros unchanged.

The system as a matrix

Every system can be written as AX=BAX = B: AA is the coefficient matrix, XX the column of unknowns and BB the column of constant terms. And the augmented matrix (A∣B)(A \mid B) attaches BB to the right of AA:

(A∣B)=(46115181024702307) (A \mid B) = \left(\begin{array}{ccc|c} 4 & 6 & 1 & 15 \\ 18 & 10 & 24 & 70 \\ 2 & 3 & 0 & 7 \end{array}\right)

In the shake, each row is a nutrient, each column of AA is an ingredient and the last column is what I ask for. Read the diagram slowly: the oats column is its nutrition label, (4,18,2)(4, 18, 2).

The augmented matrix of the shakeThe 3 by 4 augmented matrix: rows protein, carbs and fat; columns oats, milk and banana, separated by a bar from the target column 15, 70, 7. The oats column, 4, 18, 2, is highlighted.46115181024702307oatsmilkbananatargetproteincarbsfatA (coefficients)Bone column =one food labelone row = one equation
Each column of A is an ingredient; the bar separates what you put in from what you ask for.

Equivalent systems and elementary operations

Two systems are equivalent if they have the same solutions. And the three elementary operations from topic 1, applied to the equations (or to the rows of the augmented matrix), always give an equivalent system:

On the equationsOn the augmented matrix
Swap two equationsfi↔fjf_i \leftrightarrow f_j
Multiply an equation by k≠0k \neq 0fi→kfif_i \to k f_i
Add another equation times kk to an equationfi→fi+kfjf_i \to f_i + k f_j

The idea behind both methods is the same: keep replacing the system with an equivalent one that is easier each time, until it solves itself.

In a system you can multiply a row by 2 without fear; the solutions do not change. What changed in topic 1 was the determinant, not the solutions. To get rid of fractions while solving, multiplying is your friend.

Why do elementary operations not change the solutions? Look at it with the shake. If (2,1,1) (2, 1, 1) satisfies the protein equation (it gives 15) and the fat equation (it gives 7), it also satisfies the equation you get by adding the fat equation multiplied by k k to the protein one: the left-hand side gives 15+7k 15 + 7k and on the right you put 15+7k 15 + 7k . So no solution is lost.

And none is gained either, because every operation can be undone: if you add k k times another row to a row, subtracting k k times that row again takes you back to where you were. That is why multiplying by 0 is not allowed: it wipes out the equation and there is no way to get it back.

Doing column operations when solving a system. They are fine for computing a rank, but in a system each column is an unknown: if you add the oats column to the milk column, the system you are left with no longer talks about oats and milk. To solve, rows only.

Gaussian elimination

Goal: bring the augmented matrix to echelon form (zeros below each pivot) and solve from the last equation upwards, substituting. For the shake, I put the fat equation first, since it has a 0 and small numbers, and halve the carbs equation:

(23074611518102470)→f3→12f3(230746115951235) \left(\begin{array}{ccc|c} 2 & 3 & 0 & 7 \\ 4 & 6 & 1 & 15 \\ 18 & 10 & 24 & 70 \end{array}\right) \xrightarrow{f_3 \to \frac12 f_3} \left(\begin{array}{ccc|c} 2 & 3 & 0 & 7 \\ 4 & 6 & 1 & 15 \\ 9 & 5 & 12 & 35 \end{array}\right)

First column: with the 2 at the top I clear the 4 and the 9. For the 9 I use f3→2f3−9f1f_3 \to 2f_3 – 9f_1 so that no halves appear:

→f3→2f3−9f1f2→f2−2f1(230700110−17247)→f2↔f3(23070−172470011) \xrightarrow[f_3 \to 2f_3 – 9f_1]{f_2 \to f_2 – 2f_1} \left(\begin{array}{ccc|c} 2 & 3 & 0 & 7 \\ 0 & 0 & 1 & 1 \\ 0 & -17 & 24 & 7 \end{array}\right) \xrightarrow{f_2 \leftrightarrow f_3} \left(\begin{array}{ccc|c} 2 & 3 & 0 & 7 \\ 0 & -17 & 24 & 7 \\ 0 & 0 & 1 & 1 \end{array}\right)

Check row 3 in the middle matrix: 2⋅9−9⋅2=02 \cdot 9 – 9 \cdot 2 = 0, 2⋅5−9⋅3=10−27=−172 \cdot 5 – 9 \cdot 3 = 10 – 27 = -17, 2⋅12−9⋅0=242 \cdot 12 – 9 \cdot 0 = 24 and 2⋅35−9⋅7=70−63=72 \cdot 35 – 9 \cdot 7 = 70 – 63 = 7. In row 2, both xx and yy vanished at once, so I swap it with row 3 to get the staircase. It is now in echelon form (the strict definition would also divide each row by its pivot, but you do not need that to solve). Now, from the bottom up:

  • Row 3: z=1z = 1.
  • Row 2: −17y+24⋅1=7⇒−17y=−17⇒y=1-17y + 24 \cdot 1 = 7 \Rightarrow -17y = -17 \Rightarrow y = 1.
  • Row 1: 2x+3⋅1=7⇒2x=4⇒x=22x + 3 \cdot 1 = 7 \Rightarrow 2x = 4 \Rightarrow x = 2.

Two servings of oats, one glass of milk and one banana, the solution we had already checked. The diagram shows the whole journey with the staircase taking shape.

Gaussian elimination on the shakeThree stages of the augmented matrix: the fat equation on top and the carbs equation halved; the first column cleared; rows 2 and 3 swapped to form the staircase with pivots 2, −17 and 1. Below, back substitution: z = 1, y = 1, x = 2.f₃ → ½f₃230746115951235f₂−2f₁, f₃→2f₃−9f₁230700110-17247f₂ ↔ f₃23070-172470011from the bottom up:z = 1 → −17y + 24 = 7, y = 1 → 2x + 3 = 7, x = 2
Gaussian elimination stops at the staircase; the rest is substituting from the bottom up.

Gaussian elimination, operation by operation

It is the same calculation as above, with the reason for each decision. What matters is not the arithmetic but the criterion: at each step you have to know which zero you are after.

StepOperationWhat you getWhy
1I put fat at the topPivot 2 in the first rowIt has a 0 and the smallest numbers: it is the row that makes clearing cheapest
2f3→12f3 f_3 \to \frac12 f_3 The carbs row becomes (9  5  12∣35) (9 \; 5 \; 12 \mid 35) All its numbers are even: dividing by 2 makes the arithmetic cheaper and does not change the solutions
3f2→f2−2f1 f_2 \to f_2 – 2f_1 (0  0  1∣1) (0 \; 0 \; 1 \mid 1) I want a 0 below the pivot 2, and 4−2⋅2=0 4 – 2 \cdot 2 = 0
4f3→2f3−9f1 f_3 \to 2f_3 – 9f_1 (0  −17  24∣7) (0 \; {-17} \; 24 \mid 7) Clearing the 9 with the 2 would mean subtracting 92f1 \frac92 f_1 ; multiplying the row by 2 first avoids the halves
5f2↔f3 f_2 \leftrightarrow f_3 The staircase is rightIn row 2 both x x and y y vanished at once: it has to go last
6I read row 3z=1 z = 1 Only one unknown is left in that row
7I substitute into row 2y=1 y = 1 I already know z z , so only y y is left
8I substitute into row 1x=2 x = 2 I already know y y ; the 0 in front of z z is not even needed
Check you’ve got it: which shake do you get if you ask for 17 g of protein, 62 of carbs and 8 of fat?

One serving of oats, two glasses of milk and one banana, (1,2,1) (1, 2, 1) . Step by step, with the same operations: the reordered augmented matrix is (2  3  0∣8) (2 \; 3 \; 0 \mid 8) , (4  6  1∣17) (4 \; 6 \; 1 \mid 17) and (18  10  24∣62) (18 \; 10 \; 24 \mid 62) ; dividing the last one by 2 gives (9  5  12∣31) (9 \; 5 \; 12 \mid 31) . With f2→f2−2f1 f_2 \to f_2 – 2f_1 you get (0  0  1∣1) (0 \; 0 \; 1 \mid 1) , and with f3→2f3−9f1 f_3 \to 2f_3 – 9f_1 , (0  −17  24∣62−72)=(0  −17  24∣−10) (0 \; {-17} \; 24 \mid 62 – 72) = (0 \; {-17} \; 24 \mid {-10}) . You swap them and go from the bottom up: z=1 z = 1 ; −17y+24=−10 -17y + 24 = -10 , so −17y=−34 -17y = -34 and y=2 y = 2 ; 2x+6=8 2x + 6 = 8 , so x=1 x = 1 . Check: 4+12+1=17 4 + 12 + 1 = 17 , 18+20+24=62 18 + 20 + 24 = 62 and 2+6=8 2 + 6 = 8 .

The Rouché-Frobenius theorem

Now the important question: how do I know how many solutions there are before solving? With the augmented matrix in echelon form, I call:

  • pp: the number of steps (non-zero rows) of AA, that is, rg(A)rg(A).
  • qq: the number of steps of (A∣B)(A \mid B), that is, rg(A∣B)rg(A \mid B).
  • nn: the number of unknowns (columns of AA).

And the Rouché-Frobenius theorem says:

RanksClassificationSolutions
p=q=np = q = nConsistent, unique solutionOne
p=q<np = q < nConsistent, infinitely manyInfinitely many, with n−pn – p degrees of freedom
p<qp < qInconsistentNone

Since AA is part of (A∣B)(A \mid B), always p≤qp \le q. For qq to be larger means that row reducing produces a row (0  0  ⋯  0∣c)(0 \; 0 \; \cdots \; 0 \mid c) with c≠0c \neq 0, that is, the impossible equation 0=c0 = c. In the shake, p=q=3=np = q = 3 = n: a unique solution.

With oats and milk for 15 of protein and 7 of fat, the augmented matrix is (4615237)\left(\begin{array}{cc|c} 4 & 6 & 15 \\ 2 & 3 & 7 \end{array}\right) and f1→f1−2f2f_1 \to f_1 – 2f_2 gives the row (0  0∣1)(0 \; 0 \mid 1): “0=10 = 1”. There is my lost afternoon: p=1<q=2p = 1 < q = 2, inconsistent. The tree in the diagram sums up the decision.

Rouché-Frobenius in two questionsDecision tree: if the rank of A is less than that of the augmented matrix, no solution; if they match and equal n, a unique solution; if they match and are below n, infinitely many with n minus p parameters. Each leaf has an example from the shake.p = q?p = rg(A), q = rg(A | B), n = unknownsno (p < q)yesIncompatible0 = c appearsoats + milk: 15 and 7p = n?yesno (p < n)Unique solutionone solutionthe shake: (2, 1, 1)Infinitely manyn − p parameterswith ricotta: 1
Two rank comparisons and you know what you will find.

The three shakes, read with Rouché

Rouché-Frobenius, in words: reduce the augmented matrix to echelon form and count the steps with and without the last column. If the last column adds a step, there is a row that says “0 = something that is not 0”, and there is no solution. If it does not, there is a solution, and what is left to know is whether there are unknowns to spare, which will be the ones you can choose. These are the article’s three shakes:

ShakeEchelon formp p q q n n TypeWhy
Oats, milk and bananaThree non-zero rows333CDNo 0=c 0 = c appears and every unknown has its step
With ricottaThree non-zero rows, four columns334CIThere is a solution, but the ricotta column has no step: 1 degree of freedom
Only oats and milk(2  3∣7) (2 \; 3 \mid 7) and (0  0∣1) (0 \; 0 \mid 1) 122IThe second row only has a step in the right-hand column: it is 0=1 0 = 1
Check you’ve got it: what does Rouché say about the homogeneous shake system?

That it has a unique solution (CD): only the trivial one. Step by step: the last column is all zeros, so it stays all zeros when you reduce and can never add a step; that is why p=q p = q , as in any homogeneous system. And A A is the same shake matrix, with ∣A∣=34≠0 |A| = 34 \neq 0 , so its rank is 3: p=q=n=3 p = q = n = 3 . The only mix that gives 0 g of everything is putting nothing in.

Thinking that a row of zeros in the augmented matrix makes the system inconsistent. The row (0  0  0∣0)(0 \; 0 \; 0 \mid 0) is the equation 0=00 = 0, which always holds: it is simply redundant. What is inconsistent is (0  0  0∣c)(0 \; 0 \; 0 \mid c) with c≠0c \neq 0. This is another classic from the quiz.

A system with a parameter: how much protein can oats and milk give?

In the exam they do not usually give you every number: one is left as a letter and you are asked for which values the system is of one type or another. My lost afternoon shows it very well. Only oats and milk, 7 g of fat and k k grams of protein:

(46k237) \left(\begin{array}{cc|c} 4 & 6 & k \\ 2 & 3 & 7 \end{array}\right)

You do it as if k k were a number; you just leave the letter wherever it lands:

StepWhat I doWhat comes outWhy
1f1→f1−2f2 f_1 \to f_1 – 2f_2 (0  0∣k−14) (0 \; 0 \mid k – 14) The protein row is exactly twice the fat row in both columns: 4=2⋅2 4 = 2 \cdot 2 and 6=2⋅3 6 = 2 \cdot 3
2I look at the term that is leftk−14 k – 14 It is the only thing that depends on k k , and it decides whether that row is 0=0 0 = 0 or 0=c 0 = c
3If k≠14 k \neq 14 0=k−14≠0 0 = k – 14 \neq 0 An impossible equation: inconsistent
4If k=14 k = 14 0=0 0 = 0 The row is redundant and a single equation is left, 2x+3y=7 2x + 3y = 7 , with two unknowns: infinitely many solutions (CI)

The conclusion, in words: with oats and milk, the protein has to be exactly twice the fat. With 14 g there are infinitely many shakes (one is two servings of oats and one glass of milk); with any other amount, none. That is what I could not see that afternoon.

Check you’ve got it: what if I also leave the fat as a letter, g?

It is consistent only if k=2g k = 2g , and then it has infinitely many solutions. Step by step: the augmented matrix is the one from before with a g g instead of the 7; f1→f1−2f2 f_1 \to f_1 – 2f_2 gives the row (0  0∣k−2g) (0 \; 0 \mid k – 2g) . If k−2g≠0 k – 2g \neq 0 , it is the impossible equation: inconsistent. If k=2g k = 2g , the row is 0=0 0 = 0 , one equation with two unknowns is left and there are infinitely many solutions. It is the sentence from the opening story, written with letters: protein is always twice the fat.

Pivot unknowns, free unknowns and degrees of freedom

In an echelon matrix, the pivot unknowns are those whose columns have a pivot and the free unknowns (or parameters) are the rest. The number of free unknowns is n−pn – p, the degrees of freedom of the system: how many numbers you can choose as you like before the rest is fixed.

An example with the shake. I add a fourth ingredient, ricotta (80 g: 8 g of protein, 2 of carbs, 4 of fat), with tt servings. With the same targets, the system has 3 equations and 4 unknowns, and its reduced row echelon form is:

(100−120102100101) \left(\begin{array}{cccc|c} 1 & 0 & 0 & -1 & 2 \\ 0 & 1 & 0 & 2 & 1 \\ 0 & 0 & 1 & 0 & 1 \end{array}\right)

p=q=3<n=4p = q = 3 < n = 4: consistent with infinitely many solutions and 4−3=14 – 3 = 1 degree of freedom. The pivot unknowns are x,y,zx, y, z and the free one is tt. Reading each row and moving tt to the right:

x=2+t,y=1−2t,z=1,t∈R x = 2 + t, \qquad y = 1 – 2t, \qquad z = 1, \qquad t \in \mathbb{R}

Each value of tt is a different shake with the same macros. With t=0t = 0 it is the one from before; with t=12t = \tfrac12, two and a half servings of oats, no milk, one banana and half a serving of ricotta. The maths accepts any tt, but in the kitchen there are no negative amounts: y≥0y \ge 0 forces t≤12t \le \tfrac12, and t≥0t \ge 0, so in real life tt goes from 0 to 12\tfrac12. You can see it in the diagram.

Pivot and free unknownsThe reduced row echelon form of the shake with ricotta: the columns of x, y, z have a pivot and that of t is free. On the right, the solution with parameter t and the interval from 0 to one half where every amount is non-negative.100-120102100101xyztpivotfreex = 2 + ty = 1 − 2tz = 1t ∈ ℝ−½0½1in the kitcheny ≥ 0 and t ≥ 0
One degree of freedom: you choose t and everything else is fixed.

How to read the ricotta reduced form, row by row

The reduced form has three rows and four columns of unknowns. Each row is an equation, and the rule is always the same: the pivot unknown stays on the left and the free one moves to the right with its sign changed.

RowEquation it saysI solve forWhy
1x−t=2 x – t = 2 x=2+t x = 2 + t The −1 -1 in the fourth column multiplies t t ; moving it to the right changes its sign
2y+2t=1 y + 2t = 1 y=1−2t y = 1 – 2t Same: the 2t 2t moves across as a subtraction
3z=1 z = 1 z=1 z = 1 In that row the t t column has a 0: the banana does not depend on the ricotta

For the shake to be real, no amount can be negative. You check it unknown by unknown: t≥0 t \ge 0 because the ricotta cannot be negative either; y=1−2t≥0 y = 1 – 2t \ge 0 gives t≤12 t \le \frac12 ; x=2+t≥0 x = 2 + t \ge 0 gives t≥−2 t \ge -2 , which already holds; and z=1 z = 1 always works. That is where the interval from 0 to 12 \frac12 comes from.

And here you can see why a system never has exactly two solutions. The shake with t=0 t = 0 and the one with t=12 t = \frac12 give the same macros. If you mix half of one with half of the other, so does the result: you get t=14 t = \frac14 , with x=94 x = \frac94 , y=12 y = \frac12 and z=1 z = 1 , and it gives 15, 70 and 7 again. Each equation is a sum of ingredients times numbers, so mixing two solutions in parts that add up to 1 always gives another solution. Between two solutions there are infinitely many.

Gauss-Jordan elimination

Goal: reach the reduced row echelon form, with zeros above each pivot as well, so you can read the solution without substituting. You start from the echelon form of Gaussian elimination and clear the entries above the pivots from the bottom up, dividing each row by its pivot when it is its turn. With the shake:

(23070−172470011)→f2→f2−24f3(23070−170−170011)→f2→−117f2(230701010011) \left(\begin{array}{ccc|c} 2 & 3 & 0 & 7 \\ 0 & -17 & 24 & 7 \\ 0 & 0 & 1 & 1 \end{array}\right) \xrightarrow{f_2 \to f_2 – 24f_3} \left(\begin{array}{ccc|c} 2 & 3 & 0 & 7 \\ 0 & -17 & 0 & -17 \\ 0 & 0 & 1 & 1 \end{array}\right) \xrightarrow{f_2 \to -\frac{1}{17} f_2} \left(\begin{array}{ccc|c} 2 & 3 & 0 & 7 \\ 0 & 1 & 0 & 1 \\ 0 & 0 & 1 & 1 \end{array}\right)
→f1→f1−3f2(200401010011)→f1→12f1(100201010011) \xrightarrow{f_1 \to f_1 – 3f_2} \left(\begin{array}{ccc|c} 2 & 0 & 0 & 4 \\ 0 & 1 & 0 & 1 \\ 0 & 0 & 1 & 1 \end{array}\right) \xrightarrow{f_1 \to \frac12 f_1} \left(\begin{array}{ccc|c} 1 & 0 & 0 & 2 \\ 0 & 1 & 0 & 1 \\ 0 & 0 & 1 & 1 \end{array}\right)

The last column is the solution, (2,1,1)(2, 1, 1), with no substitution at all. Gauss-Jordan takes a bit more arithmetic than Gaussian elimination, but for a system with infinitely many solutions it is much more convenient: the reduced form gives you each pivot unknown already solved in terms of the free ones, as in the ricotta example.

The zeros above are cleared from the bottom up, just as with the inverse in topic 1: the pivot of the last row spoils nothing when you use it, because it has zeros to its left.

Gauss-Jordan, with the reason for each zero

Gauss-Jordan picks up where Gaussian elimination stopped. The echelon form already has zeros below the pivots; now you make them above, starting with the bottom one:

StepOperationWhat comes outWhy
1f2→f2−24f3 f_2 \to f_2 – 24f_3 (0  −17  0∣−17) (0 \; {-17} \; 0 \mid {-17}) I remove the 24 above the pivot of z z ; since row 3 is (0  0  1∣1) (0 \; 0 \; 1 \mid 1) , the right-hand side becomes 7−24=−17 7 – 24 = -17
2f2→−117f2 f_2 \to -\frac{1}{17} f_2 (0  1  0∣1) (0 \; 1 \; 0 \mid 1) I divide by the pivot so that it is 1: you can already read y=1 y = 1
3f1→f1−3f2 f_1 \to f_1 – 3f_2 (2  0  0∣4) (2 \; 0 \; 0 \mid 4) I remove the 3 above the pivot of y y : 7−3⋅1=4 7 – 3 \cdot 1 = 4 . Row 1 had no z z already
4f1→12f1 f_1 \to \frac12 f_1 (1  0  0∣2) (1 \; 0 \; 0 \mid 2) I divide by the pivot: x=2 x = 2

Cramer’s rule

If the system is square (m=nm = n) and ∣A∣≠0|A| \neq 0, it has a unique solution and each unknown can be computed with determinants:

xi=∣Ai∣∣A∣ x_i = \frac{|A_i|}{|A|}

where AiA_i is the matrix AA with column ii replaced by the constant terms. In the shake, ∣A∣=34|A| = 34 (by Sarrus: 0+288+54−20−0−288=340 + 288 + 54 – 20 – 0 – 288 = 34). For xx, I replace the oats column with (15,70,7)(15, 70, 7):

x=∣1561701024730∣34=0+1008+210−70−0−108034=6834=2 x = \frac{\begin{vmatrix} 15 & 6 & 1 \\ 70 & 10 & 24 \\ 7 & 3 & 0 \end{vmatrix}}{34} = \frac{0 + 1008 + 210 – 70 – 0 – 1080}{34} = \frac{68}{34} = 2

Likewise, ∣A2∣=34|A_2| = 34 and ∣A3∣=34|A_3| = 34, so y=1y = 1 and z=1z = 1. The diagram shows which column is replaced for each unknown.

Cramer's ruleThree determinants: in each one, the column of an unknown is replaced by the target column 15, 70, 7. They are worth 68, 34 and 34, and dividing by the determinant 34 gives x = 2, y = 1, z = 1.|A1|1561701024730x = 68 / 34 = 2|A2|4151187024270y = 34 / 34 = 1|A3|4615181070237z = 34 / 34 = 1the target column replaces the column of the unknown
One column replaced per unknown, and always the same denominator |A| = 34.

Cramer is handy for 2×22 \times 2 or 3×33 \times 3 systems and when you are only asked for one unknown. But it does not work if ∣A∣=0|A| = 0 (you would divide by 0) or if the system is not square, and with large numbers, as here, the determinants weigh more than Gaussian elimination.

Applying Cramer with ∣A∣=0|A| = 0 and concluding that “there is no solution”. If ∣A∣=0|A| = 0, Cramer says nothing: the system may have infinitely many solutions or none, and you have to look at the ranks.

Cramer in the shake, determinant by determinant

Before the rule, the idea in words: each unknown is a quotient. The bottom is always the same number, ∣A∣ |A| , which only depends on the ingredients. The top is the determinant of A A with that ingredient’s column replaced by what you ask for. You already have ∣A∣=34 |A| = 34 and ∣A1∣=68 |A_1| = 68 . These are the other two, by Sarrus:

UnknownColumn I replaceSarrusValue
y y (milk)The second, with (15,70,7) (15, 70, 7) 0+720+126−140−672−0 0 + 720 + 126 – 140 – 672 – 0 ∣A2∣=34 \lvert A_2 \rvert = 34 , so y=1 y = 1
z z (banana)The third, with (15,70,7) (15, 70, 7) 280+840+810−300−840−756 280 + 840 + 810 – 300 – 840 – 756 ∣A3∣=34 \lvert A_3 \rvert = 34 , so z=1 z = 1
Check you’ve got it: can you use Cramer in the ricotta shake?

No. Step by step: with ricotta there are 3 equations and 4 unknowns, so A A is 3×4 3 \times 4 and has no determinant. Cramer only works with square systems and ∣A∣≠0 |A| \neq 0 , that is, when the system has a unique solution. A system with infinitely many solutions can never give you each unknown as a single number, which is exactly what the formula gives. For the ricotta, Gauss-Jordan.

The same in MATLAB

In the MATLAB assignments you classify with rank and solve with rref, as explained in MATLAB from scratch (2): scripts, systems and syms. With the shake:

A = [4 6 1; 18 10 24; 2 3 0];   % rows: protein, carbs, fat
B = [15; 70; 7];                % what I ask for
p = rank(A), q = rank([A B]), n = size(A, 2)
rref([A B])                     % Gauss-Jordan: the last column is the solution
det(A)

Output:

p =

     3

q =

     3

n =

     3

ans =

     1     0     0     2
     0     1     0     1
     0     0     1     1

ans =

    34

p=q=n=3p = q = n = 3: a unique solution, and rref gives it in the last column. Now with ricotta, infinitely many:

format rat
A4 = [4 6 1 8; 18 10 24 2; 2 3 0 4];  % 4 ingredients
p = rank(A4), q = rank([A4 B]), n = size(A4, 2)
rref([A4 B])

Output:

p =

       3       

q =

       3       

n =

       4       

ans =

       1              0              0             -1              2       
       0              1              0              2              1       
       0              0              1              0              1       

p=q=3<n=4p = q = 3 < n = 4: one degree of freedom, and the reduced form is the one we read by hand. And the impossible shake, with only oats and milk:

A2 = [4 6; 2 3];                % protein and fat
B2 = [15; 7];
rank(A2), rank([A2 B2])         % 1 versus 2: inconsistent
rref([A2 B2])                   % the row 0 0 1 is the equation 0 = 1

Output:

ans =

       1       

ans =

       2       

ans =

       1              3/2            0       
       0              0              1       

The last row of rref, 0 0 1, is the impossible equation 0=10 = 1 written as a matrix.

Try it in the MATLAB playground

In the MATLAB playground on the site you can play with the shake targets:

% The shake: oats (x), milk (y), banana (z)
A = [4 6 1; 18 10 24; 2 3 0];
B = [15; 70; 7];              % protein, carbs, fat
if rank(A) == rank([A B])
    disp('Consistent')
else
    disp('Inconsistent')
end
R = rref([A B])               % the solution, in the last column

Things to look at:

  1. Change B to [17; 62; 8] and check that you get another shake with whole numbers.
  2. Try B = [15; 70; 8]: the solution has fractions and some negative amounts. The maths solves it, but the kitchen does not accept a negative banana.
  3. Remove the banana column (A = A(:, 1:2)) and see what the ranks say with the original B.
  4. In the Workspace, look at the size of R: 3×43 \times 4, the reduced augmented matrix.

Summary

ConceptWhat it isHow to recognise it
Linear systemAX=BAX = B, first-degree equationsCoefficient and augmented matrices
Unique solution (CD)One solutionrg(A)=rg(A∣B)=nrg(A) = rg(A \mid B) = n
Infinitely many (CI)Infinitely many solutionsrg(A)=rg(A∣B)<nrg(A) = rg(A \mid B) < n, with n−rg(A)n – rg(A) parameters
Inconsistent (I)No solutionrg(A)<rg(A∣B)rg(A) < rg(A \mid B): 0=c0 = c with c≠0c \neq 0 appears
HomogeneousConstant terms 0Always consistent (trivial solution)
Gaussian eliminationEchelon form and back substitutionZeros below the pivots
Gauss-JordanReduced echelon form, read the solutionZeros above and below
Cramerxi=∣Ai∣/∣A∣x_i = \lvert A_i \rvert / \lvert A \rvertOnly if square and ∣A∣≠0\lvert A \rvert \neq 0

Three ideas to take away:

  1. Before solving, classify: compare rg(A)rg(A), rg(A∣B)rg(A \mid B) and nn. Rouché-Frobenius tells you how many solutions you are going to find.
  2. A row (0  ⋯  0∣0)(0 \; \cdots \; 0 \mid 0) is redundant; a row (0  ⋯  0∣c)(0 \; \cdots \; 0 \mid c) with c≠0c \neq 0 makes the system inconsistent.
  3. In a system with infinitely many solutions, the free unknowns are the parameters: the pivot unknowns are written in terms of them, and each choice of parameters is a different solution.

Now it is your turn: in the guided practice on systems of linear equations we solve five problems step by step, checked in MATLAB, with ricotta, the swaps that leave the macros unchanged and a system with a parameter like the exam ones; and in the Gauss-Jordan step-by-step simulator you can solve any system watching each operation with exact fractions and its Rouché classification. And to check you have got it, the systems of linear equations exercises go from easy to hard, come with commented solutions and include a quiz like the Campus ones. Next comes topic 3, vector spaces, where these systems are used to find bases.

Next step: practiceSystems of linear equations — guided practice with five shake problems, Rouché without solving and an exam-style parameter (and the equation I forgot to copy)

Did this article help you? Here is how you can support SergioLearns →