
%
% Calcolo Numerico 1 -  20 giugno 2013 - MILANO ESERCIZIO 1
%
clear all
nn=[20 40 80];
for i=1:length(nn)
    n=nn(i);
    clear a
    a=-eye(n);
    u2=2*ones(n-2,1);
    a=a+diag(u2,2)+diag(u2,-2);
    u4=4*ones(n-1,1);
    a=a+diag(u4,1)+diag(u4,-1);
    n1=norm(a,1);
    [l,u,p]=lu(a);
    rand('seed',931316785)
    r=rand(n,n/2);
    for j=1:n/2
        rpiv=p*r(:,j);
        yy=l\rpiv;
        y=u\yy;
        s(j)=norm(y,1)/norm(r(:,j),1);
    end
    nm1=max(s);
    kA=n1*nm1;
    fprintf('n=%2d \t n(inv(A))=%10.6f \t n(A)=%10.6f \t K(A)=%10.6f \n',n,nm1,n1,kA); 
end
%n=20 	 n(inv(A))=  0.419478 	 n(A)= 13.000000 	 K(A)=  5.453212 
%n=40 	 n(inv(A))=  0.742344 	 n(A)= 13.000000 	 K(A)=  9.650475 
%n=80 	 n(inv(A))=  4.971532 	 n(A)= 13.000000 	 K(A)= 64.629921
 
 