function ShowChebychevPoly()
% Displays te hforst 20 Chebychev polynomials
x = linspace(-1.2,1.2)';
Y = ChebyPoly(x,20);
plot([-1.2,1.2],[0,0],'-k',[-1.2,1.2],[-1,-1],'-r',[-1.2,1.2],[1,1],'-r',...
[-1,-1],[-.03,.03],'k',[1,1],[-.03,.03],'k')
axis([-1.2 1.2 -1.2 1.2])
hold on
for k=1:20
h = plot(x,Y(:,k+1));
h1 = title(sprintf('The Chebychev polynomial of degree %1d',k),'fontsize',14);
shg
pause(1)
delete(h,h1)
end

function Y = ChebyPoly(x,n)
% x is a column m-vector and n>=1
% Y(:,k+1) is the value of the degree-k Chebychev polynomial at x,k=0:n
Y = zeros(length(x),n+1);
Y(:,1) = 1;
Y(:,2) = x;
for k=2:n
Y(:,k+1) = 2*x.*Y(:,k) - Y(:,k-1);
end