Systems of linear equations — guided practice with five shake problems, Rouché without solving and an exam-style parameter (and the equation I forgot to copy)
In the classroom worksheet on systems I solved a four-equation system by Gaussian elimination, got infinitely many solutions and called it done. When it was marked, the lecturer showed me that when writing the augmented matrix I had left one equation out: with three equations instead of four, of course I had a parameter to spare. Since then I count the rows of the augmented matrix before starting: as many as there are equations, not one fewer.
In this practice we do by hand what you saw in the theory of systems of linear equations, always with the shake: a snack by Gaussian elimination and by Cramer, the shake with ricotta by Gauss-Jordan (infinitely many solutions, and which ones work in the kitchen), three systems classified with Rouché without solving them, the homogeneous system that tells you which ingredients can be swapped and, at the end, a system with a parameter in the format of an exam question. Each problem is checked in MATLAB, as in the second MATLAB assignment.
Table of Contents
Before you start
Make sure you are comfortable with:
- How to write the augmented matrix of a system.
- The three elementary operations, and the fact that they do not change the solutions.
- The Rouché-Frobenius theorem: , and unknowns.
- How to compute the rank with the echelon form or with minors (topic 1).
If any of these feels shaky, go over the theory before carrying on.
The shake data are always the same. Per serving: oats (30 g) 4 g of protein, 18 of carbs and 2 of fat; milk (200 ml) 6, 10 and 3; banana 1, 24 and 0; ricotta (80 g) 8, 2 and 4. Each ingredient is a column of the matrix and each nutrient, a row.
How to solve a system on paper
- Data: write the augmented matrix and count its rows (as many as equations) and columns (unknowns plus one).
- Classify: row reduce and look at , and before solving for anything. If it is inconsistent, you are done.
- Solve: Gaussian elimination (and back substitution) or Gauss-Jordan (and read). If there are infinitely many solutions, take the unknowns without a pivot as parameters.
- Check: substitute the solution into all the original equations, not the transformed ones.
Problem 1: the snack, by Gaussian elimination and by Cramer
Statement. For my afternoon snack I want 12 g of protein, 76 g of carbs and 5 g of fat with oats (), milk () and banana ():
a) Classify the system and solve it by Gaussian elimination. b) Check the value of with Cramer’s rule.
The idea
It is the same coefficient matrix as the shake in the theory, with other targets. Since has not changed, still holds and we already know it will have a unique solution; even so, we classify it by row reducing, which is what is asked. I start with the fat equation because it has a 0 and small numbers.
Halve the carbs equation before starting: . Less arithmetic, same solutions.
Step by step
a) I reorder the equations (fat, protein, halved carbs) and clear the first column:
Those two arrows, row by row. The rule: from the row you want to clear, subtract the multiple of the pivot row that turns its first number into 0.
| Step | Operation | Resulting row | Why |
|---|---|---|---|
| 1 | Reorder: fat, protein, halved carbs | on top | The 2 of the fat is the handiest pivot, and the row has no banana |
| 2 | The 4 is twice the pivot. As a bonus, the 6 also becomes 0 | ||
| 3 | 9 is not a multiple of 2: multiplying by 2 before subtracting avoids fractions | ||
| 4 | moves to the second row | Row 2 has lost its milk: moving the other one up leaves the staircase properly drawn | |
| 5 | Count steps | 3 in and 3 in the augmented matrix | : unique solution |
Step 2 is the one that surprises people: clearing the oats also clears the milk. It is no coincidence: in the protein, oats and milk give twice what they give in the fat (4 and 6 against 2 and 3), so the row that is left only talks about the banana.
The tricky calculation is row 3: . Three steps in and three in the augmented matrix: , unique solution. Substituting from the bottom up:
- .
- .
- .
One serving of oats, one glass of milk and two bananas.
b) For , I replace the third column of (the banana) with the targets:
It matches. With Cramer you do not need or to get : that is why it is handy when you are only asked for one unknown.
Cramer’s numerator, product by product. By Sarrus, the main diagonal and its two parallels are added, and the other diagonal and its parallels are subtracted:
| Term | Calculation | Sign | Why |
|---|---|---|---|
| Main diagonal | Goes down from left to right | ||
| First parallel | Ends with the 2 in the bottom corner | ||
| Second parallel | Starts in the top right corner | ||
| Other diagonal | Goes down from right to left | ||
| Its first parallel | Starts with the 4 in the corner | ||
| Its second parallel | Ends with the 5 in the corner |
The added terms give 1760 and the subtracted ones 1692: that leaves 68. The denominator, with the same calculation: .
The two 912s cancel out (and in , the two 288s). Before adding, cross out equal pairs with opposite signs: fewer calculations, fewer mistakes.
Check it in MATLAB
A = [4 6 1; 18 10 24; 2 3 0]; B = [12; 76; 5]; p = rank(A), q = rank([A B]) % 3 and 3, with n = 3: unique rref([A B]) % the solution in the last column A3 = A; A3(:, 3) = B; % Cramer: column 3 replaced by B det(A3) / det(A) % the value of z
Output:
p =
3
q =
3
ans =
1.0000 0 0 1.0000
0 1.0000 0 1.0000
0 0 1.0000 2.0000
ans =
2
A3(:, 3) = B replaces the whole of column 3 with : exactly Cramer’s matrix. The ratio of determinants gives 2 (MATLAB computes it with decimals, which is why it may show 2.0000).
Questions you might ask
Why reorder the equations? Because the order does not change the solutions and a good first row saves arithmetic. The fat equation has a 0 and the pivot 2 divides the other numbers in the column.
Isn’t multiplying by 2 “cheating”? In a system, no: multiplying an equation by a non-zero number gives one with the same solutions. What you cannot do without compensating is multiply rows when computing a determinant.
What if I had not swapped and ? The row already gives directly, so you could solve it all the same. The swap just keeps the staircase tidy.
Cramer or Gaussian elimination? For the whole system, Gaussian elimination; for a single unknown of a , Cramer can be quicker. With numbers this large, the determinants take some effort.
Checking the solution in the echelon system instead of the original one. If you made a mistake while row reducing, the solution will satisfy the wrong system. Substitute into the three original equations: , , .
Try it yourself
- Solve the shake with targets 17, 62 and 8 (protein, carbs and fat). You should get another combination of whole numbers.
- Compute by Cramer in the snack and check that it is 1.
Problem 2: the shake with ricotta, by Gauss-Jordan
Statement. I add ricotta ( servings) to the shake in the theory, with the same targets: 15 g of protein, 70 of carbs and 7 of fat.
a) Classify the system and solve it by Gauss-Jordan. b) Which values of the parameter give a shake you can actually make (all amounts )?
The idea
Three equations and four unknowns: it cannot have a unique solution (). Either it is inconsistent or it has infinitely many solutions. We row reduce, count and, if it is consistent, reach the reduced form to write the pivot unknowns in terms of the free one.
Do exactly the same operations as in problem 1. The new column, the ricotta, just comes along for the ride.
Step by step
a) Same order and same operations as before:
In the ricotta column: and . Three steps in both matrices: , infinitely many solutions with degree of freedom. Now, Gauss-Jordan, from the bottom up:
Those four arrows, one at a time. The Gauss-Jordan rule: you work from the bottom up, and each pivot first clears what is above it and then becomes a 1.
| Step | Operation | What changes | Why |
|---|---|---|---|
| 1 | The 24 becomes 0 and the 7 on the right, | The banana’s 1 clears its column upwards; row 1 already has a 0 there | |
| 2 | becomes | Every number in the row is a multiple of : dividing gives no fractions | |
| 3 | , and | The milk’s pivot clears the 3 above it; the column is carried along | |
| 4 | The last pivot becomes a 1 and every row can now be read |
Why from the bottom up? Because the bottom row has only one number in and does not dirty the other columns. If you start by using row 2 on row 1, the banana’s 24 would move into row 1 and you would have to clear it again.
The column has no pivot: is the free unknown. Each row is read by moving the term to the right:
b) In the kitchen, (true if ), (if ), always, and . Putting it together: . With , for example: two and a quarter servings of oats, half a glass of milk, one banana and a quarter of a serving of ricotta.
Check it in MATLAB
format rat A4 = [4 6 1 8; 18 10 24 2; 2 3 0 4]; B = [15; 70; 7]; p = rank(A4), q = rank([A4 B]), n = size(A4, 2) R = rref([A4 B]) % the same reduced form as by hand t = 1/4; x = [2 + t; 1 - 2*t; 1; t]; % one particular solution A4*x % must give 15, 70, 7
Output:
p =
3
q =
3
n =
4
R =
1 0 0 -1 2
0 1 0 2 1
0 0 1 0 1
ans =
15
70
7
A4*x with returns the exact targets: any works for the equations, and the condition is imposed only by the kitchen.
Check you’ve got it: what would happen if you asked for 8 g of fat instead of 7?
The system would still have infinitely many solutions, but you could not make any of them. Step by step: does not change, so its three steps are still there; and since the augmented matrix only has three rows, there is no room for a fourth step: , infinitely many solutions again. With this matrix, whatever targets you choose, it is never inconsistent.
But look at the banana row. With the same operations, now gives , that is, in every solution. That is what the question about why explained: “protein minus twice the fat” can only come from the banana, and here it is . You cannot add minus one banana: the maths says “infinitely many” and the kitchen says “none”.
Questions you might ask
Why and not another unknown as the parameter? Because it is the one whose column has no pivot. You could solve for another (for example, with free), but in the exam you use the echelon form: the unknowns without a pivot are the parameters.
Why is in every solution? Because oats, milk and ricotta all have protein equal to twice the fat; only the banana breaks that ratio. The difference “protein minus twice the fat” comes from the banana, and here it is .
Do infinitely many solutions mean any shake works? No: it means infinitely many shakes with those exact macros, all on the same “line” of solutions. Any other combination does not give 15, 70 and 7.
What if I add a fourth equation, fibre? With four independent equations and four unknowns, the system would have a unique solution: the fibre would pick a single value of .
Writing the solution as , , , and calling it “the” solution. It is one of them (); for a system with infinitely many solutions you must give the general solution, with the parameter.
Try it yourself
- Take as the free unknown (call it ) and write , and in terms of . Check that it describes the same solutions.
- Which value of gives a shake with exactly 1 glass of milk? And one without ricotta?
Problem 3: three systems classified without solving them
Statement. With only oats () and milk (), classify these systems using ranks (with minors), without solving them:
a) Protein 14, carbs 46, fat 7. b) Protein 15, carbs 70, fat 7. c) The homogeneous version with protein and fat: , .
The idea
In a) and b) there are 3 equations and 2 unknowns, so is and the augmented matrix is . The rank of is at most 2; if the determinant of the augmented matrix is non-zero, its rank is 3 and the system is inconsistent. If it is 0, rank 2 and a unique solution.
The minor (protein and carbs) works for the first two systems: compute it once.
Step by step
The rank of is the same in a) and b), because does not change:
a) The augmented matrix is square; by Sarrus:
: unique solution, even though there are more equations than unknowns. The carbs equation is a combination of the other two and adds nothing new. (The solution is , .)
b) With the shake targets:
: inconsistent. It is my impossible shake from the theory.
c) Homogeneous with two equations: , so : infinitely many solutions, with . Mathematically there are infinitely many mixes “with no protein or fat”, but all except the trivial one have a negative amount: in the kitchen, the only one is putting nothing in.
Check it in MATLAB
A = [4 6; 18 10; 2 3]; rank(A) rank([A [14; 46; 7]]) % a) 2: unique solution rank([A [15; 70; 7]]) % b) 3: inconsistent rank([4 6; 2 3]) % c) 1 < 2: infinitely many null([4 6; 2 3], 'r') % c) the direction of the solutions
Output:
ans =
2
ans =
2
ans =
3
ans =
1
ans =
-3/2
1
null(M, 'r') gives the solutions of the homogeneous system with “rational” numbers (the 'r'): here, the column , which is with .
Questions you might ask
Why don’t I need to check more minors in a)? Because the only order-3 minor of the augmented matrix is the matrix itself. If it is 0, its rank cannot be 3, and it contains the order-2 minor that was already non-zero.
Can an equation that is a “combination of others” be crossed out? Yes, once you have checked it: it does not change the solutions. But you must check it with ranks or by row reducing, not by eye.
Can a homogeneous system come out inconsistent? Never: is always a solution. That is why in c) we only had to decide between a unique solution and infinitely many.
Saying in a) “three equations and two unknowns, so inconsistent”. That is exactly the trick question from the quiz: what matters is the rank.
Try it yourself
- Find a fat target that makes the system with protein 15 and carbs 70 consistent (hint: the determinant of the augmented matrix must be 0).
- Classify the system with oats, milk and banana for the target .
Problem 4: the homogeneous system of swaps
Statement. With the four ingredients, solve the homogeneous system by Gauss-Jordan and interpret its solutions. Then write the solution of problem 2 as “one particular solution plus those of the homogeneous system”.
The idea
The solutions of the homogeneous system are changes in amounts that change none of the macros. If you add one of them to a shake that already meets the targets, it still meets them. That is why the general solution of a consistent system is always “one particular solution + all those of the homogeneous system”.
They are the same operations as in problem 2 without the last column (or with zeros in it, which never change).
Step by step
With the column of zeros, the reduced form is that of problem 2 with zeros on the right:
With : one more serving of oats and one of ricotta, in exchange for two fewer glasses of milk. Check that nothing changes: protein , carbs , fat . The diagram shows it as a balance.
And the solution of problem 2 can be written like this:
The first vector is the shake from the theory (the one with ) and the second, the swap: each solution is that shake plus swaps. Check the second component: , the of problem 2.
Check it in MATLAB
A4 = [4 6 1 8; 18 10 24 2; 2 3 0 4]; N = null(A4, 'r') % the direction of the swaps A4*N % zeros: no macro changes A4*([2; 1; 1; 0] + 3*N) % the theory shake plus 3 swaps
Output:
N =
1
-2
0
1
ans =
0
0
0
ans =
15
70
7
null(A4, 'r') returns the column : the same as by hand. And adding three swaps to the theory shake gives another solution of the system with targets , although with negative milk: mathematically fine, in the kitchen not.
Questions you might ask
Why is the general solution “particular plus homogeneous”? If and , then . And conversely: the difference of two solutions of solves the homogeneous system.
How many parameters does the homogeneous system have? The same as the full system when it is consistent: , here one.
What if the homogeneous system only had the trivial solution? Then the full system, if consistent, would have a unique solution: no swap would be possible.
Forgetting that is also part of the homogeneous solution. An unknown that is 0 does not “disappear”: you have to write it.
Try it yourself
- Check by hand that satisfies the three equations of problem 2.
- Invent a fifth ingredient and say how many parameters the homogeneous system would have with five unknowns and three independent equations.
Problem 5: how the exam asks it
Exam-style question. Discuss the following system for the values of and solve it whenever it is consistent: , , . [4 points] a) (1.5 points) Classification depending on . b) (1.5 points) Solution when it has a unique solution. c) (1 point) Solution when it has infinitely many.
The idea
First the determinant of : where it does not vanish, Rouché gives a unique solution straight away. The values that make it zero are studied one by one, substituting and row reducing. And the matrix will look familiar: it is the key with a parameter from the topic 1 exercises, with the parameter in other positions.
By Sarrus, . The equations are “symmetric”: if you swap , and , the system does not change. That tells you what the solution looks like in the unique case.
Step by step
a) , which vanishes at and .
Where that determinant comes from, without skipping anything. By Sarrus, with written row by row as , and :
| Term | Calculation | Sign | Why |
|---|---|---|---|
| Main diagonal | It only picks up the in the center | ||
| First parallel | Ends with the at the bottom | ||
| Second parallel | Starts with the at the top | ||
| Other diagonal | All three are here | ||
| Its first parallel | It does not touch any | ||
| Its second parallel | Neither does this one |
Total: . To factorise it, look for a root among the divisors of 2: with , , so is a factor, and synthetic division (Ruffini’s rule) gives . The second bracket is , because its roots, 1 and , add up to and multiply to . Putting it all together, .
Always try first: with it the three rows are equal, so the determinant has to be 0.
- If and : , so : unique solution.
- If : all three equations are . : infinitely many solutions with 2 degrees of freedom.
- If : adding the three rows of the augmented matrix, :
The last row is : , inconsistent. ( because .)
b) By symmetry, if is the only solution, so is the one with its values swapped; since it is unique, . Substituting into the first equation: :
Cramer gives the same: and .
c) With , we are left with . The free unknowns are and :
The diagram places the three cases on the line of values of .
Check it in MATLAB
syms a A = [1 1 a; 1 a 1; a 1 1]; B = [1; 1; 1]; d = det(A) % the determinant with a rank(subs(A, a, -2)), rank(subs([A B], a, -2)) % 2 and 3: inconsistent rank(subs(A, a, 1)), rank(subs([A B], a, 1)) % 1 and 1: infinitely many inv(subs(A, a, 3))*B % with a = 3, x = y = z = 1/5
Output:
d =
3*a - a^3 - 2
ans =
2
ans =
3
ans =
1
ans =
1
ans =
1/5
1/5
1/5
d comes out expanded (); substituting and gives 0. The ranks confirm the classification and, with , the solution is in all three unknowns: .
Check and how it is marked
Check b) in the second equation: . And c) with : satisfies .
Indicative split of the 4 points (my own, not the official one):
| Part | What earns the marks | Points |
|---|---|---|
| a) | correctly computed and factorised | 0.5 |
| a) | General case, unique, with Rouché | 0.25 |
| a) | : infinitely many, with its ranks | 0.25 |
| a) | : inconsistent, with the row or the ranks | 0.5 |
| b) | Solution in terms of , justified | 1.5 |
| c) | Solution with two parameters | 1 |
Questions you might ask
Can I do the discussion by row reducing with inside? Yes, but when you divide by something like you have to treat separately the case where it is 0. With the determinant, the special cases appear on their own.
Why did I add all three rows at ? Because in each column of there is a 1, another 1 and a : they add up to 0. It is the shortest route to the zero row; row reducing step by step gives the same.
How many parameters are there at ? : two free unknowns.
Giving also for or . For it does not even exist (you would divide by 0), and for it would give , which is only one of infinitely many solutions.
Try it yourself
- Discuss the same system with the constant terms changed to .
- For , solve the system by Gaussian elimination and check that you get in all three unknowns.
Common mistakes in this practice
- Copying the augmented matrix wrongly, leaving out an equation or a sign. Count rows and columns before you start.
- Mistaking a row for an inconsistency. Only with is one.
- Giving one particular solution for a system with infinitely many instead of the general one with parameters.
- Classifying by the number of equations instead of by the ranks.
- Applying Cramer with or to a non-square system.
- Forgetting the special cases when discussing a parameter.
Try it in the MATLAB playground
The MATLAB playground on the site runs this check of the five problems:
format rat %% Problem 1: the snack A = [4 6 1; 18 10 24; 2 3 0]; rref([A [12; 76; 5]]) %% Problems 2 and 4: ricotta A4 = [A [8; 2; 4]]; rref([A4 [15; 70; 7]]) null(A4, 'r') %% Problem 3: oats and milk rank([4 6; 18 10; 2 3]), rank([4 6 15; 18 10 70; 2 3 7])
Things to look at:
A4 = [A [8; 2; 4]]attaches the ricotta column on the right: that is how you build a block matrix.- Compare the last column of each
rrefwith your paper solutions. - In problem 3, change the fat 7 to other values and see when the rank goes from 3 to 2.
- Remove
format ratand see how the fractions in problem 2 change.
Summary
- Before solving, classify with , and : it saves work and stops you solving the impossible.
- Gaussian elimination leaves the staircase and you substitute from the bottom up; Gauss-Jordan reaches the reduced form and you read the solution.
- With infinitely many solutions, the unknowns without a pivot are the parameters and the solution is given in general.
- The general solution of a consistent system is a particular one plus those of the homogeneous system.
- More equations than unknowns does not mean inconsistent; the ranks decide.
- With a parameter: determinant, values that make it zero, the general case and each special case separately.
Checklist: have you practised it?
- Have you solved the snack by Gaussian elimination and checked one unknown with Cramer?
- Can you write the general solution of the shake with ricotta and say which values of the parameter work in the kitchen?
- Can you classify a system with more equations than unknowns using only determinants?
- Do you understand why the solutions of the homogeneous system are “swaps” that change nothing?
- Have you run the MATLAB blocks and checked the outputs?
- Have you tried the “Try it yourself” items without looking at the theory?
If you answered yes to almost everything, you are ready for the systems of linear equations exercises, where I no longer give you the step by step and there is a 20-question quiz like the Campus ones. See you there!
Next step: exercisesSystems of linear equations — exam-style exercises with the shake, a parameter that changes everything, the equations of a subspace and a 20-question quiz (and the row of zeros that scared me)Did this article help you? Here is how you can support SergioLearns →



