# What is the LU factorization of A?

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.

- Page: https://www.acalculator.org/math/lu-decomposition-calculator
- JSON spec: https://www.acalculator.org/math/lu-decomposition-calculator.json
- Version: 7b6b33eb675a

## Default answer

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].

## Inputs

| Key | Label | Description |
| --- | --- | --- |
| a | Matrix A | The square matrix to factor, 2 to 6 rows and the same number of columns. Fractions such as 1/3 work. |

## Outputs

| Key | Label | Description |
| --- | --- | --- |
| l | L (lower triangular) | The multipliers of elimination under a diagonal of 1s, as exact fractions, rows separated by semicolons. |
| u | U (upper triangular) | The matrix after elimination, as exact fractions. |
| p | P (row swaps) | The permutation matrix when rows were swapped, so PA = LU; the identity when none were. |
| form | Form | "A = LU" with no row swaps, or "PA = LU" with them. |
| determinant | Determinant | det A = (−1)^swaps × the product of U’s diagonal, as an exact fraction. |
| steps | Elimination steps | Each row swap and each row operation, with the multiplier it puts into L. |

## 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.

## Assumptions

- 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

1. a = 2 or 1 or 4 or -6 gives l = [1, 0, 0; 2, 1, 0; −1, −1, 1], u = [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).
2. a = 2 or 1 or 8 or 7 gives l = [1, 0; 4, 1], u = [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).
3. a = 0 or 1 or 2 or 3 gives p = [0, 1; 1, 0], l = [1, 0; 0, 1], u = [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).
4. a = 1 or 2 or 3 or 4.5 gives l = [1, 0; 3, 1], u = [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).

## FAQ

### 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.

## Sources

- MIT OpenCourseWare, 18.06 Linear Algebra (Gilbert Strang), Lecture 4: Factorization into A = LU (L holds the multipliers, U the 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)
- OpenStax, Algebra and Trigonometry 2e, §11.6 Solving Systems with Gaussian Elimination (row operations to row echelon form), CC BY 4.0. https://openstax.org/books/algebra-and-trigonometry-2e/pages/11-6-solving-systems-with-gaussian-elimination (retrieved 2026-10-02)
