{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The velocities of the globular cluster, elliptical galaxy and cluster of galaxy are 4.145965 km/s, 131.106934 km/s and 293.164016 km/s, respectively\n",
      "The cross times of the globular cluster, elliptical galaxy and cluster of galaxy are 1.180e+06 yr, 3.732e+07 yr and 3.338e+09 yr, respectively\n",
      "The relax times of the globular cluster, elliptical galaxy and cluster of galaxy are 1.818e+09 yr, 2.525e+16 yr and 1.764e+21 yr, respectively\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "mSun = 1.988e33  #g\n",
    "kpc = 3.08568e21  #cm\n",
    "yr = 31536000  # s\n",
    "G = 6.67e-8\n",
    "\n",
    "M_star = np.array([1e5 * mSun, 1e11 * mSun, 1e14 * mSun])  # mass of globular cluster, elliptical galaxy and cluster of galaxy   \n",
    "Re = np.array([5e-3 * kpc, 5 * kpc, 1e3 * kpc])  # Re of globular cluster, elliptical galaxy and cluster of galaxy\n",
    "m_star = 1 * mSun  # average mass of a single star\n",
    "N = M_star / m_star  # total number of stars\n",
    "\n",
    "v_disp = np.sqrt(G * M_star / (5 * Re))\n",
    "print(\"The velocities of the globular cluster, elliptical galaxy and cluster of galaxy are %f km/s, %f km/s and %f km/s, respectively\" %(v_disp[0]/1e5, v_disp[1]/1e5, v_disp[2]/1e5))\n",
    "\n",
    "t_cross = Re / v_disp\n",
    "print(\"The cross times of the globular cluster, elliptical galaxy and cluster of galaxy are %.3e yr, %.3e yr and %.3e yr, respectively\" %(t_cross[0]/yr, t_cross[1]/yr, t_cross[2]/yr))\n",
    "\n",
    "t_relax = t_cross * N / (6 * np.log(N/2))\n",
    "print(\"The relax times of the globular cluster, elliptical galaxy and cluster of galaxy are %.3e yr, %.3e yr and %.3e yr, respectively\" %(t_relax[0]/yr, t_relax[1]/yr, t_relax[2]/yr))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 星系团的基本粒子是星系"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "银河系角动量自旋参数约为0.026327744609446257\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "mSun = 1.988e33  # g\n",
    "kpc = 3.08568e21  # cm\n",
    "G = 6.67e-8\n",
    "\n",
    "M_tot = 1.5e12 * mSun\n",
    "M_star = 5e10 * mSun\n",
    "M_gas = 0.15 * M_star\n",
    "M_d = M_star + M_gas\n",
    "m_d = M_d / M_tot\n",
    "\n",
    "R_d = 3 * kpc\n",
    "V_c = 200 * 1e5  \n",
    "J_d = 2 * M_d * R_d * V_c\n",
    "J = J_d / m_d\n",
    "\n",
    "E_tot = - 0.5 * M_tot * pow(V_c, 2)\n",
    "\n",
    "spin = J * np.sqrt(np.abs(E_tot)) * pow(M_tot, -2.5) / G\n",
    "print(\"银河系角动量自旋参数约为%s\" %spin)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
