-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathprob_dist.py
40 lines (32 loc) · 937 Bytes
/
prob_dist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
Solve Schodinger's equation and plot the probability distributions
Author: D. Hudson Smith
"""
from __future__ import print_function
import matplotlib.pyplot as plt
import numpy as np
import schrod
# Specify the potential
x = np.linspace(-3, 3, 200)
V = x + 0.5*x**4
# Create and solve Schrodinger's equation
eqn = schrod.Schrod(x, V, n_basis=40)
eqn.solve()
# Get the eigenvalues and eigenvectors
eig_vals = eqn.eigs
probs = eqn.prob_eig_x()
# Plot everything
plt.xlim((x[0],x[-1]))
plt.ylim((-1,9))
plt.title("Probability distributions for\n$V(x) = x + 0.5 x^4$", fontsize=18)
plt.xlabel("$x$")
plt.ylabel('Energy')
n_eigs_plt = 5
plt.plot(x, V, 'b-', lw=2)
for i in range(n_eigs_plt):
plt.fill_between(x, eig_vals[i], eig_vals[i]+probs[i], color='red', lw=0)
plt.axhline(eig_vals[i], ls='--', color='black', lw=2)
# Optionally show/save
# plt.show()
plt.tight_layout()
plt.savefig("./plots/prob_dist.png", dpi=100)