MATLAB: IFFT problem when approximating integrals

ifftnumerical integration

Hi all,
I have a problem when I use the ifft function to approximate an integral. For example, I want to integrate
exp(-1i*u*x)*exp(-x)
over x from 0 to infinity, for several values of u that are reals.
So I descritized and wrote
N = 2^12; %number of steps
eta = 0.01; %integration increment
lambda = 2*pi/(N*eta); %u increment
u_j = -(N-1)*lambda/2 + lambda.*(0:N-1); %list of u
x_k = eta.*(0:N-1); %grid of x for integration
Now given the ifft formula in the Matlab help, the corresponding X(k) I need to take is
f = exp(1i*u_j(end)*x_k).*exp(-x_k)*eta;
and the values of the integral for each u_j is then
sol = N*real(ifft(f));
The problem is that I do not obtain the correct approximated values (I checked with Mathematica and we know the exact solution of the integral: 1/(1+u^2) for the real part). For example, the approximation for u_j(2055)=0.9971 is sol(2055)=0.5892 instead of 0.5065 (closer to correct value 0.5). However, the correct approximation appears to be in sol(2056)=0.5065. So there is a lag of one. Is any one able to explain me why?

Best Answer

I finally found the problem. In version R2010b of Matlab, the help documentation for fft has a typo. The Nth root of unity should be defined as exp(-2i*pi/N) instead of exp(2i*pi/N).
Thus, I should use fft instead of ifft.
Related Question