Math & Statistics

LU Factorization Calculator

Enter a square matrix to factor it as A = LU, with L lower triangular (1s on the diagonal) and U upper triangular. Every elimination step and multiplier is shown in exact fractions. Choose partial pivoting to get PA = LU with the permutation matrix P.

Free, runs in your browserUpdated October 2026
Matrix size
Matrix A
Whole numbers, decimals and fractions such as 3/4 are accepted.
Examples
A = LU
–
det(A)–
Pivots (diagonal of U)–
Row swaps–
Invertible–

Step-by-step elimination

    LU Factorization Calculator diagram: textbook 3 × 3 matrix factors into L and U with det −16
    How the LU Factorization Calculator works: A = LU with exact multipliers, or PA = LU with pivoting

    How to Use the LU Factorization Calculator

    How to use the LU Factorization Calculator: size switch, matrix grid, method and L and U result
    Numbered steps on the LU Factorization Calculator. Follow them in order.
    1. Choose the matrix size, 2 × 2 to 4 × 4.
    2. Type the entries. Fractions such as 3/4 are fine.
    3. Choose A = LU or PA = LU with partial pivoting.
    4. Read L, U and P, then follow each elimination step below.

    Pick the matrix size, 2 × 2, 3 × 3 or 4 × 4, and type the entries of A. Whole numbers, decimals and fractions such as 3/4 all work, and every result is kept as an exact fraction. The factors L and U appear in the result panel together with the determinant, the pivots and whether the matrix is invertible.

    The default method, A = LU, follows the Doolittle convention used in most linear algebra courses: L has 1s on its diagonal and no rows are swapped unless a zero pivot forces it. Choose PA = LU to use partial pivoting, which always swaps the largest available entry into the pivot position. The steps below the tool show every multiplier, the matrix after each column and a final check that L times U gives back the original matrix.

    How LU Factorization Works

    LU factorization is Gaussian elimination with a memory. Each time you subtract a multiple of the pivot row from a row below it, the multiplier is saved in L, and the matrix you end up with is U.

    lik = uik ÷ ukk    Ri → Ri − likRk
    A = LU, or PA = LU when rows are swapped
    det(A) = (−1)swaps × u11u22…unn

    Once you have the factors, solving Ax = b takes two quick triangular solves: first Ly = b by forward substitution, then Ux = y by back substitution. That is why LU factorization is used whenever the same matrix must be solved with many right-hand sides.

    Worked Example

    Factor A with rows (2, 1, 1), (4, −6, 0) and (−2, 7, 2).

    • Column 1, pivot 2: l21 = 4 ÷ 2 = 2 and l31 = −2 ÷ 2 = −1. Row 2 becomes (0, −8, −2) and row 3 becomes (0, 8, 3).
    • Column 2, pivot −8: l32 = 8 ÷ (−8) = −1. Row 3 becomes (0, 0, 1).
    • So L has rows (1, 0, 0), (2, 1, 0), (−1, −1, 1), and U has rows (2, 1, 1), (0, −8, −2), (0, 0, 1).
    • det(A) = 2 × (−8) × 1 = −16.

    Multiplying L by U returns A exactly, which is the check shown at the end of the steps.

    When Row Swaps Are Needed

    If a pivot is zero, elimination cannot continue in that column, and A has no LU factorization in the plain form. Swapping rows fixes this, and the swaps are recorded in a permutation matrix P, giving PA = LU. Partial pivoting goes further and swaps the largest entry into place even when the pivot is not zero, which keeps the multipliers at or below 1 in size and reduces rounding error in floating point software.

    FormLUTypical use
    Doolittle A = LU1s on the diagonalPivots on the diagonalHand calculation, textbooks
    PA = LU1s on the diagonal, multipliers at most 1 in sizePivots on the diagonalNumerical software
    Crout A = LUPivots on the diagonal1s on the diagonalSome engineering courses

    Using LU to Solve a System

    For the example matrix and b = (5, −2, 9), forward substitution in Ly = b gives y = (5, −12, 2), and back substitution in Ux = y gives x = (1, 1, 2). Check: 2 + 1 + 2 = 5, 4 − 6 = −2 and −2 + 7 + 4 = 9.

    Tips and Limits

    • A singular matrix can still have an LU factorization, but U will have a zero on its diagonal and the matrix has no inverse.
    • Because the arithmetic is exact, the PA = LU option here shows the swaps you would make by hand. Software such as NumPy or MATLAB returns decimals and may order rows differently.
    • Check your own work by multiplying L and U. If you get A back, the factorization is correct.
    • The calculator supports square matrices up to 4 × 4.

    Frequently asked questions

    What is LU factorization?

    It writes a square matrix A as the product of a lower triangular matrix L and an upper triangular matrix U. It is Gaussian elimination recorded as matrices, and it makes solving Ax = b fast.

    How do you find L and U?

    Use row operations to eliminate the entries below each pivot. The resulting upper triangular matrix is U, and each multiplier you used, the entry divided by the pivot, goes into the matching position of L.

    Does every matrix have an LU factorization?

    No. If a zero appears in a pivot position, plain LU fails. Every square matrix does have a factorization PA = LU, where the permutation matrix P records the row swaps.

    What is partial pivoting?

    Before eliminating each column, the row with the largest absolute value in that column is swapped into the pivot position. This limits the size of the multipliers and makes computer calculations more stable.

    How do you get the determinant from LU?

    Multiply the diagonal entries of U, then change the sign once for every row swap. For the default example, 2 times minus 8 times 1 gives a determinant of minus 16.

    How is LU used to solve Ax = b?

    Solve Ly = b by forward substitution, then Ux = y by back substitution. The expensive factorization is done once, so many right-hand sides can be solved quickly.