Beyond Regular Matter. Click here

⚠️ Stay Safe Online

This website will never ask for money or collect personal information in other ways online or offline. Stay vigilant and protect yourself from cyber fraud. No paid service is enabled here now. It's a personal blog and portfolio. Use this as a digital library made personally to support academic excellence. I'm currently unavailable due to personal circumstances and academic focus; this website is incomplete and will be updated after some period of time. I'm not focusing on anything else, not even on a personal blog now.

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
cover image of python for physics on website physicxion

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"