Report

Help us improve this tool

Matrix LU Decomposition Calculator

Factor any square matrix into lower (L) and upper (U) triangular matrices with partial pivoting. Get detailed step-by-step Gaussian elimination, permutation matrix, and verification.

O M T

What is LU Decomposition?

LU decomposition (also called LU factorization) is a method that factors a square matrix $A$ into the product of a lower triangular matrix $L$ and an upper triangular matrix $U$, such that $A = LU$. When partial pivoting is used to improve numerical stability, the factorization becomes $PA = LU$, where $P$ is a permutation matrix that records the row swaps performed during Gaussian elimination.

The lower triangular matrix $L$ has ones on its diagonal and stores the multipliers used during elimination, while the upper triangular matrix $U$ is the row echelon form of the original matrix. This factorization is one of the most fundamental and widely used techniques in numerical linear algebra.

How LU Decomposition Works

The algorithm proceeds through each column $k$ of the matrix:

  1. Partial pivoting: Find the row with the largest absolute value in column $k$ and swap it into the pivot position. This prevents division by zero and improves numerical stability.
  2. Elimination: For each row below the pivot, compute the multiplier $L_{ik} = U_{ik} / U_{kk}$ and subtract the scaled pivot row to eliminate the column entry.
  3. The multiplier values form the subdiagonal entries of $L$, while the eliminated matrix becomes $U$.

The result is stored compactly: the elimination multipliers fill $L$ (with ones on the diagonal), and the row echelon form fills $U$. The permutation matrix $P$ records all row swaps.

Solving Linear Systems with LU

Once $PA = LU$ is computed, solving $Ax = b$ becomes a two-step process. First, solve $Ly = Pb$ using forward substitution (straightforward since $L$ is lower triangular). Then solve $Ux = y$ using back substitution (straightforward since $U$ is upper triangular). This two-step approach is much more efficient than performing Gaussian elimination from scratch for each new right-hand side $b$, making LU decomposition ideal for problems with multiple right-hand sides.

Applications

LU decomposition is widely used in:

  • Engineering — solving large systems from finite element analysis, circuit simulation, and structural mechanics
  • Scientific computing — numerical solution of differential equations, matrix inversion, and condition number estimation
  • Statistics — regression analysis, covariance matrix factorization, and maximum likelihood estimation
  • Computer graphics — transformation pipelines and physics simulations
  • Machine learning — training linear models and Gaussian processes

For related linear algebra tools, try the Matrix Exponential Calculator, Linear Equation Solver, or Derivative Calculator.

Frequently Asked Questions

What is LU decomposition used for?

LU decomposition is primarily used to solve systems of linear equations $Ax = b$ efficiently. Once the factorization $PA = LU$ is computed, it can be reused to solve for many different right-hand side vectors $b$ using forward and back substitution. It is also used to compute matrix determinants, find matrix inverses, and analyze numerical stability.

Why is partial pivoting needed?

Partial pivoting swaps rows to place the largest absolute value in the pivot position. This prevents division by zero when a pivot element is zero and reduces numerical errors caused by dividing by small numbers. With partial pivoting, the factorization becomes $PA = LU$, where $P$ is a permutation matrix.

How is the determinant computed from LU decomposition?

The determinant of $A$ can be efficiently computed from the LU factors as $\det(A) = (-1)^s \cdot \prod_{i=1}^{n} U_{ii}$, where $s$ is the number of row swaps and $U_{ii}$ are the diagonal entries of $U$. Since $\det(L) = 1$ (all diagonal entries of $L$ are 1), the determinant follows from $\det(P)\det(A) = \det(L)\det(U)$.

Can every square matrix be LU decomposed?

Not every square matrix has an LU decomposition without pivoting. A matrix has an LU factorization if and only if all its leading principal minors are nonzero. However, with partial pivoting ($PA = LU$), every nonsingular square matrix can be decomposed. Singular matrices may fail if a zero pivot is encountered.

What is the difference between LU and other matrix factorizations?

LU is faster than QR decomposition ($O(\frac{2}{3}n^3)$ vs $O(\frac{4}{3}n^3)$) but less numerically stable. QR is preferred for least-squares problems. Cholesky decomposition ($A = LL^T$) works only for symmetric positive-definite matrices but is twice as fast and more stable than general LU.