LUDEMO

AUXs

CheckLUMinors0[A_]:=And@@Table[Minors[A,i][[1,1]]≠0,{i,Dimensions[A][[1]]}]

CheckLUMinors[A_]:=And@@Table[Det[Take[A,i,i]]≠0,{i,Dimensions[A][[1]]}]

Clear[CreateLUMatrix]

CreateLUMatrix[n_]:=Module[{l=True,T},While[l,T=Table[Random[Integer,{0,10}],{n},{n}];If[CheckLUMinors[T]∧LUDecomposition[T][[2]]==Range[n],l=False]];T]

Clear[TM]

TM[A_,n_]:=Module[{II=IdentityMatrix[Dimensions[A][[1]]]},ReplacePart[II,Table[Rule[{j,n},-A[[j,n]]/A[[n,n]]],{j,n+1,Dimensions[A][[1]]}]]];

Clear[TSteps]

TSteps[ML_,n_]/;n==S:=ML;

TSteps[ML_,n_]:=Module[{A},If[n>S,S++;A=Dot@@Last[ML];Append[ML,{TM[A,n],A}],S--;Drop[ML,-1]]]

SM[ML_]:={MatrixForm[ML[[1]]],MatrixForm[ML[[2]]]};

Init[n_]:=Module[{M=CreateLUMatrix[n]},{{TM[M,1],M}}]

S=1;

Main

Manipulate[Row[SM[Last[MatrixList=TSteps[MatrixList,s]]]],Style["LUDEMO—2009",Red,16],Button[Init,s=1;S=1;MatrixList=Init[n]],{{n,3},2,4,1},{s,1,n,1},Initialization:>(MatrixList=Init[3])]

Exercises

1 Compare U with LUDecomposition[[1]]//MatrixForm
2 Compare (Ln...L1)^(-1).U with A
3 Explain the Demo
4 Extend it with ...

LUDecomposition[(({{1, 0, 7}, {1, 4, 5}, {3, 9, 0}}))][[1]]//MatrixForm

LUDecomposition[(({{3, 1, 1}, {4, 8, 2}, {10, 10, 1}}))][[1]]//MatrixForm