An LU factorization calculator splits a matrix into a lower triangular matrix L and an upper triangular matrix U, so that the original matrix equals L times U. The factorization is useful because solving a system with L and U, one triangular step at a time, is easier than solving the original system directly, and the same factorization can be reused for several right-hand sides.
This guide keeps the example to a simple 2×2 matrix, so every step can be checked by hand. For a 2×2 matrix [[a, b], [c, d]], the factorization has a clean form when a is not zero. L is [[1, 0], [c/a, 1]] and U is [[a, b], [0, d – (c/a) x b]]. Multiplying L by U returns the original matrix, which is the check that matters most. Larger matrices follow the same elimination idea, but the arithmetic grows quickly and is better done by software.
What this calculator does
Gaussian elimination explains the factors. The first step eliminates c, the entry below a, by subtracting (c/a) times the first row from the second row. The multiplier c/a becomes the entry below the diagonal in L, and the resulting second row becomes the second row of U. The first row is unchanged and becomes the first row of U. That is why L has 1s on its diagonal and a single multiplier below, and why U is upper triangular.
The calculator below implements that 2×2 form exactly. It requires a to be non-zero, because division by a is the first step. If a is zero, the simple form without row exchanges does not apply, and a row swap or a permutation matrix would be needed, which is outside the scope of this guide.
Formula
For [[a, b], [c, d]] with a not 0: L = [[1, 0], [c/a, 1]], U = [[a, b], [0, d – (c/a) x b]], and L x U = original matrix.
How to use it
- Write the matrix as [[a, b], [c, d]] and check that a is not 0.
- Compute the multiplier m = c / a. That is the lower entry of L.
- Keep the first row as the first row of U: [a, b].
- Compute the new second-row, second-column entry of U as d – m x b. The second-row, first-column entry of U is 0.
- Multiply L by U and confirm you recover [[a, b], [c, d]].
Try the calculator
Worked example
Factor the matrix [[4, 3], [6, 3]]. Here a = 4, b = 3, c = 6, d = 3. The multiplier is m = 6 / 4 = 1.5. Therefore L = [[1, 0], [1.5, 1]]. The upper matrix is U = [[4, 3], [0, 3 – 1.5 x 3]] = [[4, 3], [0, -1.5]], because 1.5 x 3 = 4.5 and 3 – 4.5 = -1.5. Multiplying L by U gives first row [4, 3] and second row [1.5 x 4, 1.5 x 3 + (-1.5)] = [6, 3], which is the original matrix. The factorization is therefore correct.
This check by multiplication is essential. If L x U does not return the original matrix, the multiplier or the U entry was computed wrong, and the error is in that step, not in the idea of the factorization.
How to check your answer
Multiply L by U by hand for the example. The product must equal the original matrix exactly, apart from rounding.
Check that L is lower triangular with 1s on the diagonal and U is upper triangular with 0 below the diagonal.
Test a matrix where c is 0. Then m = 0, L is the identity matrix, and U equals the original matrix, which is a sensible limiting case.
Common mistakes
- Dividing by a when a is 0, which the simple 2×2 form without row exchanges cannot handle.
- Forgetting to subtract m x b when computing the lower-right entry of U, and instead copying d unchanged.
- Placing the multiplier in U instead of L, which swaps the roles of the two factors.
- Skipping the L x U multiplication check, which is the fastest way to catch an arithmetic slip.
Frequently asked questions
What are L and U?
L is a lower triangular matrix, with zeros above the diagonal, and U is an upper triangular matrix, with zeros below the diagonal. Their product is the original matrix.
Why factor a matrix at all?
Because solving triangular systems is easy by forward and backward substitution, so one factorization can solve several systems with the same matrix more efficiently.
What if a is 0?
The simple form here needs a row exchange first, which introduces a permutation matrix. That case is handled by a more general LU with pivoting, not by this 2×2 calculator.