Exemple #1
0
def kChange(start, stop, step, show=False):
    k_range = np.arange(start, stop, step)

    E_list = energy2(k_range, hbar, m, sig)
    Es_list = []
    for i in k_range:
        Psi_x = gauss_init(x, i, x0=x0, d=sig)
        sch = Schrodinger(x, Psi_x, V_x, hbar=hbar, m=m, t=0)
        Es_list.append(sch.energy())

    Diff_list = [Es_list[j] - E_list[j] for j in range(len(k_range))]

    plt.figure()
    plt.plot(k_range, E_list, label="Theoretical")
    plt.plot(k_range, Es_list, label="Simulated", linestyle="--")
    plt.title("k0")
    plt.legend()
    plt.xlabel("k0")
    plt.ylabel("Energy")
    plt.savefig("k0.png")
    if show:
        plt.show()

    plt.figure()
    plt.plot(k_range, Diff_list, label="Diff")
    plt.title("k0_Diff")
    plt.legend()
    plt.xlabel("k0")
    plt.ylabel("k0_Difference")
    plt.savefig("k0_diff.png")
    if show:
        plt.show()
Exemple #2
0
def Nchange(nrange, show=False):
    E_ = energy2(k0, hbar, m, sig)
    Es_list = []
    for i in nrange:
        N = 2**i
        x = np.array([i * dx for i in range(N)])
        x = x - max(x) / 2

        Psi_x = gauss_init(x, k0, x0=x0, d=sig)
        V_x = np.zeros(N)

        sch = Schrodinger(x, Psi_x, V_x, hbar=hbar, m=m)
        Es_list.append(sch.energy())

    Diff_list = [Es_list[j] - E_ for j in range(len(nrange))]

    plt.figure()
    plt.plot(nrange, [E_ for i in nrange], label="Theoretical")
    plt.plot(nrange, Es_list, label="Simulated", linestyle="--")
    plt.title("N")
    plt.legend()
    plt.xlabel("N")
    plt.ylabel("Energy")
    plt.savefig("N.png")
    if show:
        plt.show()

    plt.figure()
    plt.ylim()
    plt.plot(nrange, Diff_list, label="Diff")
    plt.title("N_Diff")
    plt.legend()
    plt.xlabel("N")
    plt.ylabel("Energy_Difference")
    plt.savefig("N_diff.png")
    if show:
        plt.show()

    Rel_list = [Diff_list[j] / E_ for j in range(len(nrange))]
    plt.figure()
    plt.plot(nrange, Rel_list, label="Relative Difference")
    plt.title("N Relative Difference")
    plt.legend()
    plt.xlabel("N")
    plt.ylabel("Relative_Energy_Difference")
    plt.savefig("N_rel.png")
Exemple #3
0
def mChange(start, stop, step, show=False):
    m_range = np.arange(start, stop, step)

    E_list = energy2(k0, hbar, m_range, sig)
    Es_list = []
    for i in m_range:
        Psi_x = gauss_init(x, k0, x0=x0, d=sig)
        sch = Schrodinger(x, Psi_x, V_x, hbar=hbar, m=i, t=0)
        Es_list.append(sch.energy())

    Diff_list = [Es_list[j] - E_list[j] for j in range(len(m_range))]

    plt.figure()
    plt.plot(m_range, E_list, label="Theoretical")
    plt.plot(m_range, Es_list, label="Simulated", linestyle="--")
    plt.title("M")
    plt.legend()
    plt.xlabel("M")
    plt.ylabel("Energy")
    plt.savefig("M.png")
    if show:
        plt.show()

    plt.figure()
    plt.plot(m_range, Diff_list, label="Diff")
    plt.title("M_Diff")
    plt.legend()
    plt.xlabel("M")
    plt.ylabel("Energy_Difference")
    plt.savefig("M_diff.png")
    if show:
        plt.show()

    Rel_list = [Diff_list[j] / E_list[j] for j in range(len(m_range))]
    av = np.mean(Rel_list)
    plt.figure()
    plt.ylim(av - 0.1, av + 0.1)
    plt.plot(m_range, Rel_list, label="Average.{}".format(round(av, 5)))
    plt.title("M Relative Difference")
    plt.legend()
    plt.xlabel("M")
    plt.ylabel("Relative_Energy_Difference")
    plt.savefig("M_rel.png")
    if show:
        plt.show()
Exemple #4
0
def sigChange(start, stop, step, show=False):
    sig_range = np.arange(start, stop, step)

    E_ = energy2(k0, hbar, m, sig_range)
    Es_list = []
    for i in sig_range:
        Psi_x = gauss_init(x, k0, x0=x0, d=i)
        sch = Schrodinger(x, Psi_x, V_x, hbar=hbar, m=m, t=0)
        Es_list.append(sch.energy())

    Diff_list = [Es_list[j] - E_[j] for j in range(len(sig_range))]

    plt.figure()
    plt.plot(sig_range, E_, label="Theoretical")
    plt.plot(sig_range, Es_list, label="Simulated", linestyle="--")
    plt.title("Sigma")
    plt.legend()
    plt.xlabel("Sigma")
    plt.ylabel("Energy")
    plt.savefig("Sigma.png")
    if show:
        plt.show()

    plt.figure()
    plt.plot(sig_range, Diff_list, label="Diff")
    plt.title("Sigma_Diff")
    plt.legend()
    plt.xlabel("Sigma")
    plt.ylabel("Energy_Difference")
    plt.savefig("Sigma_diff.png")
    if show:
        plt.show()

    Rel_list = [Diff_list[j] / E_[j] for j in range(len(sig_range))]
    plt.figure()
    plt.plot(sig_range, Rel_list, label="Relative Difference")
    plt.title("Sigma Relative Difference")
    plt.legend()
    plt.xlabel("Sigma")
    plt.ylabel("Relative_Energy_Difference")
    plt.savefig("Sig_rel.png")
    if show:
        plt.show()
k = fftfreq(N, dk)
ks = fftshift(k)

# Defining time steps
t = 0
dt = 0.01
step = 10
Ns = 100
print("Final time", dt * step * Ns)

hbar = 1
m = 1

sch = Schrodinger(x, psi_x, V_x, k, hbar=hbar, m=m)

print("Numerical Energy :", sch.energy())
print("Theoretical Energy", (hbar**2 * k_initial**2) / (2 * m))

print("Difference :", sch.energy() - (hbar**2 * k_initial**2) / (2 * m))

psi_init2 = gauss_init(x, k_initial, x0=x0, d=d)
psis2 = np.real(psi_init2 * np.conj(psi_init2))

# plt.plot(x, sch.mod_square_x(True))
# plt.plot(x, V_x)
# plt.ylim(0, max(np.real(psi_x)))
# plt.show()

a = Animate(sch,
            V_x,
            step,
Exemple #6
0
sch = Schrodinger(x, psi_init, V, hbar=hbar, m=m, t=0)


# a = Animate(sch, V, 1, dt,lim1=((-xmax, xmax), (0, max(sch.psi_squared))))
# a.make_fig()

simx = []
tl = []
El = []

temp = 0
while temp < Nt:
    sch.evolve_t(1, dt=dt)
    temp += 1
    if (temp % nsave) == 0:
        simx.append(sch.expectation_x())
        tl.append(temp * dt)
        El.append(sch.energy())

actualx = x_pos(np.asarray(tl), x0, omegax, 0)
diff = abs(np.asarray(simx) - actualx)

plt.plot(tl, simx)
plt.plot(tl, actualx, linestyle="--")
plt.show()

plt.plot(tl, diff)
plt.show()

Exemple #7
0
m = 1

k0 = 1
x0 = x[int(N / 2)]
sig = 1

Psi_x = gauss_init(x, k0, x0=x0, d=sig)
V_x = np.zeros(N)

sch = Schrodinger(x, Psi_x, V_x, hbar=hbar, m=m)

# plt.plot(x,sch.mod_square_x(r=True))
# plt.show()

E = energy(k0, hbar, m)
Es = sch.energy()
print("theoretical energy", E)
print("additional theoretical energy", energy2(k0, hbar, m, sig))
print("simulated energy", Es)
print("diff", Es - E)

hbarChange(1, 15, 0.2)

mChange(1, 15, 0.2)

sigChange(1, 10, 0.2)

kChange(-5, 5, 0.1)

Nchange([9, 10, 11, 12, 13])
Exemple #8
0
k0 = 2
x0 = int(N / 4) * dx
sig = 8

bar_amp = 5
L = 20
x1 = (N / 2) * dx
x2 = x1 + (L * dx)

Psi_x = gauss_init(x, k0, x0=x0, d=sig)

V_x = barrier(x, bar_amp, x1, x2)

sch = Schrodinger(x, Psi_x, V_x, hbar=hbar, m=m, args=x1)
print(sch.energy())

dt = 0.001
step = 100
finalt = 50

c = Constants(bar_amp, dt, dx, k0)

# plt.plot(x, sch.psi_squared)
# plt.plot(x, V_x)
# plt.show()

# a = Animate(sch, V_x, step, dt)
# a.make_fig()

######Testing Impedence
Exemple #9
0
dt = 0.01
step = 50
ft = 34

Ns = int(ft / (dt * step))

print(dt * Ns * step)

print("Diffusion", dt / (dx**2))
print("vdt", A * dt)
print("kdx", k_init * dx)
sch = Schrodinger(x, psi_init, V_x, k, hbar=hbar, m=m, t=t)

E = (hbar**2) * (k_init**2 + 1 / (4 * sig**2)) / (2 * m)
print("Energy", E)
print("Energy_sim", sch.energy())
print("Lenght", L)
# print("Theory", t_theory(L, A, E))

# plt.plot(x, sch.psi_squared)
# plt.plot(x, V_x)
# plt.show()
#
# a = Animate(sch, V_x, step, dt)
# a.make_fig()

################### Testing
t_list = []
for i in range(0, Ns):
    t += dt * step
    t_list.append(t)