
function esercizio7

% CONFRONTO ITERATE E TEST ARRESTO.

% 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^(-15);
kmax=1000;

% wV=linspace(0.1,1.9,100);
wV=linspace(0.8,1.0,100);

ii=1;

SOR_its=[];

while ii <= length(wV)
    w=wV(ii);
    % TROVA SOLUZIONE GAUSS-SEIDEL.
    format short e
    tollSOR=toll*norm(b);
    [x,kSOR,flag] = SORres (A,b,w,x0,tollSOR,kmax);
    SOR_its(ii)=kSOR; 
    ii=ii+1;
end



ii=1;
SOR_its_old=[];

while ii <= length(wV)
    w=wV(ii);
    % TROVA SOLUZIONE GAUSS-SEIDEL.
    format short e
    tollSOR=toll;
    [x,kSOR,flag] = SOR (A,b,w,x0,tollSOR,kmax);
    SOR_its_old(ii)=kSOR; 
    ii=ii+1;
end

clf;
hold on;
title('SOR test (paragone)')
plot(wV,SOR_its,'r-',wV,SOR_its_old,'b');
legend('SORres,SOR');
hold off;

