1

i did an exercise with LU decomposition in Matlab, my professor highlighted some problems, but i don't understand what i should correct.

This is for the lower triangular matrix:

function b = triI(A,b)
   n = length(A);
   for i=1:n
     for j=1:i-1
       b(i) = b(i) - A(i,j)*b(j);
     end
   if A(i,i) == 0
       error(’the matrix is singular’)
   end
   b(i) = b(i)/A(i,i);
end

This is for the lower triangular matrix:

 function b = triS(A,b)
   n = length(A);
   for i=n:-1:1
     for j=i+1:n
       b(i) = b(i) - A(i,j)*b(j);
     end
   if A(i,i) == 0
       error(’the matrix is singular’)
   end
   b(i) = b(i)/A(i,i);
end

LU decomposition

function x = solveLU(A,x)
 n = lenght(A);
 M = tril(A,-1)+eye(n);
 x = solvetril(M,x);
 M = triu(A);
 x = solvetriu(M,x);

How can i resolve this? He said that it isn't a correct algorithm... Thanks in advance!

Pring
  • 31
  • 6
  • 1
    What are the problems that your professor highlighted? – yoh.lej Feb 05 '15 at 11:41
  • He didn't say nothing... He has only highlighted all the exercise on the LU decomposition... :( – Pring Feb 05 '15 at 11:49
  • 1
    Unfortunately you aren't performing the LU decomposition properly. All you're doing is splitting up the matrix `A` into upper and lower triangular. LU has an additional property where when you multiply `L` and `U` together, you should get `A`. Indeed that `L` and `U` are lower and upper triangular matrices, but you must make sure that `LU = A`. What you are doing in your `solveLU` code is not the case. You've got the **general algorithm** to solve for a system using `LU` correct, but not the actual decomposition itself. – rayryeng Feb 05 '15 at 16:06
  • Thank you very much, how can i resolve this problem? – Pring Feb 06 '15 at 09:57

0 Answers0