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
ZnVuY3Rpb24geCA9IGZ4ZChMLGIpCmI9Yig6KQpbbSxuXT1zaXplKEwpOwpwPWxlbmd0aChiKTsKaWYgbX49bgogICAgZXJyb3IoJ0wgbnUgZXN0ZSBwxIN0cmF0aWPEgyEnKTsKZW5kCmlmIG1+PXAKICAgIGVycm9yKCdMIG51IGVzdGUgY29tcGF0aWJpbCBjdSBiJykKZW5kCmZvciAgaT0xOm0KICAgIGZvciBqPWkrMTpuCiAgICAgICAgaWYgTChpLGopfj0wCiAgICAgICAgICAgIGVycm9yKCdNYXRyaWNlYSBudSBlc3RlIGluZmVyaW9yIHRyaXVuZ2hpdWxhcmEnKQogICAgIC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