$L$ $U$ Decomposition Not Working (not Sure what I'm doing wrong: Matlab)

170 Views Asked by At

enter image description here

I'm given this question 14a. The question gives me the pseudocode and I'm supposed to code it up on the algorithm or procedure in Matlab. I use this matrix for my A in my Matlab code: enter image description here

I run my Matlab code but yet I keep getting incorrect results. My L*U ends up not being equal to A. I'm really confused as I follow the pseudocode pretty much exactly.

Here's my Matlab code:

A=[1 4 0 0; 3 4 1 0; 0 2 3 4; 0 0 1 3];

$n=4$;

$L=zeros(n,n)$;

$U=zeros(n,n)$;

$L(1,1)=A(1,1)$;

for $i=2:4$

$L(i,i-1)=A(i,i-1)$;

$U(i-1,i)=A(i-1,i)/L(i-1,i-1)$;

$L(i,i)=A(i,i)-(L(i,i-1)*U(i-1,i))$; end

$Z=L*U$;

If someone could help me debug my code, I would really appreciate it as my L*U (which I store as Z) ends up not being equal to A and I have no idea what I'm doing wrong).

1

There are 1 best solutions below

3
On BEST ANSWER

ReplaceU=zeros(n,n); by U=eye(n);

$U$ is an upper bidiagonal matrix, we know that the diagonal entries are $1$.