I'm having some problems with interpolating functions that I was hoping a Mathematica whiz could help me with.
I have some K-space numerical data, and I need to compute its Fourier transform. To do this, I'm creating interpolating functions for the function in K-space, then integrating against Exp[I K . x], as usual.
I have some function GetX[x1,x2] which computes the value of the position space function at the given coordinates. Originally, I wrote this function to compute the interpolating functions from data each time GetX was called. But, then I thought, this doesn't make much sense, because the data interpolating functions are the same for all 'x'.
So I split the function into two parts: One to compute the interpolating functions, then save them to a file, and a new implementation of GetX that just takes those interpolating functions as an argument, and does the integrals only. Since the interpolating functions are built outside of GetX now, you'd think that GetX would be faster.
But it's not! It's about half as fast. Furthermore, if I call Timing on the numerical integration step itself in each of the implementations, the numerical integration when the interpolating functions are built within GetX run about 20% faster than the integration step when the interpolating functions are built outside of GetX. Both implementations give the same result, so there's no difference between the functions aside from what I've already described.
This speed reduction makes no sense to me. Does anybody know what the problem is?