import numpy as np def schwarzschild_radius(mass, mass_unit): """Computes the Schwarzschild radius of an object. Parameters ---------- mass : float The mass of the object. mass_unit : str The unit of the mass. Must be one of "sun masses", "earth masses", or "kg". Returns ------- float or None The Schwarzschild radius in meters, or None if the input is invalid. """ G = 6.67430e-11 # Gravitational constant (m^3/kg/s^2) c = 299_792_458 # Speed of light (m/s) if mass_unit == "sun": mass_kg = mass * 1.988e30 elif mass_unit == "earth": mass_kg = mass * 5.972e24 elif mass_unit == "kg": mass_kg = mass else: print("Invalid mass unit. Please use 'sun', 'earth', or 'kg'.") return None if mass_kg <= 0: print("Mass must be positive.") return None radius = (2 * G * mass_kg) / (c**2) return radius # Example usage mass_sun = 1 # Solar mass radius_sun = schwarzschild_radius(mass_sun, "sun") print(f"Schwarzschild radius of the Sun: {radius_sun} meters") mass_earth = 1 # Earth mass radius_earth = schwarzschild_radius(mass_earth, "earth") print(f"Schwarzschild radius of the Earth: {radius_earth} meters") mass_kg = 1000 # Kilograms radius_kg = schwarzschild_radius(mass_kg, "kg") print(f"Schwarzschild radius of a 1000 kg object: {radius_kg} meters") import math def time_dilation(schwarzschild_radius, distance): """Calculates the time dilation factor near a black hole. Args: schwarzschild_radius: Schwarzschild radius of the black hole in meters. distance: Distance from the center of the black hole in meters. Returns: The time dilation factor. """ if distance <= schwarzschild_radius: return 0 # Time stops at and inside the event horizon else: return math.sqrt(1-(schwarzschild_radius / distance)) # Example usage rs = schwarzschild_radius(100_000_000, "sun") # Schwarzschild radius for a black hole distance = 2 * rs # Distance outside the event horizon t_0 = time_dilation(rs, distance) print(f"Time dilation factor: {t_0}")