What is the LU factorization of A?
Type a square matrix, 2 × 2 up to 6 × 6. The LU decomposition calculator runs Gaussian elimination in exact fractions and gives the LU factorization A = LU, with L lower triangular and U upper triangular, or PA = LU when a row swap is needed, plus the determinant and every step.
- L (lower triangular)
- [1, 0, 0; 2, 1, 0; −1, −1, 1]
A = LU with L = [1, 0, 0; 2, 1, 0; −1, −1, 1] and U = [2, 1, 1; 0, −8, −2; 0, 0, 1].
- U (upper triangular)
- [2, 1, 1; 0, −8, −2; 0, 0, 1]
- P (row swaps)
- [1, 0, 0; 0, 1, 0; 0, 0, 1]
- Form
- A = LU
- Determinant
- −16
- Elimination steps
- R2 → R2 − (2) × R1, so l21 = 2; R3 → R3 − (−1) × R1, so l31 = −1; R3 → R3 − (−1) × R2, so l32 = −1
L (lower triangular): [1, 0, 0; 2, 1, 0; −1, −1, 1]. A = LU with L = [1, 0, 0; 2, 1, 0; −1, −1, 1] and U = [2, 1, 1; 0, −8, −2; 0, 0, 1].
How it is worked out
How to calculate
Factors a square matrix into A = LU (or PA = LU with row swaps) by Gaussian elimination in exact fractions: L lower triangular with 1s on the diagonal, U upper triangular, with the determinant and every step.
Example with the default inputs (Matrix A [2, 1, 1; 4, -6, 0; -2, 7, 2]): A = LU with L = [1, 0, 0; 2, 1, 0; −1, −1, 1] and U = [2, 1, 1; 0, −8, −2; 0, 0, 1].
Method: Gaussian elimination: for each pivot column k, l_ik = u_ik ÷ u_kk and row i → row i − l_ik × row k; a zero pivot swaps in the first lower row with a nonzero entry (PA = LU); det A = (−1)^swaps × Π u_kk.
- Entries are read exactly: a decimal such as 4.5 is 9/2, so L and U are exact fractions.
- Rows are swapped only when a pivot is 0, not for size (no partial pivoting by largest entry), so the L and U match a hand calculation.
- A singular matrix still factors; a column with no nonzero pivot is skipped and U has a 0 on its diagonal.
Worked examples
Each example is checked against the calculator on every build.
- Matrix A 2, 1, 1; 4, -6, 0; -2, 7, 2 gives L (lower triangular) [1, 0, 0; 2, 1, 0; −1, −1, 1], U (upper triangular) [2, 1, 1; 0, −8, −2; 0, 0, 1], Form A = LU, Determinant −16.Source: MIT OpenCourseWare, 18.06 Linear Algebra (Gilbert Strang), Lecture 4: Factorization into A = LU (L holds the multipliers with 1s on the diagonal, U is the upper triangular result of elimination; PA = LU with row exchanges), https://ocw.mit.edu/courses/18-06-linear-algebra-spring-2010/resources/lecture-4-factorization-into-a-lu/ (retrieved 2026-10-02)
- Matrix A 2, 1; 8, 7 gives L (lower triangular) [1, 0; 4, 1], U (upper triangular) [2, 1; 0, 3], Determinant 6.Source: MIT OpenCourseWare, 18.06 Linear Algebra (Gilbert Strang), Lecture 4: Factorization into A = LU (L holds the multipliers with 1s on the diagonal, U is the upper triangular result of elimination; PA = LU with row exchanges), https://ocw.mit.edu/courses/18-06-linear-algebra-spring-2010/resources/lecture-4-factorization-into-a-lu/ (retrieved 2026-10-02)
- Matrix A 0, 1; 2, 3 gives P (row swaps) [0, 1; 1, 0], L (lower triangular) [1, 0; 0, 1], U (upper triangular) [2, 3; 0, 1], Form PA = LU, Determinant −2.Source: MIT OpenCourseWare, 18.06 Linear Algebra (Gilbert Strang), Lecture 4: Factorization into A = LU (L holds the multipliers with 1s on the diagonal, U is the upper triangular result of elimination; PA = LU with row exchanges), https://ocw.mit.edu/courses/18-06-linear-algebra-spring-2010/resources/lecture-4-factorization-into-a-lu/ (retrieved 2026-10-02)
- Matrix A 1, 2; 3, 4.5 gives L (lower triangular) [1, 0; 3, 1], U (upper triangular) [1, 2; 0, −3/2], Determinant −3/2.Source: OpenStax, Algebra and Trigonometry 2e, §11.6 Solving Systems with Gaussian Elimination (row operations to upper triangular form), https://openstax.org/books/algebra-and-trigonometry-2e/pages/11-6-solving-systems-with-gaussian-elimination (retrieved 2026-10-02)
How it works
Start with U = A, L = the identity and P = the identity. For each column k from the first to the last:
- Pivot. If u_kk is 0, find the first row r below k with u_rk not 0 and swap rows k and r in U, swap the same rows of P, and swap the multipliers already in L (columns before k) of those two rows. If every entry from row k down is 0, skip the column.
- Eliminate. For each row i below k: the multiplier l_ik = u_ik ÷ u_kk; row i of U → row i − l_ik × row k; put l_ik into L. A multiplier of 0 is skipped.
Then PA = LU, written A = LU when no rows were swapped, and det A = (−1)^swaps × u₁₁ × u₂₂ × … × u_nn.
Every entry is read as the exact fraction it stands for (4.5 is 9/2, 1/3 is 1/3), and all arithmetic is exact. Rows are swapped only for a 0 pivot, never to pick a larger pivot.
Rules
- The matrix is square, 2 × 2 to 6 × 6.
Output format. Each matrix as [a, b; c, d]: rows separated by semicolons, entries by commas, each entry a fraction in lowest terms such as −3/2 with the true minus sign (−). P is shown always (the identity when no rows were swapped). The form is A = LU or PA = LU. The determinant is an exact fraction. Each step reads R2 → R2 − (m) × R1, so l21 = m or R1 ↔ R2; with no step, none: A is already upper triangular.
Worked examples by hand
A = [2, 1, 1; 4, −6, 0; −2, 7, 2]. Column 1: l₂₁ = 4 ÷ 2 = 2, row 2 → [0, −8, −2]; l₃₁ = −2 ÷ 2 = −1, row 3 → [0, 8, 3]. Column 2: l₃₂ = 8 ÷ −8 = −1, row 3 → [0, 0, 1]. So L = [1, 0, 0; 2, 1, 0; −1, −1, 1], U = [2, 1, 1; 0, −8, −2; 0, 0, 1], det = 2 × −8 × 1 = −16.
A = [2, 1; 8, 7]. l₂₁ = 4, row 2 → [0, 3]: L = [1, 0; 4, 1], U = [2, 1; 0, 3], det 6.
A = [0, 1; 2, 3]. The first pivot is 0, so swap rows 1 and 2: P = [0, 1; 1, 0], U = [2, 3; 0, 1], L = the identity, PA = LU, det = −(2 × 1) = −2.
A = [1, 2; 3, 4.5]. l₂₁ = 3, row 2 → [0, 9/2 − 6] = [0, −3/2]: U = [1, 2; 0, −3/2], det −3/2.
Other questions people ask
What is LU decomposition?
It writes a square matrix as A = LU: a lower triangular matrix L with 1s on its diagonal times an upper triangular matrix U. U is what Gaussian elimination leaves, and L records the multipliers used, so the factorization stores elimination for reuse.
How do I find L and U by hand?
Eliminate below each pivot. For A = [2, 1; 8, 7], the multiplier is 8 ÷ 2 = 4, and row 2 minus 4 × row 1 is [0, 3]. So U = [2, 1; 0, 3] and L = [1, 0; 4, 1]. Check: L times U gives back A.
When do I need PA = LU?
When a pivot is 0, elimination cannot divide by it, so you swap in a lower row first. The swaps are collected in a permutation matrix P, and the factorization is PA = LU. [0, 1; 2, 3] needs one swap: P = [0, 1; 1, 0].
What is LU decomposition used for?
To solve Ax = b for many right-hand sides: factor once, then solve Ly = b by forward substitution and Ux = y by back substitution, which is fast. The determinant also falls out: it is the product of U’s diagonal, with a minus sign for each row swap.
Does every matrix have an LU decomposition?
Every square matrix has a PA = LU factorization once rows may be swapped. Without swaps, A = LU exists when no zero pivot appears. A singular matrix still factors, but U then has a 0 on its diagonal and the determinant is 0.
Why are the answers fractions?
The calculator works in exact fractions, so 4.5 is read as 9/2 and no rounding creeps in. Hand calculations in class use fractions too, so the L and U match line for line.