%pylab inline
from ipywidgets import interact
Populating the interactive namespace from numpy and matplotlib
# mertekegysegek: hossz: L
# energia: E_1
# ido: ugy, hogy hbar=1 teljesuljon
3.6739403974420594e-16
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)
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()
interact(plot_wf, t=(0, 6, 0.05))
<function __main__.plot_wf(t=0)>
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
interact(plot_wf, t=(0, 0.6, 0.005))
<function __main__.plot_wf(t=0)>
plot(abs(cn))
[<matplotlib.lines.Line2D at 0x7f5ab508dac8>]
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, :]
#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()