Simulando a relatividade com ipywidgets e Python

Python Code: Interactive Interface

import numpy as np
import matplotlib.pyplot as plt
from ipywidgets import interact, FloatSlider

# Function for the modified equation
def modified_field(g_mu_nu, T):
    return 0.266 * g_mu_nu**2 + 2.446e-31 * T

# Function for local time (gravitational time dilation)
def local_time(R, global_time=1.0, alpha=1.0):
    return global_time / np.sqrt(1 + alpha * R)

# Interactive function
def simulate(g_mu_nu=1.0, T=1e30):
    R = modified_field(g_mu_nu, T)
    t_local = local_time(R)

    print(f"g_mu_nu = {g_mu_nu}")
    print(f"T = {T:.2e}")
    print(f"R = {R:.6f}")
    print(f"Local Time = {t_local:.6f} (Global Time = 1.0)")

# Interactive sliders
interact(simulate,
         g_mu_nu=FloatSlider(value=1.0, min=0.1, max=5.0, step=0.1, description='g_mu_nu'),
         T=FloatSlider(value=1e30, min=1e28, max=1e32, step=1e29, description='T')
);

Simulate the modified equation with g=80% and T=20% and show the dynamics.

1 Like