Vous êtes sur la page 1sur 1

METODA LUI GAUSS

clc;
disp ('Introduceti matricea sistemului');
a=input('A=')
disp ('Introduceti coloana termenilor liberi');
b=input('b=')
A=a;B=b;c=a;
[n,n]=size(a);
for p=1:n-1
for i=p+1:n
for j=p:n
a(i,j)=A(i,j)-A(i,p)*A(p,j)/A(p,p);
end
b(i)=B(i)-A(i,p)*B(p)/A(p,p);
end
A=a;B=b;
end
x=zeros(n,1);
x(n)=b(n)/a(n,n);
for i=n-1:-1:1
S=0;
for j=i+1:n
S=S+a(i,j)*x(j);
end
x(i)=(b(i)-S)/a(i,i);
end
disp ('Solutia sistemului este:');
x