function [U] = chevpolyu(p)
%
% This function returns the second kind of Chevyshev polynomial coefficients in the order of X^0 X^1 X^2 ... X^p
% U is a matrix, p is the polynomial order.
% This function is used in chebkernel.m file.
%
%written by Sedat OZER
%
%Output matrix U is coefficient matrix where each row is the coefficient of
% related row number polynomial. For example first row is U(1) polynomial
% coeffients, second row is U(2) coefficients and so on...
% U(0)=1,    U(1)=2x and   U(p)=2*U(p-1)-U(p-2)
%
%
% The code is not optimized for Matlab. Use as is.
%
% Thank you
%

coef=zeros(1,p+1);
T=zeros(p+1,p+1);
if p==0
    coef(1)=1;
elseif p==1
    coef(2)=1;
else
    coef(1)=1;
    T(1,:)=coef;
    coef(1)=0;coef(2)=2;
    T(2,:)=coef;
    
    for i=3:p+1
       k=2*T(i-1,:);
       y=zeros(1,p+1);
       for j=0:p-1
           y(p+1-j)=k(p-j);
       end     
       T(i,:)=y-T(i-2,:);       
    end
end
    
U=T;

%%--------------------------------------


















