LU Decomposition¶
Every sqaure matrix $A$ can be written as a product of $PLU$ where $P$ is a permutation matrix and $L$ is a lower triangluar matrix with $1$'s on its diagonal and $U$ is an upper triangular matrix.
%display latex
A = matrix(QQ,[[-3,-1,-2],[-1,5,-2],[1,-1,0]]); A
P,L,U = A.LU() #First we show that sage can compute the LU decomposition.
P, L, U
P*L*U #this checks that PLU = A
So how are we going to find this decomposition? And what is it good for?
First we tag the identity to the right of $A$ just like the first step for finding inverse using row reduction.
I3 = identity_matrix(3)
M = block_matrix([A,I3], ncols =2)
M
Next we turn the left-half to an upper triangluar matrix using only the 3rd type of ERO.
M.add_multiple_of_row(1,0,-1/3); M
M.add_multiple_of_row(2,0,1/3); M
R=M.with_added_multiple_of_row(2,1,1/4);
R
Now the left-half is an upper triangular matrix. And since we used only the 3rd type of ERO, the right-side is now a lower triangular matrix with 1 on its diagonal.
U = R.submatrix(0,0,ncols=3); U #U is the left-half of R.
The right-half $R$ is not the $L$ we want to find but the inverse of that $L$.
Linv=R.submatrix(0,3); Linv #this is L^{-1}
So $L$ is the inverse of the matrix above.
L = Linv.inverse(); L
L*U==A #check that $A = LU$.
L*U