function retval = chebypolys(n)
% usage: poly = chebypoly(n)
% description:  given input degree n, returns
% returns (n+1)x(n+1) matrix whose jth row
% is the vector of coefficients for T_{k+j-1}
% in poly format: highest degree to lowest.

if (n == 0)
  retval = [1];
elseif (n == 1)
  retval = [0 1;1 0];
else
  % initialize first two rows of array
  retval = zeros(n+1,n+1);
  retval(1,n+1) = 1;
  retval(2,n) = 1;  
  % implement recursion formula T_{j+1} = 2*x*T_{j} - T_{j-1}
  for j = 3:(n+1)
    retval(j,:) = 2*[retval(j-1,2:(n+1)),0] - retval(j-2,:);
  end
end
