Scientia sine finibus

Linear Algebra / Unit 3, Matrices / Topic 3.6

Units and Topics

Unit 3. Matrices

3.6 LU Factorization

This topic shows that elimination writes a square matrix as a product of two triangular matrices, A = LU. The factorization keeps a record of the elimination steps, so that the same matrix can be used again with new right sides.

You need Topics 2.2, 3.2, 3.3, and 3.4 for this topic.

1. A Row Operation Is a Matrix Multiplication

Each row operation of Topic 2.2 can be done by multiplying the matrix on the left by another matrix. To find that matrix, apply the row operation to the identity matrix. The result is called an elementary matrix.

For example, the operation R₂ → R₂ − 2R₁ on a matrix with three rows is the multiplication by

E = 100−210001

Check it on a matrix A.

EA = 100−210001 211433879E subtracts 2 times row 1 from row 2EA = 211011879row 2 is now (0, 1, 1)

Row 2 of the product is row 2 of A minus 2 times row 1 of A. The other rows did not change.

The inverse of an elementary matrix undoes the row operation. To undo “subtract 2 times row 1 from row 2”, add 2 times row 1 to row 2. So the inverse of E has +2 in place of −2.

E⁻¹ = 100210001

2. Elimination Without Row Exchanges

Reduce the matrix A to row echelon form, and write down the multiplier of each step. The multiplier is the number of times that the pivot row is subtracted.

StepOperationMultiplierResult
1R₂ → R₂ − 2R₁2211011879
2R₃ → R₃ − 4R₁4211011035
3R₃ → R₃ − 3R₂3211011002

The final matrix is upper triangular. It is called U. Its diagonal entries are the pivots 2, 1, and 2.

3. The Factorization A = LU

The three steps are three multiplications by elementary matrices, E₃E₂E₁A = U. Multiplying both sides by the inverses, in the reverse order, gives A back.

A = E₁⁻¹ E₂⁻¹ E₃⁻¹ U = LU

The matrix L = E₁⁻¹E₂⁻¹E₃⁻¹ is lower triangular, and it does not need to be calculated. It has 1 in each diagonal position, and each multiplier appears below the diagonal, in the position of the entry that the step removed.

L = 100210431 U = 211011002

The multiplier 2 removed the entry in row 2 and column 1, so it is in row 2 and column 1 of L. The multipliers 4 and 3 are in row 3. Check the product:

LU = 100210431 211011002multiply the two triangular matricesLU = 211433879the product is A

L stands for lower triangular and U stands for upper triangular. The matrix U is the result of elimination, and the matrix L is the record of how elimination reached it.

Step by step: building L and U

Press Next to do one elimination step. Each multiplier is written into L as soon as it is used. The last step multiplies L and U to check the result.

4. Solving a System with L and U

To solve Ax = b, write the system as L(Ux) = b and call the vector Ux by the name y. The system splits into two triangular systems.

  1. Solve Ly = b for y. Because L is lower triangular, work from the top row to the bottom row. This is called forward substitution.
  2. Solve Ux = y for x by back substitution, as in Topic 2.2.

For example, solve Ax = b with b = (5, 13, 33).

Forward substitution with L:

  • Row 1: y₁ = 5.
  • Row 2: 2y₁ + y₂ = 13, so y₂ = 3.
  • Row 3: 4y₁ + 3y₂ + y₃ = 33, so y₃ = 33 − 20 − 9 = 4.

Back substitution with U:

  • Row 3: 2x₃ = 4, so x₃ = 2.
  • Row 2: x₂ + x₃ = 3, so x₂ = 1.
  • Row 1: 2x₁ + x₂ + x₃ = 5, so x₁ = 1.

The solution is (1, 1, 2). Check:

2 + 1 + 2 = 5the first equation4 + 3 + 6 = 13the second equation8 + 7 + 18 = 33the third equation

Why the factorization is useful

The vector y is the right side after elimination, so the two substitutions do the same work as row reduction on the augmented matrix. The gain appears when the same matrix A is used with many different right sides. The elimination is done once, to find L and U. After that, each new right side needs only the two substitutions, which are much faster than a new elimination. In physics and engineering, the matrix often describes a fixed structure or circuit, and the right sides are the different loads or inputs.

5. When a Row Exchange Is Needed

Elimination needs a row exchange when a 0 appears in a pivot position. From Topic 3.3, a row exchange is a multiplication by a permutation matrix P. If the rows of A are first put in an order that needs no further exchanges, the reordered matrix PA has a factorization.

PA = LU

For example, the matrix below has a 0 in the first pivot position. Exchanging its two rows gives a matrix that is already upper triangular.

A = 0213 P = 0110 PA = 1302 = 1001 1302

Computer programs also exchange rows when a pivot is very small compared with the entries below it, because dividing by a very small number increases the rounding errors.

6. The Determinant from L and U

From Topic 3.4, the determinant of a product is the product of the determinants, and the determinant of a triangular matrix is the product of its diagonal entries. The diagonal entries of L are all 1, so det L = 1.

det A = (det L)(det U) = product of the pivots

For the example, det A = (2)(1)(2) = 4. When row exchanges are used, each exchange changes the sign, as in Topic 3.4.

Common Mistakes

  • Writing the multipliers into L with the wrong sign. If the step is R₂ → R₂ − 2R₁, the entry of L is +2.
  • Putting a multiplier in the wrong position. It goes where the removed entry was.
  • Multiplying in the order UL. The factorization is A = LU, and UL is usually a different matrix.
  • Solving the two triangular systems in the wrong order. Solve Ly = b first, and then Ux = y.
  • Scaling a row to make a pivot equal to 1 during the elimination. The factorization in this topic uses only the operation that subtracts a multiple of one row from another row.
  • Looking for A = LU when a pivot position holds 0. Exchange rows first, and factor PA.

Summary

TermMeaning
Elementary matrixThe identity matrix after one row operation
MultiplierThe number of times the pivot row is subtracted in one step
UThe upper triangular matrix that elimination produces
LThe lower triangular matrix with 1 on the diagonal and the multipliers below it
Forward substitutionSolving Ly = b from the top row to the bottom row
PA = LUThe factorization when row exchanges are needed

Practice

Work each problem on paper first. Then open the answer to check your work.

1. Write the elementary matrix for the operation R₃ → R₃ + 5R₁ on a matrix with three rows, and write its inverse.

Apply the operation to the identity matrix: E = 100010501.

The inverse subtracts 5 times row 1 from row 3: E⁻¹ = 100010−501.

2. Find L and U for A = 2167.

R₂ → R₂ − 3R₁gives the row (0, 4), with the multiplier 3L = 1031the multiplier goes below the diagonalU = 2104the row echelon formrow 2 of LU = 3(2, 1) + (0, 4) = (6, 7)the check

3. Find L and U for A = 1232583814.

R₂ → R₂ − 2R₁gives the row (0, 1, 2)R₃ → R₃ − 3R₁gives the row (0, 2, 5)R₃ → R₃ − 2R₂gives the row (0, 0, 1)

L = 100210321 and U = 123012001.

4. Use L and U from Problem 2 to solve Ax = b with b = (4, 20).

y₁ = 4forward substitution, row 13y₁ + y₂ = 20forward substitution, row 2y₂ = 20 − 12 = 8substitute y₁ = 44x₂ = 8back substitution, row 2x₂ = 2divide both sides by 42x₁ + x₂ = 4back substitution, row 1x₁ = 1substitute x₂ = 22 + 2 = 4the check in the first equation6 + 14 = 20the check in the second equation

The solution is (1, 2).

5. Find the determinant of the matrix in Problem 3 from its factorization.

The pivots are the diagonal entries of U: 1, 1, and 1. No row exchange was used, so det A = 1.

6. Why does A = 0123 have no factorization A = LU, and what should be done?

The first pivot position holds 0, so no multiple of row 1 can remove the 2 below it.

Exchange the two rows. Then PA = 2301, which is already upper triangular, so L = I and U = PA.

Python Practice

Step 1. Do the first elimination step and record the multiplier

The code below starts the factorization of the matrix A from Part 2 of this topic. The part dtype=float stores the entries as decimal numbers, so that divisions work correctly. The second line makes a copy of A under the name U, so that A itself does not change. The third line starts L as the 3 by 3 identity matrix.

Python counts rows and columns from 0. The entry in row 2 and column 1 of a matrix is written U[1, 0], and row 2 as a whole is written U[1]. The fourth line calculates the multiplier and stores it in L. The fifth line subtracts that multiple of row 1 from row 2.

Python

The multiplier 2 is now in L, and row 2 of U is 0, 1, 1.

Step 2. Remove the entry in row 3 and column 1

In the next box, add two lines before the print lines. The first new line stores the multiplier for row 3 in L[2, 0]. The second new line subtracts that multiple of row 1 from row 3. Follow the pattern of the fourth and fifth lines.

Python

Step 3. Finish the factorization

One entry below the diagonal of U is left, in row 3 and column 2. The pivot row for this step is row 2. Add the two lines that finish the factorization. The last line of the box multiplies L and U, so the last result should be the original matrix A.

Python

Step 4. Solve a system with L and U

The code below solves Ax = b for b = (5, 13, 33) in the two stages of Part 4. The instruction np.linalg.solve solves each triangular system.

Python

The results are y = (5, 3, 4) and x = (1, 1, 2), as in Part 4.

Now use the same L and U with a new right side, b = (4, 10, 26). Change only the third line.

Python

Step 5. Find the determinant from the pivots

When np.diag is given a matrix, it returns the diagonal entries of that matrix. The instruction np.prod multiplies all of the numbers in a list. Together they give the product of the pivots.

Python

The pivots are 2, 1, and 2. Their product is 4, which is the determinant of A.

Quiz

This quiz has 5 questions on this topic. A question asks you either to choose one answer or to type numbers. The page grades your answers and explains each one. A number can be typed as a whole number, a decimal, a fraction such as 1/3, or a calculation such as sqrt(18)/2 or arccos(1/2). The page shows the value of a calculation next to the box. Angles in a calculation are in degrees. The Calculator button under each question opens a calculator. Your answers are saved in your browser, so they are still on the page when you come back to it.

Choose how your answers are checked

1. The elimination of A = 2347 uses one operation, R₂ → R₂ − mR₁. Find the multiplier m.

2. For the same matrix A = 2347, find the second row of U.

3. The elimination of a 3 by 3 matrix uses the operations R₂ → R₂ − 3R₁, R₃ → R₃ + 2R₁, and R₃ → R₃ − 4R₂, with no row exchanges. Which matrix is L?

4. Solve Ly = b by forward substitution, with L = 1021 and b = (3, 10).

5. A matrix A is factored as A = LU with no row exchanges. The pivots are 2, 5, and −1. Find det A.

Next: Topic 4.1, Vector Spaces and Subspaces