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

Solution 4.

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_95.gif]

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

[Graphics:../Images/LUFactorMod_gr_96.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_97.gif]




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

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

[Graphics:../Images/LUFactorMod_gr_100.gif]
[Graphics:../Images/LUFactorMod_gr_101.gif]
[Graphics:../Images/LUFactorMod_gr_102.gif]
[Graphics:../Images/LUFactorMod_gr_103.gif]
[Graphics:../Images/LUFactorMod_gr_104.gif]

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


Now enter the matrix  B.  

 

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

Solve the system  AX = B for  X.

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




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

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

[Graphics:../Images/LUFactorMod_gr_110.gif]
[Graphics:../Images/LUFactorMod_gr_111.gif]
[Graphics:../Images/LUFactorMod_gr_112.gif]

[Graphics:../Images/LUFactorMod_gr_113.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_114.gif]  for  [Graphics:../Images/LUFactorMod_gr_115.gif]  using forward substitution.  This is just for fun

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




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

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

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

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

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

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

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




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

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

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

[Graphics:../Images/LUFactorMod_gr_128.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_129.gif]



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

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

[Graphics:../Images/LUFactorMod_gr_132.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_133.gif]

Solve the new system  AX = B for  X.

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



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

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

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

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

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

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

(c) John H. Mathews 2004