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 systems with the same matrix: eliminating from scratch each time, or factoring once and reusing the factors.
- Raise . The gap grows with : the saving per solve is roughly times.
- The readout gives the speedup at the right edge of the graph.
Predict
Factoring a 1000 × 1000 matrix takes about operations. About how much does each later solve with the factors cost?
About . Forward and back substitution each touch every entry of a triangular matrix once, about each. That's times cheaper than factoring. For a matrix that stays fixed, almost all the work is done once.
Name it
Elimination is a factorization
Gaussian elimination subtracts multiples of rows to make the matrix upper triangular, . Record each multiplier (the multiple of row subtracted from row ) in a lower triangular matrix with ones on its diagonal. Then
For a 2 × 2 matrix, , and
The diagonal entries of are the pivots.
Solving with the factors
To solve , write it as and do two easy triangular solves:
- Forward substitution: solve from the top down.
- Back substitution: solve from the bottom up.
Cost
| Step | Operations (multiply-adds) |
|---|---|
| Factor | about |
| Forward plus back substitution | about |
So factor once, and solve as many right-hand sides as you like for 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 , with a permutation matrix that records the swaps. NumPy's solver does this for you.
Worked example
Factor .
Show the solution
- Multiplier.
- Eliminate. Subtracting 3 times row 1 from row 2 gives
- Write the factors.
- Check. has second row
Answer and .
Worked example
Use those factors to solve .
Show the solution
- Forward substitution.
- Back substitution.
- Check in the original.
Answer and .
Worked example
Factor into .
Show the solution
- First column. Subtract 2 × row 1 from row 2 and 4 × row 1 from row 3: the rows become and .
- Second column. Subtract 3 × the new row 2 from row 3, leaving .
- Collect the factors. The multipliers 2, 4 and 3 fill :
- Pivots and determinant. The pivots are 2, 1 and 2, and their product is .
Answer holds the multipliers 2, 4 and 3 below a diagonal of ones, and has rows , and .
Check
Eliminating below the first pivot of , what multiplier goes into ?
Check
What is the second pivot, , of ?
Check
With , forward substitution solves . What is ?
Check
For an matrix with = 1000, about how many times more work is factoring () than one forward and back solve ()?
Check
Elimination on 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)
What is the multiplier ?
(b)
What is the second pivot ?
Check
Factor .
Step 1
What is ?
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°.
Step 2
What is the second pivot?
Step 3
Multiply the pivots. What is the determinant?
Explain why
A circuit simulator solves at every time step with the same . Why does it factor once instead of solving from scratch each step?
Elimination's expensive part, about operations, depends only on the matrix , not on the right-hand side. Factoring stores the result of that work. Each new right-hand side then needs only forward and back substitution through the two triangular factors, about operations, which is times cheaper. Over thousands of time steps, factoring once saves almost all the work.
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.