I want to ask something about Chebyshev differentiation via FFT, which can be used to obtain with spectral accuracy the derivative of a smooth function. See for instance this code in python, which performs the derivative of a given function "u" in the domain [-1,1] and computes the L2 norm of the error.
from numpy.fft import fft,ifft import numpy as np def chebfft(v,x): N = len(v)-1; if N==0: return 0 ii = np.arange(0,N); iir = np.arange(1-N,0); iii = np.array(ii,dtype=int) V = np.hstack((v,v[N-1:0:-1])) U = np.real(fft(V)) W = np.real(ifft(1j*np.hstack((ii,[0.],iir))*U)) w = np.zeros(N+1) w[1:N] = -W[1:N]/np.sqrt(1-x[1:N]**2) w = sum(iii**2*U[iii])/N + .5*N*U[N] w[N] = sum((-1)**(iii+1)*ii**2*U[iii])/N + .5*(-1)**(N+1)*N*U[N] return w N=50 L=10 aa = 0.34 x = np.cos(np.pi*np.arange(0,N+1)/N) u=np.sin(2*np.pi*x/L)*np.exp(-aa*x) uder = np.exp(-aa*x)*(2*np.pi*np.cos(2*np.pi*x/L)-aa*L*np.sin(2*np.pi*x/L))/L err_ft = chebfft(u,x)-uder print ("L2 norm:",np.linalg.norm(err_ft))
The problem that I have is that I don't really understand how to do the same with a general interval [a,b]. The new collocation points can be changed just with a linear mapping, but then the procedure inside chebfft fails. Provably the reason why is not woorking is very simple, but I don't see.
Thanks for the help.