Implement the LU factorization algorithm. Algorithm for LU factorization:
INPUT : Matrix Dimension n, the matrix A and method choice Doolittle or Crout.
OUTPUT : L and U, or the failure message
Step 1: Select l11 and u11 satisfying l11u11 = a11 based on the choice If l11u11 = 0, then output (’factorization impossible’); STOP
Step 2: For j = 2 : n, set
u1j = a1j/l11, lj1 = aj1/u11
Step 3: For i = 2 : n − 1, do Steps 4 and 5
Step 4: Select lii and uii satisfying liiuii = aii − ∑i−1
k=1 likuki based on the choice
If liiuii = 0, then output (’factorization impossible’); STOP
Step 5: For j = i + 1 : n, set
uij =
[ aij −
i−1∑ k=1
likukj
] /lii, lji =
[ aji −
i−1∑ k=1
ljkuki
] /uii
Step 6: Select lnn and unn satisfying lnnunn = ann − ∑n−1
k=1 lnkukn based on the choice
Step 7: Output L and U; STOP
1
Use the algorithm with both methods to factorize
A =
1 1 0 3 2 1 −1 1 3 −1 −1 2 −1 2 3 −1