a=1; b=2; int_type=1;

switch int_type
case 1
    fprintf('\n \t [SPLINE LINEARE] \n');
case 2
    fprintf('\n \t [SPLINE CUBICA NATURALE] \n');
case 3
    fprintf('\n \t [SPLINE CUBICA NOT A KNOT] \n');
end

for N=3:10
    h=(b-a)/N; 
    x=a:h:b;
    y=log(x);
    s=a:(h/10):b;
    
    switch int_type
    case 1 % LINEARE.
        t=interp1(x,y,s,'linear');
        err(N)=norm(t-log(s),inf);
        err_ext_min=(2/(b^2))*(h^2)/8;
        err_ext_max=(2/(a^2))*(h^2)/8;
        fprintf('\n [N]: %2.0f [ERR. (INF)] %2.2e',N, err(N));
        fprintf(' [EST.][MIN]: %2.2e [MAX]: %2.2e',err_ext_min,err_ext_max);
        if (err(N) > err_ext_min) & (err(N) < err_ext_max)
          fprintf(' [OK]'); 
      else
          fprintf(' [KO]'); 
        end
    case 2 % CUBICA NATURALE.
        pp=csape(x,y,'variational');
        t = ppval(pp,s);
        err(N)=norm(t-log(s),inf);
        fprintf('\n [N]: %2.0f [ERR. (INF)] %2.2e',N,err(N));
    case 3 % CUBICA NOT A KNOT.
        t=spline(x,y,s);
        err(N)=norm(t-log(s),inf);
        fprintf('\n [N]: %2.0f [ERR. (INF)] %2.2e',N,err(N));
    end
    
    plot(s,log(s),'k-'); hold on;
    plot(s,t,'r-'); 
    
    
    pause(2);
    hold off;
end
