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

x_history = x_his;

