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!