physics-simulation / potentials.py
j25aiml013's picture
Upload 16 files
05354e5 verified
Raw History Blame Contribute Delete
1.09 kB
import numpy as np
from .constants import E_CHARGE, COULOMB_CONSTANT
# ------------------------------------------------------
# Infinite Square Well (Particle in a Box)
# ------------------------------------------------------
def potential_infinite_well(x: np.ndarray, L: float) -> np.ndarray:
V = np.zeros_like(x)
V[x < 0] = np.inf
V[x > L] = np.inf
return V
# ------------------------------------------------------
# Harmonic Oscillator: V(x) = 1/2 m ω² x²
# ------------------------------------------------------
def potential_harmonic(x: np.ndarray, mass: float, omega: float) -> np.ndarray:
return 0.5 * mass * omega**2 * x**2
# ------------------------------------------------------
# Coulomb Potential for Hydrogen Atom
# ------------------------------------------------------
def potential_hydrogen_1d(x: np.ndarray) -> np.ndarray:
"""
1D radial approximation:
V(r) = - (k e²) / r
"""
x = np.where(x == 0, 1e-12, x) # avoid singularity
return -(COULOMB_CONSTANT * E_CHARGE**2) / np.abs(x)