Example 4. Use PA = LU factorization with pivoting to solve the linear system AX = B, where
and
.
Solution 4.
Remark. The LU factorization
part does not depend on B. To emphasize
this, we only enter the matrix A at this
time.
Execute
the LUfactor subroutine. Note
that the dimension of the system must be used, in this case n =
3.
Now print out the matrices L, U, L.U, L.U and P.A. (Remember we stored a copy of A in A0).
Now enter the matrix B.
Solve the system AX = B for X.
We are done.
Aside. For curiosity,
we can check to see the "in between" steps that were made in the
solution. First, we solved
for
using
forward substitution. This is just for fun
Second, we solved
for
using
back substitution.
Finally, we can verify that the residual is zero, i. e. use matrix multiplication to see if AX - B = 0.
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.
Solve the new system AX = B for X.
(c) John H. Mathews 2003