why the two split-step fourier methods using fft and ifft is equivalent ?
Afficher commentaires plus anciens
clear
close all
N = 512; % Number of Fourier modes
dt = .005; % Size of time step
tfinal = 2; % Final time
M = round(tfinal/dt); % Total number of time steps
J = 100; % Steps between output
L = 20; % Space period
q = -1;
mu = 2/3;
v = 1;
h = L/N; % Space step
n = (-N/2:1:N/2-1)'; % Indices
x = n*h; % Grid points
u0 = (12 - 48*x.^2 + 16*x.^4)./...
(8.*sqrt(6).*exp(x.*x/2.)*pi.^0.25);
u = u0; % Initial Condition Phi_4 of harmonic potential
k = 2*n.*pi/L; % Wavenumbers
t = 0;
for m = 1:1:M % Start time loop
u = exp(dt/2*1j*q*x.^2).*u; % Solve non-constant part of LSE
c = fftshift(fft(fftshift(u))); % Take Fourier transform
c = exp(dt/2*1j*-k.^2).*c; % Advance in Fourier Space
u = fftshift(ifft(fftshift(c))); % Return to Physical Space
end
plot(x,u0,'k', 'LineWidth', 2,'DisplayName', 'initial wavefunction')
hold on
plot(x,real(u),'r', 'LineWidth', 2,'DisplayName', 'final wavefunction real part')
plot(x,imag(u),'m', 'LineWidth', 2,'DisplayName', 'final wavefunction imag part')
legend('show');
u_an=exp(-1j*9/2*20).*u0;%*20 is not important, because it always in the eigen state and the modulus is constant
%just the real and imag of wavefunction is changed.
figure;
plot(x, abs(u), 'r.', 'MarkerSize', 12, 'DisplayName', '|u|');
hold on;
plot(x, abs(u_an), 'b-', 'LineWidth', 1.5, 'DisplayName', '|u_{an}|');
hold off;
legend('show');
second:@Paul told me that fft must need input from x=0, I can not figure out why the two code gives the same result.
clear
close all
N = 512; % Number of Fourier modes
dt = .005; % Size of time step
tfinal = 2; % Final time
M = round(tfinal/dt); % Total number of time steps
J = 100; % Steps between output
L = 20; % Space period
q = -1;
mu = 2/3;
v = 1;
h = L/N; % Space step
n = (-N/2:1:N/2-1)'; % Indices
x = n*h; % Grid points
u0 = (12 - 48*x.^2 + 16*x.^4)./...
(8.*sqrt(6).*exp(x.*x/2.)*pi.^0.25);
u = u0; % Initial Condition Phi_4 of harmonic potential
k = 2*n.*pi/L; % Wavenumbers
t = 0;
for m = 1:1:M % Start time loop
u = exp(dt/2*1j*q*x.^2).*u; % Solve non-constant part of LSE
c = fftshift(fft(u)); % Take Fourier transform
c = exp(dt/2*1j*-k.^2).*c; % Advance in Fourier Space
u = ifft(fftshift(c)); % Return to Physical Space
end
plot(x,u0,'k', 'LineWidth', 2,'DisplayName', 'initial wavefunction')
hold on
plot(x,real(u),'r', 'LineWidth', 2,'DisplayName', 'final wavefunction real part')
plot(x,imag(u),'m', 'LineWidth', 2,'DisplayName', 'final wavefunction imag part')
legend('show');
u_an=exp(-1j*9/2*20).*u0;%*20 is not important, because it always in the eigen state and the modulus is constant
%just the real and imag of wavefunction is changed.
figure;
plot(x, abs(u), 'r.', 'MarkerSize', 12, 'DisplayName', '|u|');
hold on;
plot(x, abs(u_an), 'b-', 'LineWidth', 1.5, 'DisplayName', '|u_{an}|');
hold off;
legend('show')
2 commentaires
Sulaymon Eshkabilov
le 20 Déc 2023
In code 1, you are shifting '0' freq component twice. Doing it once is sufficient. Therefore, using fftshit() once in code 2 is just good :).
Daniel Niu
le 21 Déc 2023
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Spectral Measurements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

