Solving Systems of Linear Equations
Linear Algebra
Now that we have matrices, we can formalize how to *solve* Amathbf{x} = mathbf{b}. The canonical algorithm is Gaussian elimination. The idea: apply a sequence of elementary row operations to reduce A (augmented with mathbf{b}) to an upper-triangular form called row-echelon form, then back-substitute
Gaussian elimination + back-substitution solves any linear system or proves inconsistency.
Strip away the linear-system solver and you lose direct least squares, optimization step computation, and almost every classical ML algorithm.
Now that we have matrices, we can formalize how to *solve* . The canonical algorithm is Gaussian elimination. The idea: apply a sequence of elementary row operations to reduce (augmented with ) to an upper-triangular form called row-echelon form, then back-substitute. The three legal operations are swapping two rows, scaling a row by a non-zero constant, and adding a multiple of one row to another.
A stronger target is reduced row-echelon form (RREF): every pivot is 1, and each pivot column has zeros everywhere else. From RREF the solution (or the parametric family of solutions) can be read off directly. Because row operations correspond to multiplying by invertible elementary matrices, they do not change the solution set โ just the ease of reading it.
Variables corresponding to pivot columns are basic variables; the others are free variables. When every column has a pivot, the solution is unique. When some columns lack pivots, each free variable contributes an extra dimension to the solution set. When the augmented column has a pivot but the coefficient column does not (a row like ), the system is inconsistent and has no solution.
The general solution of a consistent system is , where is any *particular* solution to and is any solution to the *homogeneous* system . The homogeneous solutions form a vector space โ the null space of โ whose dimension equals the number of free variables. This structural view is central to later topics like rank and linear mappings.
Worked example โ Gaussian elimination on a 3ร3 system: Solve , , . Write the augmented matrix . R2 โ R2 โ 2R1 gives row . R3 โ R3 โ R1 gives . R3 โ R3 + R2/3 gives , so . Back-substitute: , then . Solution โ.
Worked example โ inconsistent system detected: Consider . R2 โ R2 โ 2R1 gives โ a row that reads , which is impossible. The system has no solution. Seeing a row of zeros on the left with a non-zero right-hand side is the algebraic fingerprint of inconsistency.
In practice, modern ML code uses numerically stable variants of Gaussian elimination: LU decomposition (factor into lower and upper triangular matrices) and QR decomposition (factor into orthogonal and upper-triangular). The LU approach powers most dense direct solvers; QR is more robust for least-squares problems. Under the hood, numpy.linalg.solve and torch.linalg.solve are doing exactly this.
Exercises
Put your understanding to the test. Score + streak + speed all count.
Confirm you've got it
3 quick questions. Get 2 right to mark this lesson complete.