unit 2 quantum input
unit 2 quantum input
import numpy as np
# Constants
# Discretize space
x = np.linspace(-X_max, X_max, N)
# Kinetic energy term (T) and potential energy term (V) in the Hamiltonian
plt.figure(figsize=(12, 6))
plt.xlabel('x')
plt.ylabel('ψ(x)')
plt.legend()
plt.grid(True)
plt.figure(figsize=(12, 6))
a=0
a=a+70
plt.xlabel('x')
plt.ylabel('|ψ(x)|²')
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()
for i in range(3):
print(f"E_{i} = {eigenvalues[i]:.3f}")
# Particle in a box
import numpy as np
# Constants
dx = L / (N - 1) # grid spacing
# Discretize space
x = np.linspace(0, L, N)
# Kinetic energy term (T) and potential energy term (V) in the Hamiltonian
# Normalize the eigenfunctions (ensure they satisfy the boundary condition at x = 0 and x = L)
eigenfunctions = eigenfunctions / np.sqrt(np.trapz(np.abs(eigenfunctions)**2, x)) # Normalize each
eigenfunction
plt.figure(figsize=(12, 6))
plt.xlabel('x')
plt.ylabel('ψ(x)')
plt.legend()
plt.grid(True)
plt.figure(figsize=(12, 6))
a=0
a=a+3
plt.xlabel('x')
plt.ylabel('|ψ(x)|²')
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()
# Print the first few eigenvalues
for i in range(3):
print(f"E_{i+1} = {eigenvalues[i]:.3f}")
# Constants
# Discretize space
x = np.linspace(-X_max, X_max, N)
V = np.zeros(N)
# Kinetic energy term (T) and potential energy term (V) in the Hamiltonian
T = -0.5 * hbar**2 / m / dx**2 * (np.diag(np.ones(N-1), -1) - 2 * np.diag(np.ones(N)) +
np.diag(np.ones(N-1), 1))
plt.figure(figsize=(12, 6))
plt.xlabel('x')
plt.ylabel('ψ(x)')
plt.legend()
plt.grid(True)
plt.figure(figsize=(12, 6))
a=0
plt.xlabel('x')
plt.ylabel('|ψ(x)|²')
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()
for i in range(4):
print(f"E_{i} = {eigenvalues[i]:.3f}")