Пример #1
0
    # a smart numpy way to calculate the second derivative in x:
    nabla2psi[1:N + 1] = (psi[0:N] + psi[2:N + 2] - 2 * psi[1:N + 1]) / dx2
    return 1j * (nabla2psi - V * psi
                 )  # this is the RH of Schroedinger equation!


def d_dt(psi):  # find Psi(t+dt)-Psi(t) /dt with 4th order Runge-Kutta method
    k1 = f(psi)
    k2 = f(psi + dt / 2 * k1)
    k3 = f(psi + dt / 2 * k2)
    k4 = f(psi + dt * k3)
    return (k1 + 2 * k2 + 2 * k3 + k4) / 6


vp = Plotter(interactive=0, axes=2, bg=(0.95, 0.95, 1))
vp.xtitle = ""
vp.ytitle = "|\Psi(x,t)|\^2"

bck = vp.load(datadir + "images/schrod.png").alpha(.3).scale(.0255).pos(
    [0, -5, -.1])
barrier = Line(np.stack((x, V * 15, np.zeros_like(x)), axis=1),
               c="black",
               lw=2)

lines = []
for i in range(0, Nsteps):
    for j in range(500):
        Psi += d_dt(Psi) * dt  # integrate for a while before showing things
    A = np.real(Psi * np.conj(Psi)) * 1.5  # psi squared, probability(x)
    coords = np.stack((x, A, np.zeros_like(x)), axis=1)
    Aline = Line(coords, c="db", lw=3)
Пример #2
0
    # a smart numpy way to calculate the second derivative in x:
    nabla2psi[1:N + 1] = (psi[0:N] + psi[2:N + 2] - 2 * psi[1:N + 1]) / dx2
    return 1j * (nabla2psi - V * psi
                 )  # this is the RH of Schroedinger equation!


def d_dt(psi):  # find Psi(t+dt)-Psi(t) /dt with 4th order Runge-Kutta method
    k1 = f(psi)
    k2 = f(psi + dt / 2 * k1)
    k3 = f(psi + dt / 2 * k2)
    k4 = f(psi + dt * k3)
    return (k1 + 2 * k2 + 2 * k3 + k4) / 6


plt = Plotter(interactive=False, axes=2, size=(1000, 500))
plt.xtitle = ""
plt.ytitle = "|\Psi(x,t)|\^2"

bck = plt.load(dataurl + "images/schrod.png").scale(0.015).pos([0, 0, -0.5])
barrier = Line(np.stack((x, V * 15), axis=1), c="dr", lw=3)

lines = []
for j in range(150):
    for i in range(500):
        Psi += d_dt(Psi) * dt  # integrate for a while
    A = np.real(Psi * np.conj(Psi)) * 1.5  # psi squared, probability(x)
    coords = np.stack((x, A, np.zeros_like(x)), axis=1)
    Aline = Tube(coords, c="db", r=0.08)
    plt.show(Aline, barrier, bck, zoom=2)
    lines.append(Aline)
    if plt.escaped: break  # if ESC is hit during the loop