clear

%%
x = linspace(-1, 1, 1601)';
Phi = zeros(size(x));
for n = 10:10:50
    theta = linspace(0, pi, n+1)';
    t = -cos(theta);                    
    for k = 1:length(x)
        Phi(k) = prod(x(k)-t);
    end
    semilogy(x, abs(Phi))
    hold on
end
axis tight
title('Effect of Chebyshev nodes')
xlabel('x')
ylabel('|\Phi(x)|')
ylim([1e-18 1e-2])
grid on
legend('n=10', 'n=20', 'n=30', 'n=40', 'n=50', 'location', 'best')

%%
% The convergence is a bit slower in the middle than with equally spaced
% points, but far more uniform over the entire interval, which is the key
% to global convergence.