Thursday, 26 March 2026

Detecting the Invisible: A Python Simulation of Dark Matter

 

The "Missing Mass" Problem When astronomers use the Hubble Space Telescope to observe massive galaxy clusters, they encounter a startling discrepancy. By counting the stars and galaxies, we can calculate the Visible Mass (M_{vis}). However, when we measure the speed at which these galaxies orbit the cluster's center, they move far faster than the visible gravity should allow. This script uses the Orbital Velocity formula to reveal the "Mass Gap." According to the laws of gravitation, if a cluster is stable and not flying apart, the mass required to hold it together must be: Mass=vel**2 *R/G where vel= velocity R=radius G= universal gravitational constant The difference between this Mass and our calculated Mass is the physical proof of Dark Matter. The Python Implementation

import math

# Constants
G = 6.672e-11
LY_TO_M = 9.4e15 
AVG_STAR_MASS = 2e30

def get_velocity(m, r):
    """Returns escape velocity in m/s"""
    return math.sqrt(2 * G * m / r)

def get_mass_from_vel(v_kms, r_m):
    """Returns required mass in kg based on velocity in km/s"""
    v_ms = v_kms * 1000 # Convert km/s to m/s
    return (v_ms**2 * r_m) / (2 * G)

# Typical cluster data
clusters = {
    # nm: (galaxies, stars/gal, rad_ly, observed_vel_km_s)
    "A": (350, 10e09, 5e06, 300),
    "B": (1000, 10e09, 10e06, 140),
}

results = {}

for name, (gl, st, r_ly, act_vel) in clusters.items():
    # 1. Calculate Visible Mass
    mass_visible = gl * st * AVG_STAR_MASS
    radius_m = r_ly * LY_TO_M
    
    # 2. Calculate Theoretical Velocity (based on stars only)
    calc_vel = get_velocity(mass_visible, radius_m) / 1000 # convert to km/s
    
    # 3. Calculate Mass required to reach observed velocity
    mass_required = get_mass_from_vel(act_vel, radius_m)
    
    # 4. Find the difference (The "Dark Matter" or "Missing Mass")
    mass_diff = mass_required - mass_visible
    star_diff = mass_diff / AVG_STAR_MASS
    
    results[name] = {
        "visible_mass": mass_visible,
        "radius": radius_m,
        "calc_vel": calc_vel,
        "obs_vel": act_vel,
        "mass_diff": mass_diff,
        "star_diff": star_diff
    }

# --- Output Results ---
for nm, data in results.items():
    print(f"--- Galaxy Cluster: {nm} ---")
    print(f"Visible Mass:    {data['visible_mass']:.2e} kg")
    print(f"Radius:          {data['radius']:.2e} m")
    print(f"Calculated Vel:  {data['calc_vel']:.2f} km/s")
    print(f"Observed Vel:    {data['obs_vel']:.2f} km/s")
    
    if data['mass_diff'] > 0:
        print(f"STATUS: Underestimated! Missing gravity detected.")
        print(f"DARK MATTER REQ: {data['mass_diff']:.2e} kg ({data['star_diff']:.2e} stars worth)")
    elif data['mass_diff'] < 0:
        print(f"STATUS: Overestimated! Cluster has too much visible mass.")
        print(f"MASS TO SHED:    {abs(data['mass_diff']):.2e} kg ({abs(data['star_diff']):.2e} stars worth)")
    else:
        print("STATUS: Perfectly balanced (No Dark Matter needed).")
    print()
    
Please like this code. Everything is free to use

No comments:

Post a Comment

Visualizing Particle Kinematics with Python

Understanding the relationship between position, velocity, and acceleration is fundamental to physics. However, seeing how these variables e...