Calculating the laplacian of a complex field

1 visualización (últimos 30 días)
Nick Keepfer
Nick Keepfer el 31 de Ag. de 2020
Editada: Nick Keepfer el 31 de Ag. de 2020
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?

Respuestas (0)

Categorías

Más información sobre Fortran with MATLAB en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by