In [7]:
%pylab inline
from ipywidgets import interact
Populating the interactive namespace from numpy and matplotlib
In [3]:
# mertekegysegek: hossz: L 
# energia: E_1 
# ido: ugy, hogy hbar=1 teljesuljon
Out[3]:
3.6739403974420594e-16
In [43]:
x_resolution = 1000
x = linspace(0, 1, x_resolution)
dx = x[1]-x[0]


psin = []
EE = []
N = 100
for n in arange(N)+1:
    kn = n*pi
    psin.append(sqrt(2.)*sin(kn*x))
    EE.append(n*n)
EE = array(EE)
psin = array(psin)

print(shape(psin))
(100, 1000)
In [47]:
cn = zeros_like(EE) + 0.j
cn[0] = 1. 
cn[1] = 1. 

cn /= sqrt(sum(abs(cn)**2))



def plot_wf(t=0):
    psi = zeros(x_resolution) + 0.j
    for n in range(len(EE)):
        psi += cn[n]*exp(-1.j*EE[n]*t)*psin[n, :]
    plot(x, abs(psi)**2)
    plot(x, psi.real, "--", color="red")
    plot(x, psi.imag, "--", color="green")
    #ylim(-4, 4)
    show()
In [41]:
interact(plot_wf, t=(0, 6, 0.05))
Out[41]:
<function __main__.plot_wf(t=0)>
In [75]:
x0 = 0.5
sigma = 0.05
k0 = 0.
psi_0 = zeros(x_resolution, dtype=complex)
psi_0 = exp(-(x-x0)**2/(2.*sigma**2)) * exp(1.j*k0*x)
psi_0 /= sqrt(sum(abs(psi_0)**2)*dx)

plot(x, psi_0.real)
plot(x, psi_0.imag)

for n in range(N):
    cn[n] = sum(psin[n, :]*psi_0)*dx
print(sum(abs(cn)**2))
1.0000000000000002
In [61]:
interact(plot_wf, t=(0, 0.6, 0.005))
Out[61]:
<function __main__.plot_wf(t=0)>
In [50]:
plot(abs(cn))
Out[50]:
[<matplotlib.lines.Line2D at 0x7f5ab508dac8>]
In [76]:
t_resolution = 500
tt = linspace(0, 0.5, t_resolution)

psixt = zeros((x_resolution, t_resolution), dtype=complex)
for nt in range(t_resolution):
    for n in range(N):
        psixt[:, nt] += cn[n]*exp(-1.j*EE[n]*tt[nt])*psin[n, :]
In [88]:
#fig, ax = subplots(1, figsize=(6,6)) 
imshow(abs(psixt.T)**2, origin="lower", extent=(0, x[-1], 0, tt[-1]), aspect=x[-1]/tt[-1])
colorbar()
show()
In [ ]: