Code covered by the BSD License  

Highlights from
Chebpack

image thumbnail

Chebpack

by

 

15 Jul 2011 (Updated )

The MATLAB package Chebpack solves specific problems for differential or integral equations.

t2x.m
function v = t2x(c,kind)
% c: spectral representation of a function
% v: physical representation, i.e. the values at the Chebyshev points
% c is a matrix, each column contains the coefficients of some other function  
%   
%   Inspired by chebpolyval.m from chebfun package
%   Copyright  2011, 
%   The Chancellor, Masters and Scholars of the University of Oxford, 
%   and the Chebfun Developers. All rights reserved.
%   See http://www.maths.ox.ac.uk/chebfun/ for Chebfun information.
%
% Warning! Corrected bugs at lines 13 and 38%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%n=size(c,1);c(1,:)=c(1,:)/2;
[n,m]=size(c);c(1,:)=c(1,:)/2;
if n == 1, v = c; return; end
c=flipud(c);
if nargin == 1 || kind == 2, % 2nd kind Chebyshev points
    ii = 2:n-1;c(ii,:) = c(ii,:)/2;v = [(c(end:-1:1,:)); c(ii,:)];
    if isreal(c)
        v=real(ifft(v));
    elseif isreal(1i*c)
        v=1i*real(ifft(imag(v)));
    else
        v=ifft(v);
    end
    v = (n-1)*[2*v(1,:); (v(ii,:)+v(2*n-ii,:)); 2*v(n,:)];v=flipud(v);   
else % 1st kind
    if isreal(c)
        v = realvals(c);
    elseif isreal(1i*c)
        v = 1i*realvals(imag(c));
    else
        v = realvals(real(c))+1i*realvals(imag(c));
    end
end
function c = realvals(c)
% Real case - Chebyshev points of the 1st kind
%%c = flipud(c);w = n*exp(1i*(0:n-1)*pi/(2*n)).';c = w.*c;vv=real(ifft(c));
c = flipud(c);w = n*exp(1i*(0:n-1)*pi/(2*n)).';c = repmat(w,[1,m]).*c;vv = real(ifft(c));
if rem(n,2) == 0 % Even case
    c(1:2:n-1,:) = vv(1:n/2,:);c(n:-2:2,:) = vv(n/2+1:n,:);
else % odd case
    c(1:2:n,:) = vv(1:(n+1)/2,:);c(n-1:-2:2,:) = vv((n+1)/2+1:n,:);
end
c = flipud(c);
end
end

Contact us