1. Why Factorize Matrices?
Solving a linear system $Ax = b$ using naive matrix inversion $x = A^{-1}b$ is both computationally slow ($O(n^3)$ with large constant factor) and numerically unstable due to floating-point roundoff error.
In production engineering (robotics state estimation, physics simulations, financial modeling, machine learning), systems are solved via Matrix Decompositions—factoring $A$ into structured triangular or orthogonal matrices that can be solved in $O(n^2)$ time via forward and back-substitution.
2. LU Decomposition with Partial Pivoting
Any square invertible matrix $A \in \mathbb{R}^{n \times n}$ can be factored into a permutation matrix $P$, a unit lower-triangular matrix $L$, and an upper-triangular matrix $U$:
$$P A = L U$$
$$\begin{bmatrix}
\cdot & \cdot & \cdot \
\cdot & \cdot & \cdot \
\cdot & \cdot & \cdot
\end{bmatrix} = \begin{bmatrix}
1 & 0 & 0 \
l_{21} & 1 & 0 \
l_{31} & l_{32} & 1
\end{bmatrix} \begin{bmatrix}
u_{11} & u_{12} & u_{13} \
0 & u_{22} & u_{23} \
0 & 0 & u_{33}
\end{bmatrix}$$
Solving $Ax = b$ in Two Triangular Passes
- Permute: Compute $b' = Pb$.
- Forward Substitution: Solve $Ly = b'$ for $y$ in $O(n^2)$ operations.
- Back Substitution: Solve $Ux = y$ for $x$ in $O(n^2)$ operations.
If you have to solve $Ax = b$ for 10,000 different vectors $b$, you compute the $LU$ decomposition once ($O(n^3)$), and then each solve takes only $O(n^2)$.
3. Cholesky Decomposition: $A = L L^T$
If matrix $A \in \mathbb{R}^{n \times n}$ is Symmetric and Positive-Definite (SPD)—meaning $A = A^T$ and $x^T A x > 0$ for all $x \neq \mathbf{0}$—we can compute the Cholesky factorization:
$$A = L L^T$$
where $L$ is a lower-triangular matrix with strictly positive diagonal entries.
Advantages in Machine Learning & Robotics
- 2x Faster: Requires half the arithmetic operations of general LU ($\frac{1}{3}n^3$ vs $\frac{2}{3}n^3$).
- Unconditionally Stable: Requires zero pivoting.
- Core Applications: Kalman filters in autonomous vehicles, Gaussian Process regression, and sampling from multivariate normal distributions ($\mathcal{N}(\mu, \Sigma) \sim \mu + L \cdot z$ where $z \sim \mathcal{N}(0, I)$).
4. QR Factorization: $A = Q R$
Every real matrix $A \in \mathbb{R}^{m \times n}$ ($m \ge n$) can be factored into an orthogonal matrix $Q \in \mathbb{R}^{m \times m}$ ($Q^T Q = I$) and an upper-triangular matrix $R \in \mathbb{R}^{m \times n}$:
$$A = Q R$$
Solving Overdetermined Least-Squares
Given an overdetermined system $Ax \approx b$ (e.g., fitting a linear model to 1,000,000 data points):
$$Q R x = b \implies R x = Q^T b$$
Because $Q$ is orthogonal, multiplication by $Q^T$ preserves vector lengths and never amplifies numerical noise ($|Q^T v|_2 = |v|_2$). This avoids the catastrophic squaring of condition numbers $\kappa(A^T A) = \kappa(A)^2$ seen in the naive Normal Equation $(A^T A)x = A^T b$.
5. Python Implementation: Benchmarking Decompositions
python