clear all
A=[5 0 0 0;
-2 -4 0 0;
7 2 3 0;
6 8 9 7];
C=[12;8;-4;1]
x=LowerTriangularSolver(A,C)
%Check that you have the right answer by calculating Ax-C=0, which should be
%very close to zero if Ax=C.
A*x-C
function x=LowerTriangularSolver(A,C)
[n,n]=size(A); % Finding the size of the problem
x=zeros(n,1); % set up x vector with elements initially set to zero
x(1)=C(1)/A(1,1);
for i=2:n
sum=0;
for j=1:i-1
sum=sum+A(i,j)*x(j);
end
x(i)=(C(i)-sum)/A(i,i);
end
end