function ShowCheby(a,b,n)
% How does the maximum value of
%
% psi(z) = (z - x(1))*(z - x(2))*...*(z - x(n))
%
% on the interval [a,b] depend on the placement of the x(i)?
%
% We assume that
% a <= x(1) < x(2) <...< x(n) <= b.

close all
% We look at two choices: Equal spacing and Chebychev spacing.

% For plotting, we will evaluate psi(.) at these points...
z = linspace(a,b)';

% Equal spacing...
x = linspace(a,b,n)';
% Evaluate psi...
phi = ones(100,1);
for k=1:n
phi = phi.*(z - x(k));
end
plot(z,phi)
mEqual = max(abs(phi));

% Chebychev spacing
x = (a+b)/2 + ((b-a)/2)*cos((2*(1:n)'-1)*pi/(2*n));
% Evaluate psi...
phi = ones(100,1);
for k=1:n
phi = phi.*(z - x(k));
end
hold on
plot(z,phi,'r')
hold off
set(gca,'fontsize',14)
mCheby = max(abs(phi))
% mCheby Cool result: mCheby equals 2*((b-a)/4)^n
title(sprintf('n = %2d mEqual = %10.2e mCheby = %10.2e',n,mEqual,mCheby),'fontsize',14)
xlabel('z','fontsize',14)
ylabel('psi(z)','fontsize',14)
v = axis; axis([v(1) v(2) -max(abs(v(3:4))) max(abs(v(3:4)))])
mpredict = ((b-a)/2)^n/2^(n-1)