LU decomposition (also known as LU factorization) is a method of decomposing a matrix A into the product of two other matrices:
L: A Lower triangular matrix.
U: An Upper triangular matrix.
So, the fundamental idea is: A = L * U
What are Triangular Matrices?
Lower Triangular Matrix (L): A square matrix where all the entries above the main diagonal are zero.
code
[ a 0 0 ]
[ b c 0 ]
[ d e f ]
(Often, in LU decomposition, the diagonal entries of L are set to 1. This is a standard convention called Doolittle factorization, which makes L and U unique if they exist.)
Upper Triangular Matrix (U): A square matrix where all the entries below the main diagonal are zero.
code
[ a b c ]
[ 0 d e ]
[ 0 0 f ]
Why is LU Decomposition Useful?
The primary motivation for LU decomposition is to make certain matrix computations, especially solving systems of linear equations, much more efficient, particularly when you need to solve the same system with different right-hand side vectors (b).
Solving Systems of Linear Equations (Ax = b):
If you have the system Ax = b, you can substitute A = LU:
(LU)x = b
Now, you can introduce an intermediate vector, let's call it y, such that y = Ux.
The original equation becomes Ly = b.
This gives you a two-step process to solve for x:
a. Solve Ly = b for y. This is easy because L is lower triangular. You can use forward substitution.
b. Solve Ux = y for x. This is also easy because U is upper triangular. You can use backward substitution.
Solving two triangular systems (using substitution) is computationally much faster than solving a general system using Gaussian elimination directly, especially if you need to do it repeatedly for different 'b' vectors. You perform the LU decomposition once, and then solving for each new 'b' only requires the two fast substitution steps.
Calculating the Determinant:
The determinant of a matrix product is the product of the determinants: det(A) = det(L * U) = det(L) * det(U).
The determinant of a triangular matrix is simply the product of its diagonal entries.
If L has 1s on the diagonal (standard case), det(L) = 1.
Therefore, det(A) = 1 * det(U) = product of the diagonal entries of U. This is a very efficient way to find the determinant.
Calculating the Inverse:
While less common than solving systems, the inverse A⁻¹ can be found using L and U: A⁻¹ = (LU)⁻¹ = U⁻¹L⁻¹. Inverting triangular matrices is simpler than inverting a general matrix.
How is it Computed?
LU decomposition is essentially a form of Gaussian elimination.
The Process: You perform row operations (specifically, subtracting a multiple of one row from another row below it) to eliminate the entries below the main diagonal of matrix A. This process transforms A into an upper triangular matrix, which is your U.
Constructing L: The multipliers you used during the elimination process are used to construct the lower triangular matrix L.
L has 1s on its main diagonal.
The entry L[i, j] (where i > j, i.e., below the diagonal) is the negative of the multiplier used to eliminate the entry in the j-th column of the i-th row during the Gaussian elimination.
Example: If you subtracted 3 times row 1 from row 3 to make A[3,1] zero, then L[3,1] would be 3.
Example (Simple 2x2):
Let A = [[2, 4], [6, 10]]
Transform A into U: We want to make the entry below the diagonal (6) zero.
Sometimes, during Gaussian elimination, you might encounter a zero on the diagonal where you need a non-zero value to use as a pivot for elimination. Or, the diagonal value might be very small, leading to numerical instability. In these cases, you need to swap rows.
When row swaps are necessary, the decomposition is slightly modified: PA = LU
P: Is a permutation matrix. It's an identity matrix with its rows swapped in the same way as the rows of A were swapped during the elimination process.
PA=LU decomposition always exists for a non-singular matrix A, whereas a simple A=LU decomposition without pivoting only exists if all leading principal minors of A are non-zero. In practice, numerical stability almost always requires pivoting (using PA=LU).
In Summary:
LU decomposition is a powerful matrix factorization technique that breaks a matrix A into a lower triangular matrix L and an upper triangular matrix U (often with a permutation matrix P involved, so PA=LU). Its main benefit is transforming the problem of solving Ax=b into two easier-to-solve triangular systems (Ly=b and Ux=y), making it highly efficient for repeated system solving, determinant calculation, and finding inverses.