function [x]=gauss_seidel(A,b,x0,N)
n=length(b);
x=x0;
for k=1:N,
    for i=1:n,
        s=b(i);
        for j=1:i-1
            s=s-A(i,j)*x(j);
        end;
        for j=i+1:n
            s=s-A(i,j)*x(j);
        end;
        x(i)=s/A(i,i);
    end;
end;
