I have some code that does exactly this, but I do not like to use things I do not understand. Here is the code
N1=N+1;
cheb=cos(pi*(0:N)/N)';
unif=linspace(-1,1,N1)';
if N<3
x=cheb;
else
x=cheb+sin(pi*unif)./(4*N);
end
P=zeros(N1,N1);
%N1xN1 zero matrix
xold=2;
%eps= epsilon!
while max(abs(x-xold))>eps
xold=x;
P(:,1)=1;
P(:,2)=x;
%set first collumn entries to 1 (P(:,1) = 1);
%set second collumn entries to x (P(:,2) = x);
for k=2:N
P(:,k+1)=( (2*k-1)*x.*P(:,k)-(k-1)*P(:,k-1) )/k;
%%Bonnets formula ;)
end
x=xold-( x.*P(:,N1)-P(:,N) )./( N1*P(:,N1));
end
%---chebyshev differentiation matrix---------------------------------------- ---------
x=-x;
X=repmat(x,1,N1);%set every collumn of X to x
Xdiff=X-X'+eye(N1);
L=repmat(P(:,N1),1,N1);
L(1:(N1+1):N1*N1)=1;
D=(L./(Xdiff.*L'));
D(1:(N1+1):N1*N1)=0;
D(1)=-(N1*N)/4;
D(N1*N1)=(N1*N)/4;
I really want understand, theoretically, how this matrix is formed and then more importantly, implemented in MATLAB.
Up until the comment
% --- chebyshev differenti....
I understand.
I can not seem to find any documentation relating to the formation of this matrix.
NOTE: The syntax I am ok with, it is the actual formation of the matrix I am having trouble with. I have posted this on MSE and it had been put on hold. I had a look on the help centre and this site seemed to fit the description.
chebfun
, which implements adaptive (piecewise) Chebyshev approximation and collocation for differential equations -- no need to reinvent the wheel! (I happen to know the author, and recognize his style ;)) $\endgroup$ – Christian Clason Jul 17 '16 at 11:26