function [x,k]=SOR(A,b,w) 
% Resolución de Ax=b por SOR
%
 n=size(A,1); x=ones(n,1); sm=1; k=0;
 if nargin<3, w=1.25; end
 while sm>=0.0001
    k=k+1; sm=0;
    for i=1:n
       j = [1:i-1  i+1:n];
       su=b(i)-A(i,j)*x(j);
       xi=(1-w)*x(i)+w*su/A(i,i);
       sm=max(abs(x(i)-xi),sm);
       x(i)=xi;
    end
    sm=sm/max(abs(x));
 end
end