
function [eequi,echeb]=esercizio2

esempio=1;
d = [-1, 1]; % INTERVALLO.

switch esempio
    case 1
        ff = @(x) 1./(1+25*x.^2); % FZ. RUNGE
    case 2
        ff = @(x) abs(x-0.3); % FZ. CONTINUA
    case 3
        ff = @(x) exp(x.^2); % FZ. ANALITICA
    case 4
        ff = @(x) exp(x); % FZ. ANALITICA
    case 5
        ff = @(x) sin(x); % FZ. ANALITICA
    case 6
        ff = @(x) sinc(x); % FZ. sinc
end
f=chebfun(ff,d,'splitting','on');
eequi=[];
echeb=[];
nn=1:1:100;
for n=nn
    x = linspace(d(1), d(2), n+1);
    p = chebfun.interp1(x, ff(x));
    fc = chebfun(ff, n+1);
    eequi=[eequi norm(f-p,inf)];
    echeb=[echeb norm(f-fc,inf)];
end

clf;
semilogy(nn,eequi,'r-');
pause;
semilogy(nn,echeb,'r-');
