Solving Systems Using Matrices
Writing the system as AX = B
A system is not a stack of unrelated equations, it is one matrix equation wearing three hats. The coefficient matrix collects every multiplier of the unknowns into its own column, so column belongs to the -th unknown and column order is a promise you make once and keep everywhere. The constant column carries the right-hand sides in the same order as the rows, and the variable column is the answer you are constructing. Turning and into a matrix equation with coefficient matrix and constant column discards nothing, but it buys three things: one object to invert, a determinant that decides the answer before any substitution, and a notation in which the three consistency outcomes read as three rank comparisons instead of three different kinds of algebra.
Two habits remove the usual transcription slips. Announce the column order in the answer box before writing the matrix, and keep the constants in their own column so that a stray sign cannot migrate into an unknown.
Three methods and when each one pays
| Method | The move it makes | Reaches for it when |
|---|---|---|
| Matrix inverse | several constant columns share one coefficient matrix | |
| Cramer's rule | the order is two or three with small integers | |
| Row reduction | augmented matrix reduces to the unknowns | the determinant is zero, or the order grows past three |
Both the inverse route and Cramer's rule divide by a determinant, so both stop dead when that determinant vanishes, and both are exact when it does not. The difference between them is reuse: an inverse answers every right-hand side built on the same coefficient matrix, while Cramer's rule recomputes determinants for a single answer and throws the work away. Row reduction never divides by a determinant at all, which makes it both the fallback and, once the systems grow, the method of first resort.
Example 1: solving with the matrix inverse
Example 2: solving with Cramer's rule
Four determinants were computed to obtain three numbers, and only the first of them is ever reused. That ratio is why Cramer's rule is a good examination method for a single three-equation system and a poor one for anything larger: the cost grows with the number of unknowns while the payoff stays at one answer.
What a zero determinant actually means
A vanishing determinant is a statement about information rather than about difficulty. When the determinant of the coefficient matrix is non-zero its rows are independent, every equation removes one dimension of the possibilities, and exactly one point survives. When it is zero, at least one equation is a consequence of the others, so the system either contradicts itself or leaves a free direction along which every point is equally valid. The three outcomes are therefore decided by two quantities: the rank of the coefficient matrix, which counts the independent equations, and the rank of the augmented matrix, which counts what the constants are still able to say.
| Determinant of A | Rank of the augmented matrix against the rank of A | Outcome |
|---|---|---|
| Non-zero | both equal to the number of unknowns | exactly one solution |
| Zero | both equal, but smaller than the number of unknowns | infinitely many solutions |
| Zero | augmented rank is larger | no solution at all |
The trap is treating a zero determinant as the end of the problem. Two of the three methods divide by it and stop, but row reduction divides by nothing and carries on, which is why it is the fallback whenever the determinant fails.
Example 3: an inconsistent system
Example 4: non-zero determinant, unique solution
Example 5: a system with infinitely many solutions
The two checks are worth more than they look. Substituting two different parameter values and confirming both points solve the original equations is the quickest way to show that the answer is a family rather than a slip, and it also settles the direction of the free parameter.
Solving and checking in Python
The library solve and the hand method must agree to the last digit, and the residual column is what proves it: substituting a candidate solution back into the matrix equation should return the zero vector.
import numpy as np
A = np.array([[2., 3.], [1., 2.]])
b = np.array([8., 5.])
det = np.linalg.det(A)
adj = np.array([[2., -3.], [-1., 2.]])
inv = adj / det
x = inv @ b
print("det(A) :", round(float(det), 6)) # 1.0
print("solution x :", np.round(x, 6)) # [1. 2.]
print("residual Ax-b:", np.round(A @ x - b, 12)) # [0. 0.]
print("A A^-1 == I :", np.allclose(A @ inv, np.eye(2))) # True
three = np.array([[1., 1., 1.], [2., -1., 1.], [1., 2., -1.]])
c = np.array([6., 3., 2.])
print("3x3 solution :", np.round(np.linalg.solve(three, c), 6)) # [1. 2. 3.]
print("3x3 residual :", np.round(three @ np.linalg.solve(three, c) - c, 12))
# [0. 0. 0.]
The first block reproduces both earlier examples exactly, and the residual lines are the part worth copying into your own work: a residual of the zero vector is a stronger statement than agreement to a few decimal places, because it confirms the whole matrix equation at once.
Distinguishing the three cases in code
Rank, not the determinant alone, separates the three outcomes, and the function below applies the table from earlier without any branching on the entries. The determinant is still reported, because a non-zero determinant already settles the question before the ranks are computed.
import numpy as np
def classify(a, b):
"""Return (verdict, determinant) for the system a x = b."""
a = np.asarray(a, float)
b = np.asarray(b, float).reshape(-1, 1)
n = a.shape[1]
rank_a = np.linalg.matrix_rank(a)
rank_ab = np.linalg.matrix_rank(np.hstack([a, b]))
det = round(float(np.linalg.det(a)), 9)
if rank_a == rank_ab == n:
return "unique solution", det
if rank_a == rank_ab:
return "infinitely many solutions", det
return "no solution", det
print(classify([[1, 2], [3, 4]], [5, 11])) # ('unique solution', -2.0)
print(classify([[1, 1], [2, 2]], [2, 5])) # ('no solution', 0.0)
print(classify([[1, 1, 1], [2, 2, 2], [1, 2, 3]], [3, 6, 6])) # ('infinitely many solutions', 0.0)
Each verdict matches the worked example it belongs to, and the third line is the machine reading of the rank argument: the coefficient matrix and the augmented matrix both have rank two while three unknowns are present, so the solution set is a line rather than a point.
Common Mistakes
Copying the constants into the coefficient matrix, or mixing up the column order of the unknowns
Fix: Write the column order in the answer box first, then read each equation across one row at a time, and check the result by multiplying the matrix out again.
Applying Cramer's rule after finding that the determinant of the coefficient matrix is zero
Fix: Test the determinant before building any A-i matrix, and switch to row reduction when it vanishes, since the rule divides by that number.
Reporting no solution merely because the determinant is zero
Fix: Zero determinant means the outcome is undecided, not that it is empty; reduce the augmented matrix and compare its rank with the rank of the coefficient matrix.
Giving a single numerical answer for a system whose reduced form contains a row of zeros
Fix: Name a free parameter, express every unknown in terms of it, and confirm with two different parameter values that the whole family solves the original equations.
Key Takeaways
- Writing a system as AX equals B turns every question into a statement about two matrices, and the column order of the unknowns is a promise that must be kept everywhere.
- The inverse method and Cramer's rule both divide by a determinant, so both require it to be non-zero, while row reduction divides by nothing and handles every case.
- A zero determinant leaves three outcomes open, and the ranks of the coefficient matrix and the augmented matrix decide between a unique solution, no solution and a family of solutions.
- A zero numerator in Cramer's rule is ordinary and simply means that unknown is zero, whereas a zero denominator means the rule itself is unavailable.