I'm making the following exercise in Matlab, and I'm having trouble expresing my result in $x\in[0,2\pi]$ not in $x\in[-1,1]$. I first done this (as shown below) in Gauss-Lobatto points, but I don't know how to transform everything to the original domain ($[0,2\pi]$). Any fix, comment or hint is welcome, thank you in advance!
Exercise with Matlab: Given the function $\,f(x)=e^{\,\text{sin}^{2}\,(x)+\cos(x)}\,$ defined in $\,[0,2\,\pi].\,$ Find the derivative of such function using Chebyshev spectral derivation with 16 nodes and find the error (using infinite norm).
These 3 matlab files I have done:
Nodos=16;
[x1,w1,df1,error1]=EjerunoCheby(Nodos);
hold on
plot(x1,w1','g',x1,df1,'*');
error1;
str1 = num2str(error1);
str2= num2str(Nodos);
title(['Chebyshev with ' str2 ' nodes. Error (infinite norm): ' str1])
hold off
%%%%%%%%%%%%%%%%%%%end of file 1%%%%%%%%%%%%%%%%%%%%%
function [x,DerCheby,df,error] = EjerunoCheby(N)
enteros=0:N;
x=cos(pi*enteros/N);
f=exp((sin(x)).*(sin(x))+cos(x));
D=MatrizD(N);
DerCheby=D*f';
df=f.*(2.*sin(x).*cos(x)-sin(x));
error=max(abs(DerCheby'-df));
%%%%%%%%%%%%%%%%%%%end of file 2%%%%%%%%%%%%%%%%%%%%%
function [D] = MatrizD(N)
nrows = N+1;
ncols = N+1;
enteros=0:N;
x=cos(pi*enteros/N);
v=-x./(2.*(1-x.*x));
D=diag(v);
D(1,1)=((2.*N*N+1)./6);
D(N+1,N+1)=-D(1,1);
cc=ones(length(x)-2,1);
c=[2;cc;2];
for i = 1:ncols
for j = 1:nrows
if i~= j
D(i,j) = (c(i)/c(j))*(((-1)^(i+j))/(x(i)-x(j)));
end
end
end
%%%%%%%%%%%%%%%%%%%%%end of file 3%%%%%%%%%%%%%%%%%%%%%%%%%%