-
Notifications
You must be signed in to change notification settings - Fork 1
/
analytical_psi.py
42 lines (35 loc) · 1 KB
/
analytical_psi.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
from math import sin,pi
import matplotlib.pyplot as plt
import numpy as np
from probability_plotter import normalise
length=1 #Length of potential well
def psi(x_array,n,L):
"""
Produces a wavefunction of an infinite square potential well
Parameters
----------
x_array : numpy.ndarray
Array of positional values.
n : int
Principle quantum number.
L : float
Length of potential well.
Returns
-------
psi_norm : numpy.ndarray
Normalised wavefunction.
"""
psi=np.array([sin((x+length/2)*pi*n/L) for x in x_array]) #accounts for not starting at x=0
psi_norm=psi*normalise(psi, x_array) #normalises array
return psi_norm
if __name__=="__main__":
"""
Plots wavefunction if script is run directly
"""
plt.figure("Analytical Wavefunctions")
for n in range(1,11):
x=np.linspace(-length/2,length/2,1000)
y=psi(x,n,length)
plt.plot(x,y,label="n="+str(n))
plt.legend()
plt.show()