You are on page 1of 1

function [nbr_eteration,x]=methode_gauss_seidel(A,b,x0,esp)

n=length(b);
for k=1:1000

for i=1:n
s1=0.0;
s2=0.0;
if (i~=1)
for j=1:i-1
s1=s1+A(i,j)*x1(j);
end
end
for j=i+1:n
s2=s2+A(i,j)*x0(j);
end
x1(i)=(b(i)-s1-s2)/A(i,i);
end
if norm(x1-x0)<esp
break
else
x0=x1;
end
end
x=x1;
nbr_eteration=k;

You might also like