So I wrote a short Python program to estimate the accuracy of the Python's FFT method.
import numpy as np
import matplotlib.pyplot as plt
#Aufgabe 1
x0=0
a=2.5
k0=3
X=np.linspace(-4,4,100)
timestep=0.1
k=np.fft.fftfreq(X.size,d=timestep)
psi_analytical=[(2/(np.pi*a**2))**(1/4)*np.exp(-((i-x0)**2)/a**2)*np.exp(1j*k0*(i-x0)) for i in X]
psi_tilde_numerical=np.fft.fft(psi_analytical)
psi_tilde_analytical=[(2/(np.pi*a**2))**(1/4)*(a/2)*np.exp(-(a*(i-k0))**2/4)*np.exp(-1j*i*x0) for i in k]
psi_numerical=np.fft.ifft(psi_tilde_analytical)
#plt.plot(k,np.abs(psi_tilde_numerical),label='numerical psi tilde')
#plt.plot(k,np.abs(psi_tilde_analytical),'--',color='tab:orange', label='analytical psi tilde')
plt.plot(X,np.abs(psi_analytical),label='analytical psi, real')
plt.plot(X,np.abs(psi_numerical),'--',color='tab:orange',label='numerical psi, real')
plt.legend()
plt.show()
The analytical function is as follows:
To my surprise, the numerical and analytical functions are totally different. However, I'm not sure why this is the case.
The normalisation constant N
is (2/(np.pi*a**2))**(1/4)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…