function [x,ni]=relax(a,b,x0,omega,n_iter,pres)
% function [x,ni]=relax(A,b,x0,omega,n_iter,pres)
% Relaxacni iteracni metoda pro reseni soustavy Ax=b

n=length(x0);
xn=x0;
xo=xn+1;
if nargin<5 n_iter=100; end
if nargin<6 pres=0.001; end
ii=0;
while norm(xo-xn)>pres & ii<n_iter
ii=ii+1;
xo=xn;
 for k=1:n
  xx=b(k);
  for l=1:k-1
    xx=xx-a(k,l)*xn(l);
  end
  for l=k+1:n
    xx=xx-a(k,l)*xo(l);
  end
  xn(k)=(1-omega)*xo(k)+omega*xx/a(k,k);
 end
end
ni=ii;
x=xn;
