Harmonic oscillator in phase space: with both quantum and field theoretic hamiltonian
PHYSICXION: Harmonic oscillator in phase space: with both quantum and field theoretic hamiltonian
Harmonic oscillator in phase space
Hamiltonian is defined as simple quantum harmonic oscillator.
CODE:
import numpy as np
import matplotlib.pyplot as plt
m=1 # mass of the quantum particle oscillating
H=np.array([0.5, 1, 1.5, 2]) # energy values
w=1
# Set canvas to 10 inches wide and 5 inches high
plt.figure(figsize=(7, 5))
for i in H:
q = np.linspace(-5,5,1000) # Generating q values to plot
p = np.sqrt(2*m*i - (m*w*q)**2) # Harmonic oscillator hamiltonian equation in terms of p as we will generate p values for known H and q
plt.plot(q,p, label=f"H = {i:.1f}") # Plot with energy levels
plt.plot(q,-p, color=plt.gca().lines[-1].get_color()) # Plot with energy levels as well as matching colors for -ve and +ve p
plt.title("Harmonic Oscillator Phase Space")
plt.xlabel("q")
plt.ylabel("p")
plt.legend(title="Energy Levels (H)", loc="upper right")
plt.grid()
plt.show()
OUTPUT:
Hamiltonian is defined as field theoretic quantum harmonic oscillator.
CODE:
import numpy as np
import matplotlib.pyplot as plt
H = np.array([0.5, 1, 1.5, 2]) # energy values
m = 1 # mass of the quantum particle oscillating
k = 1
w = np.sqrt(k**2 + m**2)
q = np.linspace(-6, 6, 1000) # Generating q values to plot
# Set canvas to 10 inches wide and 5 inches high
plt.figure(figsize=(7, 5))
for i in H:
p = np.sqrt(2*i - (w*q)**2) # Harmonic oscillator hamiltonian equation in terms of p as we will generate p values for known H and q
p[p.imag != 0] = np.nan
plt.plot(q, p, label=f"H = {i:.1f}") # Plot with energy levels
plt.plot(q, -p, color=plt.gca().lines[-1].get_color()) # Plot with energy levels as well as matching colors for -ve and +ve p
plt.title("Scalar Field Mode Phase Space")
plt.xlabel(r"$\phi_k$")
plt.ylabel(r"$\pi_k$")
plt.legend(title="Energy Levels (H)", loc="upper right")
plt.grid()
plt.show()
OUTPUT:
"These articles and the views expressed as notes are my own interpretations made to easily organize and simplify the complexity of higher studies and do not represent the official views of any professor or their institution. Collection of personal notes and ideas as portfolio"
.png)


Join the conversation