% diffFFT Compute the derivative using fft

N = 128; % number of grid points

% Set up computational grid

xMin = -10; xMax = 10; xDomain = xMax-xMin;

x = linspace(xMin, xMax-xDomain/N, N);
    
% Fourier space discretization

dom = 2*pi/xDomain; om = [0:N/2,-N/2+1:-1]*dom;

f = exp(-x.^2); fnumF = 1i*om.*fft(f); fnum = real(ifft(fnumF));

fana = -2.*x.*exp(-x.^2);

% plot results

plot(x,fnum,x,fana,'o')

