Untitled11 4
Untitled11 4
# Parameters
hbar = 197.3 # Reduced Planck's constant
m = 940 # Mass of the electron
e=3.795
a=[10]
plt.figure(figsize=(10,8))
#----------------------------------------------------
# Create potential matrix
def plot(b):
def v(x):
k=100
return 1/2 * k * x**2 + 1/3 * b * x**3
x = np.linspace(1e-2, 10, 1000) # Spatial domain
d=x[1]-x[0]
v_matrix=v(x)
#---------------------------------------------------------
# Hamiltonian matrix initialization
n = len(x)
matrix = np.zeros((n-2, n-2))
constant = 2 * m * d**2 / hbar**2
for i in range(n-2):
if i > 0:
matrix[i, i-1] = -1 # Off-diagonal (lower)
matrix[i, i] = 2 + constant * v_matrix[i+1] # Diagonal
if i < n - 3:
matrix[i, i+1] = -1 # Off-diagonal (upper)
#----------------------------------------------------------------
# Solve the eigenvalue problem
eigen_value, eigen_vector = np.linalg.eigh(matrix)
#---------------------------------------------------------------------
# Plotting the first few eigenstates
1
for n in range(3): # Plotting first three states
value=eigen_vector.T[n] # Taking transpose of the matrix
value=np.insert(value,0,0) #inserting values at the boundary
value=np.append(value,0)
plt.plot(x, value, label=f'b={b}\n Energy eigen =␣
,→{eigen_value[n]*hbar**2/(2*m*d**2)}')
plt.xlabel('Position (m)')
plt.ylabel('Wavefunction')
plt.legend()
plt.grid()
for i in range(len(a)):
plot(a[i])
[ ]:
2
[ ]: