What does the wavenumber refer to when solving the Poisson equation with fourier transforms?

67 Views Asked by At

I am working on my senior project in college on $n$-body gravitational simulations solving the Poisson equation using Fast Fourier Transforms. After realizing that I did not understand the math well enough, I decided to play around with scilab (similar to matlab and I believe even uses the same scripting language) to see if I could figure it out. I solved for potential (or tried) and plotted using this equation...

$$\nabla^2 (\hat{\phi}e^{i(k_xx)}) = -(k_x^2)(\hat{\phi}e^{i(k_xx)}) \\= 4\pi G \hat{\rho} e^{i(k_xx)}$$ So... $$ -(k_x^2)\hat{\phi} = 4 \pi G\hat\rho \\ \hat\phi = -\frac{4\pi G \hat\rho}{k_x^2}$$

This is not my own work. This is based off of an observablehq.com notebook by Ricky Reusser. You can find the whole explanation as well as their 2d simulation here.

Next is my scilab attempt at a 1D model, the script and the resulting graph. (I apologize to any matlab veterans out there. This is my first time using anything like matlab, so please forgive the cluckiness)

s = [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 0 0];
c = 0:28;

y=fftshift(fft(s));
k_x = 2 * %pi * c/ 29;
y=-(4 * %pi * 4.300E-03 * s)/ k_x * k_x;

new_y = ifftshift(ifft(y));

f = 29 *(0:(56/2))/29;
n = size(f,'*')
clf()
plot(f, new_y(1:n))

Picture of the Graph:Picture of the Graph

Issue 1: even though my mass is over to the right, the location of the potential does not change.

Issue 2: I should be getting numbers with just real components out, but when I print out the data this is not the case.

I am pretty sure that the issue is with the wave number $k_x$ and despite many hours of search I have not found a way to understand what is going on with the wave number. So any insight into what is causing these issues and what k actually mean more concretely than that it is related to $\frac{2\pi}{\lambda}$ would be great!