a=0; b=2*pi; 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:6
    h=(b-a)/N; 
    x=a:h:b;
    y=myfun_sp(x);
    s=a:(h/10):b;
    
    switch int_type
    case 1 % LINEARE.
        t=interp1(x,y,s,'linear');
        err=norm(t-myfun_sp(s),inf);
        fprintf('\n [N]: %2.0f [ERR. (INF)] %2.2e',N, err);
    case 2 % CUBICA NATURALE.
        pp=csape(x,y,'variational');
        t = fnval(pp,s);
        err=norm(t-myfun_sp(s),inf);
        fprintf('\n [N]: %2.0f [ERR. (INF)] %2.2e',N,err);
    case 3 % CUBICA NOT A KNOT.
        t=spline(x,y,s);
        err=norm(t-myfun_sp(s),inf);
        fprintf('\n [N]: %2.0f [ERR. (INF)] %2.2e',N,err);
    end
    
    plot(s,myfun_sp(s),'k-'); hold on;
    plot(s,t,'r-'); 
    plot(x,y,'o');
    
    
    pause(2);
    hold off;
end
