-
Notifications
You must be signed in to change notification settings - Fork 1
/
probability_plotter.py
59 lines (47 loc) · 1.44 KB
/
probability_plotter.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import numpy as np
import matplotlib.pyplot as plt
#from os import listdir
import pandas as pd
from error import error
def normalise(y_array,x_array):
"""
Produces the normalisation constant for a given array
Parameters
----------
y_array : numpy.ndarray
Array of y-axis values to be normalised.
x_array : numpy.ndarray
Array of corresponding x-axis values.
Returns
-------
TYPE
DESCRIPTION.
"""
integral=np.trapz(y_array**2,x=x_array)
const=1/integral
return const**0.5
if __name__=="__main__":
"""
Plots the normalised probability density when script is run directly
"""
try:
wave_function_csv="wavefunctions_N=1000.csv"
except:
error("Unable to load"+str(wave_function_csv))
data=pd.read_csv("wavefunctions\\"+str(wave_function_csv))
N=len(data) # No. of integration steps
position_array=np.linspace(-1/2,1/2,N)
plt.figure("Probability (N={})".format(N))
plt.xlabel(r"$\tilde{x}$")
plt.ylabel(r"$|\psi(\tilde{x})|^2$")
i=1
while 1:
try:
prob=((normalise(data[str(i)],position_array))*data[str(i)])**2 # Normalises probability density
plt.plot(position_array,prob, label="n="+str(i))
i+=1
except:
break
plt.tick_params(which='both',direction='in',right=True,top=True)
plt.legend()
plt.show()