{
 "metadata": {
  "name": "",
  "signature": "sha256:3790a3d51914dcd136e5ca3ce886512d33fbd8ae15c97de507356c2c79104f21"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 16: Cosmology and Modern Astrophysics - The Beginning and the End"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16.1, Page 581"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "H0 = 22;    # Value of Hubble constant, km/s per million ly\n",
      "parsec = 3.26;    # The value of 1 parsec, light years\n",
      "\n",
      "#Calculations&Result\n",
      "print \"The value of Hubble constant = %d km/s per Mpc\"%math.ceil(H0*parsec)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of Hubble constant = 72 km/s per Mpc\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16.2, Page 583"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "M = 1;    # Let the current mass of the universe be unity\n",
      "m_u = 1;    # Mass equivalent of 1 amu, u\n",
      "N_n = 2;    # Number of neutrons in helium\n",
      "N_p = 2;    # Number of protons in helium\n",
      "\n",
      "#Calculations\n",
      "M_p = 0.75*M*m_u;    # Total mass of protons\n",
      "M_He = 0.25*M*m_u;    # Total mass of helium\n",
      "N_fp = M_p/M_He*(N_n + N_p);    # Total number of free protons for every He-4\n",
      "N_P = N_fp + N_p;    # Total number of protons per He-4\n",
      "ratio = N_P/N_n;    # Current ratio of protons to the neutrons in the universe\n",
      "\n",
      "#Result\n",
      "print \"The current ratio of protons to the neutrons in the universe = %d\"%ratio"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The current ratio of protons to the neutrons in the universe = 7\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16.3, Page 607"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "m_n = 939.566;    # Rest mass of the neutron, MeV/c^2\n",
      "m_p = 938.272;    # Rest mass of the proton, MeV/c^2\n",
      "e = 1.6e-019;    # Energy equivalent of 1 eV, J\n",
      "c = 1;    # For simplicity assume speed of light of light to be unity\n",
      "T = 1e+010;    # Temperature of the universe, K\n",
      "\n",
      "#Calculations\n",
      "delta_m = m_n - m_p;    # Mass difference between a proton and a neutron, MeV/c^2\n",
      "k = 1.38e-023;    # Boltzmann constant, J/k\n",
      "# As from Maxwell-Boltzmann distribution from thermodynamics, N = exp(-m*c^2/(k*T)), so\n",
      "ratio = math.exp(delta_m*c**2*1e+006*e/(k*T));    # Ratio of protons to neutrons in the universe at 10 billion kelvin\n",
      "\n",
      "#Result\n",
      "print \"The ratio of protons to neutrons in the universe at 10 billion kelvin = %3.1f\"%ratio"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The ratio of protons to neutrons in the universe at 10 billion kelvin = 4.5\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16.4, Page 589"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "M = 1.99e+030;    # Mass of the sun, kg\n",
      "G = 6.67e-011;    # Universal gravitational constant, N-Sq.m/kg^2\n",
      "k = 1.38e-023;    # Boltzmann constant, J/K\n",
      "R = 6.96e+008;    # Radius of the sun, m\n",
      "m = 1.67e-027;    # Rest mass of the proton, kg\n",
      "\n",
      "#Calculations\n",
      "PE = 3./5*(G*M**2/R);    # Self potential energy of the sun, J\n",
      "# As KE = 1./3*(M/m_p)*m_p*v**2, solving for v\n",
      "v = math.sqrt(2*PE/M);    # Velocity of a proton inside the sun, m/s\n",
      "# From kinetic theory of gases, v = sqrt(3*k*T/m), solving for T\n",
      "T = m*v**2/(3*k);    # The mean temperature of the sun, K\n",
      "\n",
      "#Result\n",
      "print \"The mean temperature of the sun = %1.0e K\"%T"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The mean temperature of the sun = 9e+06 K\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16.5, Page 590"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "M_sun = 1.99e+030;    # Mass of the sun, kg\n",
      "m_n = 1.675e-027;    # Rest mass of the neutron, kg\n",
      "h = 6.62e-034;    # Planck's constant, Js\n",
      "\n",
      "#Calculations\n",
      "h_bar = h/(2*math.pi);    # Planck's constant, Js\n",
      "G = 6.67e-011;    # Universal gravitational constant, N-Sq.m/kg^2\n",
      "N = 2*M_sun/m_n;    # Number of neutrons in the neutron star\n",
      "V = (6.5*h_bar**2/(N**(1./3)*m_n**3*G))**3;    # Volume of the neutron star, metre cube\n",
      "R = (3./(4*math.pi)*V)**(1./3);    # The radius of neutron star, m\n",
      "\n",
      "#Result\n",
      "print \"The radius of the neutron star of 2 solar masses = %d km\"%math.ceil(R/1e+003)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The radius of the neutron star of 2 solar masses = 11 km\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16.7, Page 598"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "c = 1;    # For simplicity assume speed of light to be unity, m/s\n",
      "d = 1.6e+005;    # Distance of the supernova 1987A from the earth, ly\n",
      "m = 16;    # Mass of heavier neutrino, eV/c^2;\n",
      "E = 20e+006;    # Energy of the neutrino, eV\n",
      "\n",
      "#Calculations\n",
      "delta_t = d/(2*c)*(m/E)**2;    # Difference between the travel times of the lighter and the massive neutrinos, y\n",
      "\n",
      "#Result\n",
      "print \"The difference between the travel times of the lighter and the massive neutrinos = %3.1f s\"%(delta_t*(365.25*24*60*60))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The difference between the travel times of the lighter and the massive neutrinos = 1.6 s\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16.8, Page 602"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "c = 3.00e+008;    # Speed of light, m/s\n",
      "H = 22;    # Hubble constant, km/s per million ly\n",
      "G = 6.67e-011;    # Universal gravitational constant, N-Sq.m/kg^2\n",
      "\n",
      "#Calculations\n",
      "rho_c = 3/(8*math.pi)*H**2/G*1e+003/(c*365.25*24*60*60*1e+006)**2;    # The critical density of the universe, g/cc\n",
      "\n",
      "#Result\n",
      "print \"The critical density of the universe = %3.1e g/cc\"%rho_c"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The critical density of the universe = 9.7e-30 g/cc\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 16.9, Page 604"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "H0 = 71;    # Hubble constant, km/s per Mpc\n",
      "\n",
      "#Calculations\n",
      "tau = 1./H0*1e+006*3.26*9.46e+012/3.16e+007;    # The upper limit of the age of the universe, y\n",
      "\n",
      "#Result\n",
      "print \"The upper limit of the age of the universe = %4.2e y\"%tau"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The upper limit of the age of the universe = 1.37e+10 y\n"
       ]
      }
     ],
     "prompt_number": 8
    }
   ],
   "metadata": {}
  }
 ]
}