{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [], "authorship_tag": "ABX9TyNEkM4BrRyFzrD//jPwa7cY", "include_colab_link": true }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "metadata": { "id": "view-in-github", "colab_type": "text" }, "source": [ "<a href=\"https://colab.research.google.com/github/ThomasAlbin/Astroniz-YT-Tutorials/blob/main/CompressedCosmos/CompressedCosmos_SchwarzschildRadius.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "id": "SP_LaDX-Xx4Z", "outputId": "b36e47ba-b027-4e53-bbfc-8ed10c601698", "colab": { "base_uri": "https://localhost:8080/" } }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Schwarzschild radius of the Sun: 2952.641323001581 meters\n", "Schwarzschild radius of the Earth: 0.008869805825435334 meters\n", "Schwarzschild radius of a 1000 kg object: 1.4852320538237329e-24 meters\n" ] } ], "source": [ "import numpy as np\n", "\n", "def schwarzschild_radius(mass, mass_unit):\n", " \"\"\"Computes the Schwarzschild radius of an object.\n", "\n", " Parameters\n", " ----------\n", " mass : float\n", " The mass of the object.\n", " mass_unit : str\n", " The unit of the mass. Must be one of \"sun masses\", \"earth masses\", or \"kg\".\n", "\n", " Returns\n", " -------\n", " float or None\n", " The Schwarzschild radius in meters, or None if the input is invalid.\n", " \"\"\"\n", " G = 6.67430e-11 # Gravitational constant (m^3/kg/s^2)\n", " c = 299_792_458 # Speed of light (m/s)\n", "\n", " if mass_unit == \"sun\":\n", " mass_kg = mass * 1.988e30\n", " elif mass_unit == \"earth\":\n", " mass_kg = mass * 5.972e24\n", " elif mass_unit == \"kg\":\n", " mass_kg = mass\n", " else:\n", " print(\"Invalid mass unit. Please use 'sun', 'earth', or 'kg'.\")\n", " return None\n", "\n", " if mass_kg <= 0:\n", " print(\"Mass must be positive.\")\n", " return None\n", "\n", " radius = (2 * G * mass_kg) / (c**2)\n", " return radius\n", "\n", "# Example usage\n", "mass_sun = 1 # Solar mass\n", "radius_sun = schwarzschild_radius(mass_sun, \"sun\")\n", "print(f\"Schwarzschild radius of the Sun: {radius_sun} meters\")\n", "\n", "mass_earth = 1 # Earth mass\n", "radius_earth = schwarzschild_radius(mass_earth, \"earth\")\n", "print(f\"Schwarzschild radius of the Earth: {radius_earth} meters\")\n", "\n", "mass_kg = 1000 # Kilograms\n", "radius_kg = schwarzschild_radius(mass_kg, \"kg\")\n", "print(f\"Schwarzschild radius of a 1000 kg object: {radius_kg} meters\")" ] }, { "cell_type": "code", "source": [ "import math\n", "\n", "def time_dilation(schwarzschild_radius, distance):\n", " \"\"\"Calculates the time dilation factor near a black hole.\n", "\n", " Args:\n", " schwarzschild_radius: Schwarzschild radius of the black hole in meters.\n", " distance: Distance from the center of the black hole in meters.\n", "\n", " Returns:\n", " The time dilation factor.\n", " \"\"\"\n", " if distance <= schwarzschild_radius:\n", " return 0 # Time stops at and inside the event horizon\n", " else:\n", " return math.sqrt(1-(schwarzschild_radius / distance))\n", "\n", "# Example usage\n", "rs = schwarzschild_radius(100_000_000, \"sun\") # Schwarzschild radius for a black hole\n", "distance = 2 * rs # Distance outside the event horizon\n", "t_0 = time_dilation(rs, distance)\n", "print(f\"Time dilation factor: {t_0}\")" ], "metadata": { "id": "qwRxoCwsu_Us", "outputId": "d94a4f76-333c-4332-ff24-ba26a9892147", "colab": { "base_uri": "https://localhost:8080/" } }, "execution_count": 27, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Time dilation factor: 0.7071067811865476\n" ] } ] } ] }