lu factorization calculator

LU Decomposition Calculator (with Partial Pivoting)

Enter a square matrix A, then compute P·A = L·U.

Tip: decimals and negative values are supported. If pivoting is needed, the calculator returns a permutation matrix P.

What is LU factorization?

LU factorization (also called LU decomposition) rewrites a square matrix as the product of two triangular matrices: A = L·U in the simple case, or more generally P·A = L·U when row swaps are needed for numerical stability.

  • L is lower triangular (zeros above the diagonal).
  • U is upper triangular (zeros below the diagonal).
  • P is a permutation matrix representing row swaps.

Why LU decomposition is useful

LU decomposition is one of the most practical tools in numerical linear algebra. Instead of solving a full system from scratch each time, you factor once and solve quickly using substitution.

Common applications

  • Solving linear systems Ax = b efficiently.
  • Computing determinants from diagonal entries of U.
  • Building matrix inverse routines.
  • Powering simulations in engineering, data science, and optimization.

How to use this calculator

  1. Select matrix size (2 to 8).
  2. Click Generate Matrix Fields.
  3. Enter matrix values, or click Load Example Matrix.
  4. Click Calculate LU Factorization.
  5. Read the computed P, L, and U matrices, plus verification metrics.

Understanding the output

Permutation matrix P

If your matrix needs row exchanges (for zero or tiny pivots), you will see a non-identity permutation matrix. The exact factorization is then P·A = L·U.

Lower and upper triangular factors

The lower matrix contains elimination multipliers, with 1s on the diagonal. The upper matrix contains the transformed coefficients after elimination.

Residual check

The residual norm measures how close P·A is to L·U. A tiny value (near zero) indicates a correct decomposition up to floating-point rounding.

Numerical notes

Real-world calculations use floating-point arithmetic, so small rounding differences are expected. Partial pivoting significantly improves stability and handles many cases where naive LU would fail.

  • If a pivot is effectively zero after pivoting, the matrix is singular (or near singular).
  • Singular matrices do not have a unique LU decomposition suitable for solving all systems.
  • For ill-conditioned matrices, expect larger rounding sensitivity.

Quick example

For a matrix such as A = [[2,1,1],[4,-6,0],[-2,7,2]], LU factorization yields triangular matrices that can be used to solve any right-hand side vector much faster than repeating Gaussian elimination each time.

Final takeaway

LU factorization is foundational for efficient matrix computation. Use this calculator to explore decomposition, verify identities, and build intuition for how linear systems are solved in scientific computing.

🔗 Related Calculators