Spaces:
Sleeping
Sleeping
Download potentials.py from j25aiml013/physics-simulation: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/j25aiml013/physics-simulation/resolve/main/potentials.py
- Command line
-
hf download hf://spaces/j25aiml013/physics-simulation/potentials.py
-
curl -L -o potentials.py https://huggingface.co/spaces/j25aiml013/physics-simulation/resolve/main/potentials.py
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) | |