
function esericizio5



% DETERMINA PROBLEMA.
n = 50;
A = diag(4*ones(n,1)) + diag(-2*ones(n-1,1),1) + diag(ones(n-1,1),-1);

sol=ones(n,1);
b=A*sol;
x0=zeros(n,1);
toll=10^(-5);
kmax=100;

wV=linspace(0.9,1.1,3);

ii=1;
while ii <= length(wV)
    w=wV(ii);
    % TROVA SOLUZIONE GAUSS-SEIDEL.
    [x,kSOR,flag] = SOR (A,b,w,x0,toll,kmax);
    
    % CALCOLA ERRORE.
    for j=1:kSOR
        errSOR(j)=norm(x(:,j)-sol);
    end
    
    % ESEGUI GRAFICO ERRORE.
    semilogy(1:kSOR,errSOR,'o-');
    hold on;
    wstr=num2str(w,'%1.1e');
    text(kSOR,errSOR(end),wstr);
    
    ii=ii+1;
    
end

hold off;
