from
ChebyshevTools
by Michael Watson Tool box for solving ODE/PDEs using spectral Chebyshev differentiation matrices.
y=phys2cheb(f);
function y=phys2cheb(f);
% Written by Mike Watson, November 29
% takes a real vector from physical space f defined on a grid [-1,1] and
% outputs it's normalized Chebyshev spectral coefficients y
N=length(f)-1;
f_even=[f;flipud(f(2:N))]; % create an even extension of f;
F=real(fft(f_even)); %perform a discrete cosine transform (DCT);
if N > 1
y=(1/N).*F(1:N+1);
y(1)=y(1)/2;
y(N+1)=y(N+1)/2;
else
y=f;
end