A79 of 56
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

A7 · Lesson 9 · LU factorization

Do the elimination once, reuse it forever

A circuit simulator stepping through a transient solves the same matrix equation thousands of times: the circuit's matrix stays fixed and only the right-hand side changes as the sources move. Doing full elimination at every step would waste almost all the work, because elimination's expensive part depends only on the matrix. LU factorization records that work once, as two triangular matrices, so each new right-hand side costs only a quick forward and backward sweep. SPICE does exactly this.

  • The curves compare total work for solving k systems with the same n×n matrix: eliminating from scratch each time, or factoring once and reusing the factors.
  • Raise n. The gap grows with n: the saving per solve is roughly n/3 times.
  • The readout gives the speedup at the right edge of the graph.

Predict

Factoring a 1000 × 1000 matrix takes about n3/3≈3×108 operations. About how much does each later solve with the factors cost?

Name it

Elimination is a factorization

Gaussian elimination subtracts multiples of rows to make the matrix upper triangular, U. Record each multiplier ℓij (the multiple of row j subtracted from row i) in a lower triangular matrix L with ones on its diagonal. Then

A=LU

For a 2 × 2 matrix, ℓ21=a21a11, and

[abcd]=[10c/a1][ab0d−cab]

The diagonal entries of U are the pivots.

Solving with the factors

To solve A𝐱=𝐛, write it as L(U𝐱)=𝐛 and do two easy triangular solves:

  1. Forward substitution: solve L𝐜=𝐛 from the top down.
  2. Back substitution: solve U𝐱=𝐜 from the bottom up.

Cost

StepOperations (multiply-adds)
Factor A=LUabout n33
Forward plus back substitutionabout n2

So factor once, and solve as many right-hand sides as you like for n2 each.

Pivoting

If a pivot is zero, elimination can't divide by it, so you swap in a lower row first. In practice you always swap up the row with the largest entry in the column (partial pivoting), because dividing by a small pivot magnifies rounding errors. The result is PA=LU, with P a permutation matrix that records the swaps. NumPy's solver does this for you.

Worked example

Factor A=[2168].

Show the solution
  1. Multiplier. ℓ21=62=3
  2. Eliminate. Subtracting 3 times row 1 from row 2 gives (0,8−3)=(0,5)
  3. Write the factors. L=[1031]U=[2105]
  4. Check. LU has second row 3(2,1)+(0,5)=(6,8)

Answer L=[1031] and U=[2105].

Worked example

Use those factors to solve A𝐱=(3,19).

Show the solution
  1. Forward substitution. c1=3 3c1+c2=19soc2=10
  2. Back substitution. 5x2=10sox2=2 2x1+x2=3sox1=0.5
  3. Check in the original. 6(0.5)+8(2)=19

Answer x1=0.5 and x2=2.

Worked example

Factor A=[211433879] into LU.

Show the solution
  1. First column. Subtract 2 × row 1 from row 2 and 4 × row 1 from row 3: the rows become (0,1,1) and (0,3,5).
  2. Second column. Subtract 3 × the new row 2 from row 3, leaving (0,0,2).
  3. Collect the factors. The multipliers 2, 4 and 3 fill L: L=[100210431] U=[211011002]
  4. Pivots and determinant. The pivots are 2, 1 and 2, and their product is det⁡A=4.

Answer L holds the multipliers 2, 4 and 3 below a diagonal of ones, and U has rows (2,1,1), (0,1,1) and (0,0,2).

Check

Eliminating below the first pivot of [2165], what multiplier ℓ21 goes into L?

Check

What is the second pivot, u22, of [21−89]?

Check

With L=[1031], forward substitution solves L𝐜=(4,20). What is c2?

Check

For an n×n matrix with n = 1000, about how many times more work is factoring (n33) than one forward and back solve (n2)?

Check

Elimination on [0123] stops at once. What's the fix?

Check

Write lu(A) returning (L, U) for a square NumPy array, using elimination without row swaps: L unit lower triangular with the multipliers, U upper triangular, L @ U == A.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Factor A=[2179]=LU.

(a)

What is the multiplier ℓ21?

(b)

What is the second pivot u22?

Check

Factor [x1y2].

Step 1

What is ℓ21?

Type it the way you would write it, like 3sin(2πft) or 3*sin(2*pi*f*t). Angles can be in radians or carry a degree sign, like 45°.

Explain why

A circuit simulator solves A𝐱=𝐛 at every time step with the same A. Why does it factor A once instead of solving from scratch each step?

Practice

Keep practicing

8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.