Untitled
unknown
plain_text
2 months ago
1.5 kB
1
Indexable
import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation # Define the number of galaxies num_galaxies = 10 # Initial positions of galaxies in a 1D space initial_positions = np.linspace(-10, 10, num_galaxies) # Time steps for the animation timesteps = 50 # Expansion factors for two universes no_dark_energy_factor = np.linspace(1, 2, timesteps) # Slower expansion dark_energy_factor = np.exp(np.linspace(0, 1, timesteps)) # Accelerating expansion # Function to calculate new positions def expand_universe(initial_positions, expansion_factor): return np.outer(initial_positions, expansion_factor) # Calculate positions over time positions_no_dark_energy = expand_universe(initial_positions, no_dark_energy_factor) positions_dark_energy = expand_universe(initial_positions, dark_energy_factor) # Create the figure and axis fig, ax = plt.subplots(1, 2, figsize=(12, 5)) # Function to update animation def update(frame): ax[0].clear() ax[1].clear() ax[0].scatter(positions_no_dark_energy[:, frame], np.zeros(num_galaxies), color='blue') ax[0].set_title("Universe Without Dark Energy (Matter-Only)") ax[0].set_xlim(-25, 25) ax[0].set_ylim(-1, 1) ax[1].scatter(positions_dark_energy[:, frame], np.zeros(num_galaxies), color='red') ax[1].set_title("Universe With Dark Energy (Accelerating Expansion)") ax[1].set_xlim(-50, 50) ax[1].set_ylim(-1, 1) # Create animation ani = animation.FuncAnimation(fig, update, frames=timesteps, interval=100) plt.show()
Editor is loading...
Leave a Comment