LU Decomposition Calculator
Factor a square matrix into a unit lower triangular L and an upper triangular U.
What it does
LU decomposition factors a square matrix A into L times U, where L is lower triangular and U is upper triangular. The version used here is the Doolittle form, which fixes every diagonal entry of L to one and stores the elimination multipliers below the diagonal.
The University of Pennsylvania notes on LU without pivoting show that the multipliers from Gaussian elimination can be collected directly into L. Multiplying the elimination inverses gives a unit lower triangular matrix whose subdiagonal entries are exactly those multipliers.
Illinois at Urbana Champaign lecture notes give the same construction and the compact algorithm: compute each row of U first, then the corresponding column of L, using previously computed entries. This is what the engine implements.
This tool accepts the full matrix for a 2 by 2 or 3 by 3 case and returns the entries of L and U. It stops with a clear message if a zero pivot appears, because a factorisation without row swaps is then impossible.
Once A is factored, solving A x = b becomes two triangular solves, which is cheaper than repeating elimination when b changes.
How to use
- Choose a 2 by 2 or 3 by 3 matrix.
- Enter all entries of the matrix, row by row.
- Read the upper triangular factor U, starting at the top left.
- Read the lower triangular factor L. Its diagonal is one and is not printed.
- For a 2 by 2 matrix, the 3 by 3 entries show a dash.
- Multiply L by U on paper to confirm you recover the input matrix.
Formula
- A
- The square matrix being factored.
- L
- Unit lower triangular factor, with ones on the diagonal.
- U
- Upper triangular factor.
- U(i,i)
- The pivot at step i. It must be nonzero for this method.
The engine reads previously computed entries only, so each pass fills one row of U and one column of L. A pivot whose absolute value is below 1e-12 stops the calculation. Unlike a full PA = LU routine, this tool does not swap rows.
Worked example
Example: factoring a 2 by 2 matrix
A has entries A(1,1) = 4, A(1,2) = 3, A(2,1) = 6 and A(2,2) = 3.
- The first pivot is U(1,1) = A(1,1) = 4.000000.
- The upper right entry is U(1,2) = A(1,2) = 3.000000.
- The multiplier below the pivot is L(2,1) = A(2,1) / U(1,1) = 6 / 4 = 1.500000.
- The second pivot is U(2,2) = A(2,2) - L(2,1) U(1,2) = 3 - 1.5 x 3 = -1.500000.
- Check the product: row 2 of L times U gives 1.5 x 4 = 6 and 1.5 x 3 - 1.5 = 3.
- The tool reports U(1,1) 4.000000, U(1,2) 3.000000, L(2,1) 1.500000 and U(2,2) -1.500000.
- The 3 by 3 default gives U(3,3) equal to 3.166667.
Reference table
| Matrix | Row 1 | Row 2 |
|---|---|---|
| A | [4, 3] | [6, 3] |
| L | [1, 0] | [1.5, 1] |
| U | [4, 3] | [0, -1.5] |
| L times U | [4, 3] | [6, 3] |
Limits
- Only 2 by 2 and 3 by 3 matrices are supported.
- Matrices that need row swaps cannot be factored by this tool.
- The matrix should be square and reasonably well conditioned.
- Entries are limited to 1e9 and results are shown to six decimal places.
Common mistakes
- Entering a matrix with a zero leading entry and expecting a factor without pivoting.
- Assuming L has the elimination multipliers on its diagonal instead of U.
- Forgetting that a dash in an output means that entry does not exist for the chosen size.
- Comparing this factor with a Cholesky factor, which applies only to positive definite matrices.
- Multiplying U by L instead of L by U when checking the result.
Try it yourself
Quick checks. Answers sit tucked under each question.
For A = [[4,3],[6,3]], what are L and U?
L21 = 1.5, U11 = 4, U12 = 3 and U22 = -1.5. The product L U returns A.
Why does a zero pivot stop the method?
Because the next multiplier would require division by that pivot. A row swap would be needed.
What is special about the diagonal of L?
In the Doolittle form used here, every diagonal entry of L is one.
Questions
What is LU decomposition used for?
Solving several systems with the same matrix, computing determinants and inverting matrices.
Is the factorisation unique?
It is unique when L is required to have a unit diagonal and no row swaps are needed.
How is it related to Gaussian elimination?
The multipliers used to clear entries below pivots become the subdiagonal entries of L.
How is it different from Cholesky?
Cholesky needs a symmetric positive definite matrix and produces L L transpose. LU works for a wider class of matrices.
Why does the tool reject some matrices?
A zero pivot cannot be divided by, and this implementation does not swap rows.
Can I use this for a 4 by 4 matrix?
Not on this page. The tool is limited to 2 by 2 and 3 by 3 inputs.
Sources
- University of Pennsylvania, LU Decomposition Without Pivoting
- University of Illinois at Urbana Champaign, CS 357 Lecture 8