LU Decomposition Calculator

Factor a square matrix into lower and upper triangular matrices A=LU with step-by-step Doolittle method, solve Ax=b via forward/back substitution, and verification display.

Matrix A (3×3)
Vector b
Decomposition
Success ✓
PA = LU factored successfully
Determinant
4.000000
Product of diagonal of U (with sign from pivoting)
Steps
5
Elimination + pivot operations
Max Error ‖LU−PA‖
0.00
Verification: should be ≈ 0
x1
1.000000
Solution component 1
x2
1.000000
Solution component 2
x3
1.000000
Solution component 3
Intermediate y
[24.0000, -2.0000, -0.6667]
Ly = Pb (forward substitution)

Lower Triangular L

1.00000.00000.0000
0.25001.00000.0000
0.50000.66671.0000

Upper Triangular U

8.00007.00009.0000
0.0000-0.7500-1.2500
0.00000.0000-0.6667

Solution Visualization

x1
1.0000
x2
1.0000
x3
1.0000

Decomposition Steps

#Operation
1Swap R1 ↔ R3 (pivot = 8.0000)
2l21 = 0.500000, R2 − 0.5000·R1
3l31 = 0.250000, R3 − 0.2500·R1
4Swap R2 ↔ R3 (pivot = -0.7500)
5l32 = 0.666667, R3 − 0.6667·R2

Solution Verification (Ax = b)

RowAxbMatch
14.0000004.000000
210.00000010.000000
324.00000024.000000
Planning notes, formulas, and examples

About the LU Decomposition Calculator

LU decomposition factors a square matrix A into the product of a lower triangular matrix L and an upper triangular matrix U, so that A = LU. This factorization is the computational backbone of most numerical linear algebra: once you have L and U, solving Ax = b becomes two simple triangular solves — forward substitution for Ly = b, then back substitution for Ux = y — each requiring only O(n²) operations.

This calculator implements the Doolittle algorithm, where L has 1s on the diagonal and U retains the original diagonal scaling. The step-by-step display shows how each element of L and U is computed, with the multipliers (entries of L) clearly identified.

For systems with the same coefficient matrix but different right-hand sides (b vectors), LU decomposition is far more efficient than re-running Gauss-Jordan elimination each time — you factor once and solve repeatedly. This is why LU is the workhorse method in engineering simulations and scientific computing.

The calculator handles matrices from 2×2 to 5×5, with optional partial pivoting (row swaps) when a zero pivot is encountered. It also computes the determinant from the diagonal of U (since det(A) = det(L)·det(U) = product of diagonal entries of U when L has unit diagonal), and verifies that L·U reproduces the original matrix A.

When This Page Helps

LU decomposition requires careful bookkeeping of multipliers and pivots across n² entries — a single incorrect multiplier corrupts all subsequent rows. The savings come from factoring once and reusing L and U for many right-hand sides, but the factoring step itself is where mistakes occur. This calculator shows every multiplier, pivot swap, and row operation, displays the final L and U, computes the determinant from U’s diagonal, and solves Ax = b via forward and back substitution. It is the preferred tool for students learning triangular factorization and engineers verifying decompositions.

How to Use the Inputs

  1. Select the matrix size (2×2 to 5×5)
  2. Enter the matrix elements or choose a preset
  3. View the L and U matrices in the output
  4. Optionally enter a right-hand side vector b to solve Ax=b
  5. Follow the step-by-step decomposition process
  6. Check the verification table confirming L·U = A
Formula used
A = LU where L is lower triangular with 1s on diagonal, U is upper triangular. Solve: Ly = b (forward), Ux = y (backward).

Example Calculation

Result: L = [[1,0,0],[2,1,0],[4,3,1]], U = [[2,1,1],[0,1,1],[0,0,2]]

Row 2: l₂₁=4/2=2, subtract 2×R1 from R2. Row 3: l₃₁=8/2=4, l₃₂=(7-4·1)/1=3, giving the final U.

Tips & Best Practices

  • LU decomposition requires no zero pivots (or use partial pivoting to avoid them)
  • The determinant is the product of U's diagonal entries when L has unit diagonal
  • Factor once, solve for many different b vectors — much faster than repeated elimination
  • Partial pivoting (PA = LU) improves numerical stability for ill-conditioned matrices
  • For symmetric positive definite matrices, Cholesky decomposition (A = LLᵀ) is more efficient

The Doolittle Algorithm

The Doolittle method constructs L with 1s on the diagonal and stores the elimination multipliers below. For each column k, the algorithm computes the off-diagonal entries of L (lᵢₖ = aᵢₖ / uₖₖ for i > k) and the entries of U (uₖⱼ = aₖⱼ − Σₘ<ₖ lₖₘuₘⱼ for j ≥ k). Each multiplier records how much of row k was subtracted from row i during elimination — this is why LU decomposition is equivalent to Gaussian elimination with the operations recorded in L.

Partial Pivoting and Permutation Matrices

When a zero (or very small) pivot is encountered, **partial pivoting** swaps rows to place the largest absolute value in the pivot position, improving numerical stability. The factorization becomes PA = LU where P is a permutation matrix recording the row swaps. Modern numerical libraries (LAPACK, NumPy) always use partial pivoting. The determinant is then det(A) = (−1)^s · ∏ uᵢᵢ, where s is the number of row swaps.

Efficiency and Multiple Right-Hand Sides

The factorization phase costs ≈ 2n³/3 floating-point operations, comparable to Gaussian elimination. The key advantage is **reusability**: each subsequent solve for a new right-hand side b costs only 2n² operations (forward + back substitution). This makes LU decomposition the standard method in circuit simulation, structural analysis, and any application where the same system matrix is solved with many different loads or inputs. For symmetric positive definite matrices, Cholesky decomposition (A = LLᵀ) is about twice as fast.

Sources & Methodology

Last updated:

Frequently Asked Questions

  • LU decomposition factors a square matrix A into a lower triangular matrix L (with 1s on the diagonal) and an upper triangular matrix U, such that A = LU. It is equivalent to Gaussian elimination with the multipliers stored in L.