Ultimate Energy Galactic Energy Simulation

A star moves in the gravitational field of a galaxy (flat rotation curve). Energy flows between kinetic and potential as it swings in and out, but the total is conserved. Switch the integrator to see how numerical methods can create or destroy energy.

Multiplies how fast model time runs (physics step stays fixed).
The science

Potential. Logarithmic halo: Φ = ½v02 ln(Rc2 + x2 + y2/q2), which gives a nearly flat rotation curve vc = v0R/√(R2 + Rc2) at large R. q = 1 is round; q < 1 is flattened along y.

Equations of motion. a = −∇Φ: ax = −v02x/D, ay = −v02(y/q2)/D with D = Rc2 + x2 + y2/q2. Units: kpc, km/s; 1 kpc/(km/s) = 977.8 Myr.

Conserved quantities. Total energy E = ½v2 + Φ is always conserved (the potential is static). Angular momentum Lz = xvy − yvx is conserved only for q = 1; for q ≠ 1 the torque exchanges Lz and the orbit becomes a box or rosette shape.

Integrators. Leapfrog (kick–drift–kick) is symplectic: energy error stays bounded. Forward Euler multiplies the error each step and gains energy, so orbits spiral outward. RK4 is accurate per step but not symplectic, so it slowly drifts.

Independent check. The page launches a separate circular orbit (q = 1, v = vc) at your starting radius with a tiny time step and measures its period by tracking the accumulated angle; the analytic period is 2πR/vc.

Simplifications. One star as a test particle, a fixed smooth potential (no disk, bulge, spiral arms, dynamical friction or relativistic effects). The background galaxy picture is decorative. Default v0 = 220 km/s, Rc = 1 kpc are typical Milky-Way-like numbers.