% Example taken from Chapter 4 of N. Trefethen's book 
% "Approximation Theory and Approximation Practice" (SIAM, 2013)

close all, clear all

x = chebfun('x');
n = 4; X = chebpts(n+1); 

fprintf('Chebyshev grid had %d points. \n',n+1)
for k = 1:10, 
  T{k} = chebpoly(k); 
end

disp('Compare T3 and T5 ...')
disp([T{3}(X) T{5}(X)])
figure(1), hold on;
plot(x,T{3}), plot(x,T{5}), plot(X,T{5}(X),'or')

disp('Compare T1, T7 and T9 ...')
disp([T{1}(X) T{7}(X) T{9}(X)])
figure(2), hold on;
plot(x,T{1}), plot(x,T{7}), plot(x,T{9}), plot(X,T{9}(X),'or')
