Member-only story
Math Explained to Programmers — QR Decomposition (Gram-Schmidt)
Clean Code by Orthogonalizing Your Monolith
Imagine you have a matrix A with each column as a vector:
A = [x₁ x₂ x₃ ... xₙ]
Our goal is to decompose A into:
A = QR
Where:
- Q is a matrix with orthonormal columns (clean, independent directions)
- R is an upper-triangular matrix showing how to reconstruct A from Q
This is exactly what the Gram-Schmidt process achieves — step-by-step orthogonalization, just like refactoring a tangled monolith into clean, decoupled modules.
Why Orthogonalize?
The Gram-Schmidt process removes redundancy and overlap among vectors, making each new vector orthogonal to those we’ve already processed.
To developers:
It’s similar to refactoring your (yes, also mine) spaghetti code into clearly defined, independent modules.
Gram-Schmidt, Step-by-Step
Step 1: Start With the First Vector (Your First “Clean Module”)
Define the first orthogonal vector simply as:
u₁ = x₁
q₁ = u₁ / ‖u₁‖