function T = cheby(x,p)
%CHEBT Chebyshev polynomials.
% T = CHEBT(X,P) evaluates the first P Chebyshev polynomials
% at the vector X. The K'th column of T contains the
% Chebyshev polynomial of degree K-1 evaluated at X.
T = ones(length(x),p);
x = x(:); % Ensure x is a column vector.
if p == 1, return, end
T(:,2) = x;
for k = 3:p
T(:,k) = 2*x.*T(:,k-1) - T(:,k-2);
end