Calculating the laplacian of a complex field
2 次查看(过去 30 天)
显示 更早的评论
I'm trying to solve a Nonlinear-Schrodinger equation that contains a laplacian term.
I know that you can use the
del2(psi,x,y)
command. But I wish to do this in Fourier space, and without using any inbuilt functions as I am porting the code over to fortran.
So far, I have the code
%% Setup of grid and Fourier grid/operators
xmax = 15;
xmin = -15;
ymax = 15;
ymin = -15;
nx = 1024;
ny = 1024;
dx = (xmax-xmin)/nx;
dy = (ymax-ymin)/nx;
x = [xmin+dx:dx:xmax];
y = [ymin+dy:dy:ymax];
kx = 2*pi/(xmax-xmin)*[0:nx/2 -nx/2+1:-1];
ky = 2*pi/(ymax-ymin)*[0:ny/2 -ny/2+1:-1];
Tx = - kx .* kx;
Ty = - ky .* ky;
%% Load wavefunction
load('psi.mat')
psi = psiR + 1i.*psiI;
%% Move to fourier space
kpsi = fftn(psi);
%% Calculate laplacian using both methods
delsqLaplacian = 4*del2(u_og,x,y); % using del2
fourierLaplacian = ifftn((Tx + Ty').*kpsi)*(4*pi*pi/((xmax-xmin)*(ymax-ymin))); % Using Fourier derivatives
Unfortunately, these two variables do not return the same result. Can someone let me know how I should be doing this?
0 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!