Chapter 5 - Determinants, Inverses, and Cramer’s Rule

Section 5.4 - LU Factorization

Example 5.4.1

A={{3,4,-2,5},{2,-7,-8,9},{1,4,2,-5},{-2,3,4,-1}};

L=IdentityMatrix[4];

(A1={A[[1]],A[[2]]-(2/3) A[[1]],A[[3]],A[[4]]})//MatrixForm

L[[2,1]]=2/3;

(A2={A1[[1]],A1[[2]],A1[[3]]-(1/3) A1[[1]],A1[[4]]})//MatrixForm

L[[3,1]]=1/3;

(A3={A2[[1]],A2[[2]],A2[[3]],A2[[4]]-(-2/3) A[[1]]})//MatrixForm

L[[4,1]]=-2/3;

(A4={A3[[1]],A3[[2]],A3[[3]]-(-8/29) A3[[2]],A3[[4]]})//MatrixForm

L[[3,2]]=-8/29;

(A5={A4[[1]],A4[[2]],A4[[3]],A4[[4]]-(-17/29) A4[[2]]})//MatrixForm

L[[4,2]]=-17/29;

(A6={A5[[1]],A5[[2]],A5[[3]],A5[[4]]-(-36/24) A5[[3]]})//MatrixForm

L[[4,3]]=-36/24;

L//MatrixForm

L.A6//MatrixForm

X={{(Subscript[x, 1])},{(Subscript[x, 2])},{(Subscript[x, 3])},{(Subscript[x, 4])}};

Y={{(Subscript[y, 1])},{(Subscript[y, 2])},{(Subscript[y, 3])},{(Subscript[y, 4])}};

B={{-1},{2},{-3},{-1}};

L.Y//MatrixForm

Flatten[Ysoln=Y/.Solve[L.Y==B,{(Subscript[y, 1]),(Subscript[y, 2]),(Subscript[y, 3]),(Subscript[y, 4])}][[1]]]

A6.X//MatrixForm

Flatten[Xsoln=X/.Solve[A6.X==Ysoln,{(Subscript[x, 1]),(Subscript[x, 2]),(Subscript[x, 3]),(Subscript[x, 4])}][[1]]]

RowReduce[Join[A,B,2]]//MatrixForm

Example 5.4.1 continued...

({lu,p,c}=LUDecomposition[A])[[1]]//MatrixForm

p

(l=lu SparseArray[{i_,j_}/;j<i-> 1,{4,4}]+IdentityMatrix[4])//MatrixForm

(u=lu SparseArray[{i_,j_}/;j≥i->1,{4,4}])//MatrixForm

l.u//MatrixForm

A[[p]]//MatrixForm