function x = fxd(L,b)
b=b(:)
[m,n]=size(L);
p=length(b);
if m~=n
    error('L nu este pătratică!');
end
if m~=p
    error('L nu este compatibil cu b')
end
for  i=1:m
    for j=i+1:n
        if L(i,j)~=0
            error('Matricea nu este inferior triunghiulara')
        end
    end
end
for i=1:n
    if L(i,i)==0
        error('L este singulară')
    end
end
x(1) = b(1)/L(1,1);
for i=2:n
    sum=0
    for j=1:i-1
    sum=sum+L(i,j)*x(j);
end
x(i)=(b(i)-sum)/L(i,i);
end
end
 
 
 
 
 
 
 
 
 
 
 
function x = bwd(U,b)
 
[m,n]=size(U);
b=b(:)
p=length(b);
if m~=n
    error('U nu este pătratică!');
end
if m~=p
    error('U nu este compatibil cu b');
end
 
for  i=1:m
    for j=1:i-1
        if U(i,j)~=0
            error('Matricea U nu este superior triunghiulara');
        end
    end
end
 
if det(U)==0
    error('Matricea U nu este inversabilă');
end
 
x(n) = b(n)/U(n,n);
for i=n-1:-1:1
    sum=0
    for j=i+1:n
    sum=sum+U(i,j)*x(j);
end
x(i)=(b(i)-sum)/U(i,i);
 
 
end
end











function [L,b] = gem(L,b)
[m,n]=size(L)
b=b(:);
p=length(b);
if m~=n
	error('L nu e patratica')
end
if m~=p
	error('L nu e compatibil cu b')
end
for k=1:n-1
	for i=k+1:n
		m(1,k)=L(i,k)/L(k,k);
		b(i)=b(i)-m(i,k)*b(k);
		for j=1:n
			L(i,j)=L(i,j)-m(i,k)*L(k,j);
		end
	end
end
end
