Module 3: Systems of Equations
np.linalg.solve, MATLAB's backslash operator, and finite element solvers in engineering simulation all use variants of it. Understanding it means you understand what your tools are actually doing.Knowing that a system has a solution is one thing. Finding it is another. Gaussian elimination is the systematic algorithm for doing that — and it works for any size system.
There are three operations you can perform on the rows of a system that preserve its solutions:
Using these, you reduce the system to a simpler form — one where the answer can be read off directly.
The goal is upper triangular form: zeros below the diagonal. For a 2×2 system that means:
Row 2 now says dy=f, so y=f/d. Then substitute back into row 1 to find x. This is called back-substitution.
The columns are x-coefficients, y-coefficients, and the right-hand side (separated by the bar). Every row operation applies identically to all four numbers in a row — including the right-hand side.
import numpy as np
A = np.array([[2, 1],
[4, -1]], dtype=float)
b = np.array([5, 7], dtype=float)
x = np.linalg.solve(A, b)
print(x) # [2. 1.] — x=2, y=1np.linalg.solve runs an optimised Gaussian elimination (LU decomposition) internally. Same algorithm, much faster for large systems.