From 5d7a9ddfc13d8eec746005fad54cabaca15c6449 Mon Sep 17 00:00:00 2001 From: sotech117 Date: Tue, 7 May 2024 18:34:59 -0400 Subject: finish hw8, the last hw --- .DS_Store | Bin 12292 -> 14340 bytes hw8/10-17-new.jl | 75 +++++++++++++++++++++++++++++++++++ hw8/10-17-tunnelling-0.025-200.0.mp4 | Bin 0 -> 1268128 bytes hw8/10-17-tunnelling-0.025-40.0.mp4 | Bin 0 -> 1308178 bytes hw8/10-17-tunnelling-0.025.mp4 | Bin 0 -> 1268128 bytes hw8/10-17-tunnelling-0.05-200.0.mp4 | Bin 0 -> 1251259 bytes hw8/10-17-tunnelling-0.05-40.0.mp4 | Bin 0 -> 1127725 bytes hw8/10-17-tunnelling-0.05.mp4 | Bin 0 -> 326530 bytes hw8/10-17-tunnelling-0.1.mp4 | Bin 0 -> 289775 bytes hw8/10-17.jl | 4 +- hw8/10-17.png | Bin 0 -> 16132 bytes hw8/wavefunction.png | Bin 0 -> 19169 bytes 12 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 hw8/10-17-new.jl create mode 100644 hw8/10-17-tunnelling-0.025-200.0.mp4 create mode 100644 hw8/10-17-tunnelling-0.025-40.0.mp4 create mode 100644 hw8/10-17-tunnelling-0.025.mp4 create mode 100644 hw8/10-17-tunnelling-0.05-200.0.mp4 create mode 100644 hw8/10-17-tunnelling-0.05-40.0.mp4 create mode 100644 hw8/10-17-tunnelling-0.05.mp4 create mode 100644 hw8/10-17-tunnelling-0.1.mp4 create mode 100644 hw8/10-17.png create mode 100644 hw8/wavefunction.png diff --git a/.DS_Store b/.DS_Store index 2b5a296..1d1ed19 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/hw8/10-17-new.jl b/hw8/10-17-new.jl new file mode 100644 index 0000000..1353618 --- /dev/null +++ b/hw8/10-17-new.jl @@ -0,0 +1,75 @@ +using Plots +using LinearAlgebra + +m = 1 +hbar = 1 +xmin = -6.5 +xmax = 6.5 +N = 2000 +x = collect(range(xmin, stop = xmax, length = N + 1)) # one extra, want 1000 spaces +dx = x[2] - x[1] +println("dx = ", dx) +p = 100.0 +V0 = 2 * p^2 / (2.0 * m) +sig = 0.25 +x0 = 2.0 # a bit away to not interfere with the walls +barrier_width = 0.025 + +# setup the potential barrier +V = 0 .* x +# println("V = ", length(V)) +for i in 1:length(V) + if x[i] > 0 && x[i] < barrier_width + V[i] = V0 + end +end +plot(x, V, xlabel = "x", ylabel = "V(x)", title = "Potential V(x)", legend = :none) + +# make the initial wavefunction +psi0 = exp.(-((x[2:end-1] .+ x0) .^ 2) / (2 * sig^2)) .* exp.(1.0im * p * x[2:end-1]) +C = sum(abs2.(psi0) .* dx) +psi0 = psi0 / sqrt(C) +plot(x[2:end-1], abs.(psi0), xlabel = "x", ylabel = "Re(psi)", title = "Initial wavefunction", legend = :none) + +# make the Hamiltonian +A = (hbar^2 / (2 * m * dx^2)) +# main diagonal +d = A * ones(N - 1) + V[2:end-1] # add potential +# upper and lower diagonals +dl = (A / -2.0) * ones(N - 2) +du = (A / -2.0) * ones(N - 2) +H = Tridiagonal(dl, d, du) + +# diagonalize matrix +E, psi = eigen(H) +psi1 = psi[:, 1] + +# normalize +A = sum(abs2.(psi1) .* dx) +psi = psi ./ sqrt(A) +println("A = ", A) + +c = zeros(ComplexF64, length(psi[:, 1])) +for i in 1:length(c) + c[i] = sum(conj.(psi[:, i]) .* psi0 .* dx) +end + +dt = 0.0001 + +anim = @animate for t in 0:dt:0.25 + tmp = zeros(ComplexF64, length(psi[:, 1])) + for i in 1:length(c) + tmp = tmp .+ c[i] .* exp.(-1.0im * E[i] * t / hbar) .* psi[:, i] + end + rounded_p = round(p, digits = 3) + rounded_pot = round(V0, digits = 3) + plot(x[2:end-1], abs.(tmp), xlabel = "x", ylabel = "abs(Ψ)", title = "Propagating Wavepacket (k_0 = $p, V0 = $rounded_pot)", label = "psi @ t = $t", ylims = (-2, 2), lw = 2) + # plot the real + plot!(x[2:end-1], real(tmp), xlabel = "x", label = "real") + # plot the imaginary + plot!(x[2:end-1], imag(tmp), xlabel = "x", label = "imag") + plot!([endpoint_1, endpoint_1], [0, 2], label = "", line = :dash, color = :red) + plot!([endpoint_2, endpoint_2], [0, 2], label = "barrier (width = $barrier_width)", line = :dash, color = :red) +end + +mp4(anim, "hw8/10-17-tunnelling-$barrier_width-$p.mp4", fps = 30) \ No newline at end of file diff --git a/hw8/10-17-tunnelling-0.025-200.0.mp4 b/hw8/10-17-tunnelling-0.025-200.0.mp4 new file mode 100644 index 0000000..49b9c9f Binary files /dev/null and b/hw8/10-17-tunnelling-0.025-200.0.mp4 differ diff --git a/hw8/10-17-tunnelling-0.025-40.0.mp4 b/hw8/10-17-tunnelling-0.025-40.0.mp4 new file mode 100644 index 0000000..9b80be7 Binary files /dev/null and b/hw8/10-17-tunnelling-0.025-40.0.mp4 differ diff --git a/hw8/10-17-tunnelling-0.025.mp4 b/hw8/10-17-tunnelling-0.025.mp4 new file mode 100644 index 0000000..49b9c9f Binary files /dev/null and b/hw8/10-17-tunnelling-0.025.mp4 differ diff --git a/hw8/10-17-tunnelling-0.05-200.0.mp4 b/hw8/10-17-tunnelling-0.05-200.0.mp4 new file mode 100644 index 0000000..25ebb7d Binary files /dev/null and b/hw8/10-17-tunnelling-0.05-200.0.mp4 differ diff --git a/hw8/10-17-tunnelling-0.05-40.0.mp4 b/hw8/10-17-tunnelling-0.05-40.0.mp4 new file mode 100644 index 0000000..9b3124f Binary files /dev/null and b/hw8/10-17-tunnelling-0.05-40.0.mp4 differ diff --git a/hw8/10-17-tunnelling-0.05.mp4 b/hw8/10-17-tunnelling-0.05.mp4 new file mode 100644 index 0000000..b247200 Binary files /dev/null and b/hw8/10-17-tunnelling-0.05.mp4 differ diff --git a/hw8/10-17-tunnelling-0.1.mp4 b/hw8/10-17-tunnelling-0.1.mp4 new file mode 100644 index 0000000..f2ba8b9 Binary files /dev/null and b/hw8/10-17-tunnelling-0.1.mp4 differ diff --git a/hw8/10-17.jl b/hw8/10-17.jl index d1d18b7..6690d1f 100644 --- a/hw8/10-17.jl +++ b/hw8/10-17.jl @@ -16,7 +16,9 @@ function H(psi, dx, k = 0, width = 0.1) # action of Hamiltonian on wavefunction for i in 1:length(psi) x = i * dx if x >= 30.0 && x <= 30.0 + width - Hpsi[i] = 2 * k^2 * psi[i] + Hpsi[i] += 2 * k^2 + # else + # Hpsi[i] += -0.01 end end diff --git a/hw8/10-17.png b/hw8/10-17.png new file mode 100644 index 0000000..9f76c42 Binary files /dev/null and b/hw8/10-17.png differ diff --git a/hw8/wavefunction.png b/hw8/wavefunction.png new file mode 100644 index 0000000..5ad2d78 Binary files /dev/null and b/hw8/wavefunction.png differ -- cgit v1.2.3-70-g09d2