
function esercizio1

% settings
A=gallery('minij',20);
n=size(A,1);
b=ones(n,1);

% Jacobi
tol=10^(-6);
max_it=2000;
x0=zeros(n,1);
[x, error, iter, flag]  = jacobi(A, x0, b, max_it, tol);

if flag == 1
    fprintf('\n \t Jacobi non converge');
else
    fprintf('\n \t Jacobi converge in %5.0f iterazioni',iter);
end

% SOR
wv=0.01:0.01:1.99;
iterv=[];

for w=wv
    [xw, errorw, iterw, flagw]  = sor(A, x0, b, w, max_it, tol);
    if flagw == 1
        iterw=realmax;
    end
    iterv=[iterv iterw];
end

[itermin,imin]=min(iterv);
wmin=wv(imin);

plot(wv,iterv);

fprintf('\n \t w minimo iterazioni : %1.5f',wmin);
fprintf('\n \t # minimo iterazioni : %5.0f \n \n',itermin);



