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.
Table of Contents
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 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 g | 4 | 18 | 2 |
| Semi-skimmed milk, 200 ml | 6 | 10 | 3 |
| Medium banana | 1 | 24 | 0 |
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 try | Fat | Does it work? | Why |
|---|---|---|---|
| 0 servings of oats | 7 g missing, and glasses of 3 g cannot make 7 | no | 7 is not a multiple of 3 |
| 1 serving of oats | 2 g; 5 missing | no | 5 is not a multiple of 3 either |
| 2 servings of oats | 4 g; 3 missing, one glass of milk | yes | 4 + 3 = 7 exactly |
| 3 servings of oats | 6 g; 1 missing | no | One glass is already 3 g: you overshoot |
With two servings of oats and one glass of milk I already have g of protein. I am 1 g short, and that is exactly one banana. Now the acid test, the carbs: . 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 the servings of oats, the glasses of milk and the bananas, each nutrient gives an equation:
That is a system of linear equations: equations in unknowns, all of first degree (no , no , no ). 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 , , a solution? I substitute: , and . All three hold: two servings of oats, one glass of milk and one banana. What about , , ? In the first, , fine; in the second, . 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 () and banana () for 9 g of protein and 60 g of carbs, the lines and cross at one point, : unique solution. With oats and milk for 15 g of protein and 7 of fat, the lines and are parallel: inconsistent. And if I ask for 14 g of protein instead of 15, is the same line as multiplied by 2: infinitely many points.
Some clues from the size ( equations, unknowns):
- With , it can be CD, CI or I.
- With , it is never CD: there are not enough equations to pin down every unknown, so it is CI or I.
- With , 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 , : 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?
A homogeneous system is always consistent, because 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 : is the coefficient matrix, the column of unknowns and the column of constant terms. And the augmented matrix attaches to the right of :
In the shake, each row is a nutrient, each column of is an ingredient and the last column is what I ask for. Read the diagram slowly: the oats column is its nutrition label, .
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 equations | On the augmented matrix |
|---|---|
| Swap two equations | |
| Multiply an equation by | |
| Add another equation times to an equation |
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 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 to the protein one: the left-hand side gives and on the right you put . So no solution is lost.
And none is gained either, because every operation can be undone: if you add times another row to a row, subtracting 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:
First column: with the 2 at the top I clear the 4 and the 9. For the 9 I use so that no halves appear:
Check row 3 in the middle matrix: , , and . In row 2, both and 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: .
- Row 2: .
- Row 1: .
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, 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.
| Step | Operation | What you get | Why |
|---|---|---|---|
| 1 | I put fat at the top | Pivot 2 in the first row | It has a 0 and the smallest numbers: it is the row that makes clearing cheapest |
| 2 | The carbs row becomes | All its numbers are even: dividing by 2 makes the arithmetic cheaper and does not change the solutions | |
| 3 | I want a 0 below the pivot 2, and | ||
| 4 | Clearing the 9 with the 2 would mean subtracting ; multiplying the row by 2 first avoids the halves | ||
| 5 | The staircase is right | In row 2 both and vanished at once: it has to go last | |
| 6 | I read row 3 | Only one unknown is left in that row | |
| 7 | I substitute into row 2 | I already know , so only is left | |
| 8 | I substitute into row 1 | I already know ; the 0 in front of 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, . Step by step, with the same operations: the reordered augmented matrix is , and ; dividing the last one by 2 gives . With you get , and with , . You swap them and go from the bottom up: ; , so and ; , so . Check: , and .
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:
- : the number of steps (non-zero rows) of , that is, .
- : the number of steps of , that is, .
- : the number of unknowns (columns of ).
And the Rouché-Frobenius theorem says:
| Ranks | Classification | Solutions |
|---|---|---|
| Consistent, unique solution | One | |
| Consistent, infinitely many | Infinitely many, with degrees of freedom | |
| Inconsistent | None |
Since is part of , always . For to be larger means that row reducing produces a row with , that is, the impossible equation . In the shake, : a unique solution.
With oats and milk for 15 of protein and 7 of fat, the augmented matrix is and gives the row : “”. There is my lost afternoon: , inconsistent. The tree in the diagram sums up the decision.
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:
| Shake | Echelon form | Type | Why | |||
|---|---|---|---|---|---|---|
| Oats, milk and banana | Three non-zero rows | 3 | 3 | 3 | CD | No appears and every unknown has its step |
| With ricotta | Three non-zero rows, four columns | 3 | 3 | 4 | CI | There is a solution, but the ricotta column has no step: 1 degree of freedom |
| Only oats and milk | and | 1 | 2 | 2 | I | The second row only has a step in the right-hand column: it is |
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 , as in any homogeneous system. And is the same shake matrix, with , so its rank is 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 is the equation , which always holds: it is simply redundant. What is inconsistent is with . 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 grams of protein:
You do it as if were a number; you just leave the letter wherever it lands:
| Step | What I do | What comes out | Why |
|---|---|---|---|
| 1 | The protein row is exactly twice the fat row in both columns: and | ||
| 2 | I look at the term that is left | It is the only thing that depends on , and it decides whether that row is or | |
| 3 | If | An impossible equation: inconsistent | |
| 4 | If | The row is redundant and a single equation is left, , 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 , and then it has infinitely many solutions. Step by step: the augmented matrix is the one from before with a instead of the 7; gives the row . If , it is the impossible equation: inconsistent. If , the row is , 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 , 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 servings. With the same targets, the system has 3 equations and 4 unknowns, and its reduced row echelon form is:
: consistent with infinitely many solutions and degree of freedom. The pivot unknowns are and the free one is . Reading each row and moving to the right:
Each value of is a different shake with the same macros. With it is the one from before; with , two and a half servings of oats, no milk, one banana and half a serving of ricotta. The maths accepts any , but in the kitchen there are no negative amounts: forces , and , so in real life goes from 0 to . You can see it in the diagram.
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.
| Row | Equation it says | I solve for | Why |
|---|---|---|---|
| 1 | The in the fourth column multiplies ; moving it to the right changes its sign | ||
| 2 | Same: the moves across as a subtraction | ||
| 3 | In that row the 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: because the ricotta cannot be negative either; gives ; gives , which already holds; and always works. That is where the interval from 0 to comes from.
And here you can see why a system never has exactly two solutions. The shake with and the one with give the same macros. If you mix half of one with half of the other, so does the result: you get , with , and , 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:
The last column is the solution, , 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:
| Step | Operation | What comes out | Why |
|---|---|---|---|
| 1 | I remove the 24 above the pivot of ; since row 3 is , the right-hand side becomes | ||
| 2 | I divide by the pivot so that it is 1: you can already read | ||
| 3 | I remove the 3 above the pivot of : . Row 1 had no already | ||
| 4 | I divide by the pivot: |
Cramer’s rule
If the system is square () and , it has a unique solution and each unknown can be computed with determinants:
where is the matrix with column replaced by the constant terms. In the shake, (by Sarrus: ). For , I replace the oats column with :
Likewise, and , so and . The diagram shows which column is replaced for each unknown.
Cramer is handy for or systems and when you are only asked for one unknown. But it does not work if (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 and concluding that “there is no solution”. If , 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, , which only depends on the ingredients. The top is the determinant of with that ingredient’s column replaced by what you ask for. You already have and . These are the other two, by Sarrus:
| Unknown | Column I replace | Sarrus | Value |
|---|---|---|---|
| (milk) | The second, with | , so | |
| (banana) | The third, with | , so |
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 is and has no determinant. Cramer only works with square systems and , 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
: 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
: 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 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:
- Change
Bto[17; 62; 8]and check that you get another shake with whole numbers. - 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. - Remove the banana column (
A = A(:, 1:2)) and see what the ranks say with the originalB. - In the Workspace, look at the size of
R: , the reduced augmented matrix.
Summary
| Concept | What it is | How to recognise it |
|---|---|---|
| Linear system | , first-degree equations | Coefficient and augmented matrices |
| Unique solution (CD) | One solution | |
| Infinitely many (CI) | Infinitely many solutions | , with parameters |
| Inconsistent (I) | No solution | : with appears |
| Homogeneous | Constant terms 0 | Always consistent (trivial solution) |
| Gaussian elimination | Echelon form and back substitution | Zeros below the pivots |
| Gauss-Jordan | Reduced echelon form, read the solution | Zeros above and below |
| Cramer | Only if square and |
Three ideas to take away:
- Before solving, classify: compare , and . Rouché-Frobenius tells you how many solutions you are going to find.
- A row is redundant; a row with makes the system inconsistent.
- 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 →



