import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse
from scipy.integrate import odeint
# --- 1. CONFIGURACIÓN DEL BARRIDO ---
alphas = np.linspace(-20, -5, 15)
psi_inits = np.linspace(0.01, 0.5, 15)
beta = 10.0
results_w0 = np.zeros((len(alphas), len(psi_inits)))
results_wa = np.zeros((len(alphas), len(psi_inits)))
# --- 2. BUCLE DE SIMULACIÓN ---
print(f"Simulating {len(alphas)*len(psi_inits)} universes...")
for i, alpha in enumerate(alphas):
for j, psi0 in enumerate(psi_inits):
psi_min = np.sqrt(-alpha / (2*beta))
V_shift = 0.7 - (alpha * psi_min**2 + beta * psi_min**4)
def Potential(p): return alpha * p**2 + beta * p**4 + V_shift
def dV_dpsi(p): return 2 * alpha * p + 4 * beta * p**3
def dynamics(y, t):
a, psi, pi = y
if a < 1e-5: a = 1e-5
rho_tot = 1e-4/a**4 + 0.3/a**3 + 0.5*pi**2 + Potential(psi)
H = np.sqrt(rho_tot)
return [a*H, pi, -3*H*pi - dV_dpsi(psi)]
sol = odeint(dynamics, [1e-3, psi0, 0.0], np.linspace(0, 1.0, 200))
# Extract w0, wa
a_now, psi_now, pi_now = sol[-1]
w0 = (0.5*pi_now**2 - Potential(psi_now)) / (0.5*pi_now**2 + Potential(psi_now))
a_prev, psi_prev, pi_prev = sol[-2]
w_prev = (0.5*pi_prev**2 - Potential(psi_prev)) / (0.5*pi_prev**2 + Potential(psi_prev))
wa = -((w0 - w_prev)/(a_now - a_prev)) * a_now
results_w0[i, j] = w0
results_wa[i, j] = wa
# --- 3. VISUALIZACIÓN ---
fig, ax = plt.subplots(figsize=(10, 7))
# Model Points
sc = ax.scatter(results_w0.flatten(), results_wa.flatten(), c=np.repeat(alphas, len(psi_inits)),
cmap='viridis', s=60, alpha=0.8, label='Dynamic Background Models')
plt.colorbar(sc, label=r'Mass Parameter $\alpha$')
# Planck 2018 Confidence Region (Approximate Ellipse)
# Center (-1, 0), Width 0.1, Height 0.6 (2-sigma approx)
ellipse = Ellipse((-1.0, 0.0), width=0.15, height=0.8, edgecolor='red', facecolor='none', lw=2, ls='--')
ax.add_patch(ellipse)
ax.plot(-1, 0, 'rx', markersize=10, label='Lambda-CDM')
# Formatting
ax.axvline(-1, color='gray', ls=':', alpha=0.5)
ax.axhline(0, color='gray', ls=':', alpha=0.5)
ax.set_xlabel(r'Current Equation of State ($w_0$)')
ax.set_ylabel(r'Evolution Parameter ($w_a$)')
ax.set_title('Theoretical Predictions vs. Observational Constraints')
ax.set_xlim(-1.05, -0.8)
ax.set_ylim(-1.0, 0.5)
ax.legend(loc='upper right')
ax.grid(True, alpha=0.3)
plt.show()