Example 5.  Use  PA = LU  factorization with pivoting to solve the linear system  [Graphics:Images/LUFactorMod_gr_141.gif].  

Solution 5.

Remark.  The  LU  factorization part does not depend on  B.  To emphasize this, we only enter the matrix  A  at this time.

 

 

[Graphics:../Images/LUFactorMod_gr_142.gif]

Execute the  LUfactor  subroutine.  Note that the dimension of the system must be used, in this case n = 3.

[Graphics:../Images/LUFactorMod_gr_143.gif]

Now print out the matrices  L,  U,  L.U,  L.U and  P.A.  (Remember we stored a copy of  A  in A0).

[Graphics:../Images/LUFactorMod_gr_144.gif]




[Graphics:../Images/LUFactorMod_gr_145.gif]

[Graphics:../Images/LUFactorMod_gr_146.gif]

[Graphics:../Images/LUFactorMod_gr_147.gif]
[Graphics:../Images/LUFactorMod_gr_148.gif]
[Graphics:../Images/LUFactorMod_gr_149.gif]
[Graphics:../Images/LUFactorMod_gr_150.gif]
[Graphics:../Images/LUFactorMod_gr_151.gif]

[Graphics:../Images/LUFactorMod_gr_152.gif]

Now enter the matrix  B.  

 

[Graphics:../Images/LUFactorMod_gr_153.gif]

Solve the system  AX = B for  X.

[Graphics:../Images/LUFactorMod_gr_154.gif]




[Graphics:../Images/LUFactorMod_gr_155.gif]

[Graphics:../Images/LUFactorMod_gr_156.gif]

[Graphics:../Images/LUFactorMod_gr_157.gif]
[Graphics:../Images/LUFactorMod_gr_158.gif]
[Graphics:../Images/LUFactorMod_gr_159.gif]

[Graphics:../Images/LUFactorMod_gr_160.gif]

We are done.

Aside.  For curiosity, we can check to see the "in between" steps that were made in the solution.  First, we solved  [Graphics:../Images/LUFactorMod_gr_161.gif]  for  [Graphics:../Images/LUFactorMod_gr_162.gif]  using forward substitution.  This is just for fun

[Graphics:../Images/LUFactorMod_gr_163.gif]




[Graphics:../Images/LUFactorMod_gr_164.gif]

[Graphics:../Images/LUFactorMod_gr_165.gif]

[Graphics:../Images/LUFactorMod_gr_166.gif]

[Graphics:../Images/LUFactorMod_gr_167.gif]

[Graphics:../Images/LUFactorMod_gr_168.gif]

Second, we solved [Graphics:../Images/LUFactorMod_gr_169.gif]  for  [Graphics:../Images/LUFactorMod_gr_170.gif]  using back substitution.

[Graphics:../Images/LUFactorMod_gr_171.gif]




[Graphics:../Images/LUFactorMod_gr_172.gif]

[Graphics:../Images/LUFactorMod_gr_173.gif]

[Graphics:../Images/LUFactorMod_gr_174.gif]

[Graphics:../Images/LUFactorMod_gr_175.gif]

Finally, we can verify that the residual is  zero, i. e. use matrix multiplication to see if    AX - B  =  0.

[Graphics:../Images/LUFactorMod_gr_176.gif]



[Graphics:../Images/LUFactorMod_gr_177.gif]

[Graphics:../Images/LUFactorMod_gr_178.gif]

[Graphics:../Images/LUFactorMod_gr_179.gif]

Aside.  Suppose a new linear system  AX = B  is to be solved, where  A  is the same we used above, but  B  is a new vector.
Then we enter  B  and only invoke the  SolveLU  subroutine.

[Graphics:../Images/LUFactorMod_gr_180.gif]

Solve the new system  AX = B for  X.

[Graphics:../Images/LUFactorMod_gr_181.gif]




[Graphics:../Images/LUFactorMod_gr_182.gif]

[Graphics:../Images/LUFactorMod_gr_183.gif]

[Graphics:../Images/LUFactorMod_gr_184.gif]
[Graphics:../Images/LUFactorMod_gr_185.gif]
[Graphics:../Images/LUFactorMod_gr_186.gif]

[Graphics:../Images/LUFactorMod_gr_187.gif]

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

(c) John H. Mathews 2004