Lesson 5 of 15
LU Decomposition
LU Decomposition
Every square matrix (with non-zero pivots) can be factored as where:
- is lower triangular with 1s on the diagonal
- is upper triangular
This is Gaussian elimination written as a matrix product.
Algorithm
For each pivot column , eliminate below the diagonal by subtracting scaled rows:
The multipliers become the entries of .
Example
Why LU?
Once , solving costs — just two triangular solves — instead of rerunning Gaussian elimination for each new .
Your Task
Implement lu_decompose(A) returning (L, U). Modify a copy of A in-place for U while recording multipliers in L.
Python runtime loading...
Loading...
Click "Run" to execute your code.