{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 2 : Maxwell's Equations and Electromagnetic Waves"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.8,Page Number 112"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "magnetic field in region 2 in A/m: [ 2.4  1.5 -3. ]\n",
      "magnitude of magnetic field in region 2 in A/m: 4.124\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "import numpy as np\n",
    "from math import pi\n",
    "\n",
    "#variable delaration\n",
    "mu_0 = 4*pi*10**(-7)  #  permeability in free space\n",
    "mu_r1 = 3  #  region 1 relative permeability\n",
    "mu_r2 = 5  #  region 2 relative permeability\n",
    "mu_1 = mu_r1*mu_0  #  region 1 permeability\n",
    "mu_2 = mu_r2*mu_0  #  region 2 permeability\n",
    "\n",
    "#calculations\n",
    "H1  = np.array([4,1.5,-3])  #  magnetic field in region 1 in A/m\n",
    "Ht1 = np.array([0,1.5,-3])  #  tangential component of magnetic field H1\n",
    "Hn1 = np.array([4,0,0])     #  normal component of magnetic field H1\n",
    "Ht2 = np.array([0,1.5,-3])  #  as tangential componenet of magnetic field H2 = tangential component of magnetic field H1\n",
    "Hn2 = (mu_1/mu_2)*Hn1       #  normal component of magnetic field H2\n",
    "H2  = Ht2+Hn2               #  magnetic field in region 2 in A/m\n",
    "h2  = np.linalg.norm(H2)    #  magnitude of the magnetic field H2 in A/m\n",
    "\n",
    "#results\n",
    "print \"magnetic field in region 2 in A/m:\",np.around(H2,2)\n",
    "print \"magnitude of magnetic field in region 2 in A/m:\",round(h2,3) \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.9,Page Number 113"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "electric field in region 2 in V/m: [ 0.5  2.   3. ]\n",
      "electric flux density in region 2 in C/m**2: [  8.85400000e-12   3.54160000e-11   5.31240000e-11]\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "import numpy as np\n",
    "\n",
    "#variable Declaration\n",
    "epsilon_0 = 8.854*10**(-12) # permittivity in free space\n",
    "sigma_1 = 0 #conductivity of medium 1\n",
    "sigma_2 = 0 #conductivity of medium 2\n",
    "epsilon_r1 = 1 # region 1 relative permittivity\n",
    "epsilon_r2 = 2 # region 2 relative permittivity\n",
    "\n",
    "#calculations\n",
    "epsilon_1 = epsilon_r1*epsilon_0 # region 1 permittivity\n",
    "epsilon_2 = epsilon_r2*epsilon_0 # region 2 permittivity\n",
    "E1  = np.array([1,2,3])  # Electric field in region 1 in V/m\n",
    "Et1 = np.array([0,2,3])  # tangential component of electric field E1\n",
    "En1 = np.array([1,0,0])  # normal component of electric field E1\n",
    "Et2 = np.array([0,2,3])  # as tangential componenet of electric field E2 = tangential component of electric field E1\n",
    "En2 = (epsilon_1/epsilon_2)*En1 # normal component of electric field E2\n",
    "E2  = Et2+En2 # electric field in region 2 in V/m\n",
    "Dt1 = epsilon_0*Et1  # tangential component of electric flux density D1\n",
    "D2  = epsilon_2*E2   # electric flux density in region 2 in C/m**2\n",
    "\n",
    "\n",
    "#Results\n",
    "print \"electric field in region 2 in V/m:\",np.around(E2,2)\n",
    "print \"electric flux density in region 2 in C/m**2:\",D2 \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.12,Page Number 116"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "eta_0 =  E/H  =  377*cos(10**8*t-Beta*z)/cos(10**8*t-Beta*z)  = > E/H = 377\n",
      "intrinsic impedence in ohm: 377\n",
      "frequency in MHz: 15.915\n",
      "phase constant in rad/m: 0.333\n",
      "wavelength in m: 18.85\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "import numpy as np\n",
    "from math import pi\n",
    "\n",
    "#variable Declaration\n",
    "\n",
    "#  H = cos(10**8*t-Beta*z)ay       #  magnetic field in A/m\n",
    "#  E = 377*cos(10**8*t-Beta*z)ax   #  electric field in V/m\n",
    "omega = 10**8    #  angular frequency in Hz\n",
    "v_0 = 3*10**8    #  speed of light in m/s\n",
    "\n",
    "\n",
    "#calculations\n",
    "f = omega/(2*pi) #  frequency in Hz\n",
    "lamda = v_0/f    #  wavelength in m\n",
    "Beta = (2*pi)/lamda #  phase constant in rad/m\n",
    "print \"eta_0 =  E/H  =  377*cos(10**8*t-Beta*z)/cos(10**8*t-Beta*z)  = > E/H = 377\"\n",
    "eta_0 = abs(377) #  intrinsic impedence in ohm\n",
    "\n",
    "\n",
    "\n",
    "#Results\n",
    "print \"intrinsic impedence in ohm:\",eta_0\n",
    "print \"frequency in MHz:\",round(f/(10**6),3)\n",
    "print \"phase constant in rad/m:\",round(Beta,3)\n",
    "print \"wavelength in m:\",round(lamda,3)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.14,Page Number 116"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "propagation constant in m**-1: 2.094j\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "import numpy as np\n",
    "\n",
    "#Variable Declaration\n",
    "f = 100        #  frequency in MHz\n",
    "f = 100*10**6  #  frequency in Hz\n",
    "v_0=3*10**8    #  speed of light in m/s\n",
    "\n",
    "\n",
    "#  formula : Gamma = omega(j)*sqrt(mu_0*epsilon_0)=omega(j)/v_0 =(2j*pi*f)/v_0\n",
    "Gamma =(2j*pi*f)/(v_0)  # propagation constant\n",
    "\n",
    "\n",
    "#result\n",
    "print \"propagation constant in m**-1:\",np.around(Gamma,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.15,Page Number 116"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "amplitude of the magnetic field in A/m: 48\n",
      "frequency in MHz: 15.915\n",
      "phase constant in rad/m: 40.0\n",
      "wavelength in m: 0.157\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "\n",
    "#Variable Declaration\n",
    "\n",
    "# H(z,t) =  48*cos(10**8*t+40*z)ay  #  equation of magnetic field \n",
    "A = 48  #  amplitude of the magnetic field in A/m\n",
    "omega = 10**8  #  angular frequency in radians/sec\n",
    "Beta = 40  #  phase constant in rad/m\n",
    "\n",
    "#Calculations\n",
    "f = omega/(2*pi)  #  frequency in Hz\n",
    "lamda = (2*pi)/Beta  #  wavelength in m\n",
    "\n",
    "\n",
    "#results\n",
    "print \"amplitude of the magnetic field in A/m:\",A\n",
    "print \"frequency in MHz:\",round(f/10**6,3)\n",
    "print \"phase constant in rad/m:\",round(Beta,3)\n",
    "print \"wavelength in m:\",round(lamda,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.16,Page Number 117"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "magnitude of electric field in V/m in free space: 753.982\n",
      "magnitude of electric field in V/m: 376.734\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi,sqrt\n",
    "\n",
    "#Variable Declaration\n",
    "\n",
    "H = 2  #  ampliutude of magnetic field in A/m\n",
    "sigma = 0  #  conductivity\n",
    "mu_0 = 4*pi*10**-7  #  permeability in free space in H/m\n",
    "epsilon_0 = 8.854*10**-12  #  permittivity in free space in F/m\n",
    "\n",
    "#calculations\n",
    "mu = mu_0  #  permeability in F/m\n",
    "epsilon = 4*epsilon_0  #  permittivity in F/m\n",
    "Eta_0 = 120*pi  #  intrinsic impedence in free space in ohm\n",
    "E_free = Eta_0*H  #  electric field in V/m\n",
    "\n",
    "\n",
    "#results\n",
    "print \"magnitude of electric field in V/m in free space:\",round(E_free,3)\n",
    "Eta = sqrt(mu/epsilon)  #  intrinsic impedence in ohm\n",
    "E = Eta*H  #  magnitude of electric field\n",
    "print \"magnitude of electric field in V/m:\",round(E,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.17,Page Number 117"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "propagation constant im m**-1: 18.862j\n",
      "intrinsic impedence in ohm: 125.578\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi,sqrt\n",
    "import numpy as np\n",
    "\n",
    "\n",
    "#variable Declaration\n",
    "\n",
    "sigma = 0  #  conductivity in mho/m\n",
    "f = 0.3  #  frequency in GHz\n",
    "f = 0.3*10**9  #  frequency in Hz\n",
    "omega = 2*pi*f  #  angular frequency in rad/sec\n",
    " #  formula : Gamma = sqrt(1j*omega*mu*(sigma+1j*omega*epsilon)) = 1j*omega*sqrt(mu*epsilon)\n",
    "epsilon_0 = 8.854*10**-12  #  permittivity in free space in F/m\n",
    "epsilon = 9*epsilon_0  #  permittivity in F/m\n",
    "mu_0 = 4*pi*10**-7  #   permeability in free space in H/m\n",
    "mu = mu_0  #  permeability in H/m\n",
    "Gamma = 1j*omega*sqrt(mu*epsilon)  #  propagation constant im m**-1\n",
    "\n",
    "\n",
    "#results\n",
    "\n",
    "print \"propagation constant im m**-1:\",np.around(Gamma,3)\n",
    " #  formula : eta = sqrt((1j*omega*mu)/(sigma+omega*epsilon)) = sqrt(mu/epsilon)\n",
    "eta = sqrt(mu_0/(9*epsilon_0))  #  intrinsic impedence in ohm\n",
    "print \"intrinsic impedence in ohm:\",round(eta,3)\n",
    "\n",
    "\n",
    "\n",
    "# note : answer in the book is wrong.\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.18,Page Number 118"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "frequecy in MHz: 600.0\n",
      "relative permittivity: 4.0\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi\n",
    "\n",
    "#variable declaration\n",
    "\n",
    "lamda = 0.25    #  wavelength in m\n",
    "v = 1.5*10**10  #  velocity of propagation of wave in cm/sec\n",
    "v = 1.5*10**8   #  velocity of propagation of wave in m/sec\n",
    "epsilon_0 = 8.854*10**-12  #  permittivity in free space in F/m\n",
    "mu_0 = 4*pi*10**-7         #   permeability in free space in H/m\n",
    "mu = mu_0      #  permeability in H/m\n",
    "v_0 = 3*10**8  #  speed of light in m/s\n",
    "f = v/lamda     #  frequency in Hz\n",
    " #  formula : v = 1/(mu*epsilon) = 1/(mu_0*epsilon_0*epsilon_r) = v_0/sqrt(epsilon_r)\n",
    "epsilon_r = (v_0/v)**2  #  relative permittivity\n",
    "\n",
    "\n",
    "#results\n",
    "print \"frequecy in MHz:\",round(f/10**6,3)\n",
    "print \"relative permittivity:\",epsilon_r\n",
    "\n",
    "\n",
    " # note : answer in the book is wrong.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.19,Page Number 118"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "frequency in MHz: 15.915\n",
      "phase constant in rad/m: 4.0\n",
      "wavelength in m: 18.85\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi\n",
    "\n",
    "#variable declaration and calculations\n",
    "\n",
    "#E = 5*sin(10**8*t+4*x)az  #  equation of electric field \n",
    "\n",
    "A = 5  #  amplitude of the electric field\n",
    "omega = 10**8  #  angular frequency in radians/sec\n",
    "f = omega/(2*pi)  #  frequency in Hz\n",
    "Beta = 4  #  phase constant in rad/m\n",
    "v_0 = 3*10**8  #  speed of light in m/s\n",
    "lamda = v_0/f  #  wavelength in m\n",
    "\n",
    "\n",
    "#results\n",
    "print \"frequency in MHz:\",round(f/10**6,3)\n",
    "print \"phase constant in rad/m:\",round(Beta,3)\n",
    "print \"wavelength in m:\",round(lamda,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.20,Page Number 119"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "When frequency = 50Hz:\n",
      "K1 is equal to 360000.0\n",
      "since k1>>1 hence it behaves like a good conductor:\n",
      "When frequency = 1kHz:\n",
      "K2 is equal to 18000.0\n",
      "since k2>>1 hence it behaves like a good conductor:\n",
      "When frequency = 1MHz:\n",
      "K3 is equal to 18.0\n",
      "since k3 = 18 hence it behaves like a moderate conductor:\n",
      "When frequency = 100MHz:\n",
      "K4 is equal to 0.18\n",
      "since k4 = 0.18 hence it behaves like a quasi-dielectric:\n",
      "When frequency = 10GHz:\n",
      "K5 is equal to 0.0018\n",
      "since k5<<1 hence it behaves like a good dielectric:\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi\n",
    "\n",
    "sigma = 10**-2  #  conductivity of earth in mho/m\n",
    "epsilon_r = 10  #  relative permittivity\n",
    "mu_r = 2  #  relative permeability\n",
    "epsilon_0 = (1/(36*pi))*10**-9  #  permittivity in free space\n",
    "epsilon = epsilon_r*epsilon_0  #  permittivity\n",
    "f1 = 50  #  frequency in Hz\n",
    "omega1 = 2*pi*f1  #  angular frequency in rad/sec\n",
    "print \"When frequency = 50Hz:\"\n",
    "k1 = sigma/(omega1*epsilon)\n",
    "print \"K1 is equal to\",k1\n",
    "print \"since k1>>1 hence it behaves like a good conductor:\"\n",
    "f2 = 1  #  frequency in kHz\n",
    "f2 = 1*10**3  #  frequency in Hz\n",
    "omega2 = 2*pi*f2  #  angular frequency in rad/sec\n",
    "print \"When frequency = 1kHz:\"\n",
    "k2 = sigma/(omega2*epsilon)\n",
    "print \"K2 is equal to\",k2\n",
    "print \"since k2>>1 hence it behaves like a good conductor:\"\n",
    "f3 = 1  #  frequency in MHz\n",
    "f3 = 1*10**6  #  frequency in Hz\n",
    "omega3 = 2*pi*f3  #  angular frequency in rad/sec\n",
    "print \"When frequency = 1MHz:\"\n",
    "k3 = sigma/(omega3*epsilon)\n",
    "print \"K3 is equal to\",k3\n",
    "print \"since k3 = 18 hence it behaves like a moderate conductor:\"\n",
    "f4 = 100  #  frequency in MHz\n",
    "f4 = 100*10**6  #  frequency in Hz\n",
    "omega4 = 2*pi*f4  #  angular frequency in rad/sec\n",
    "print \"When frequency = 100MHz:\"\n",
    "k4 = sigma/(omega4*epsilon)\n",
    "print \"K4 is equal to\",k4\n",
    "print \"since k4 = 0.18 hence it behaves like a quasi-dielectric:\"\n",
    "f5 = 10  #  frequency in GHz\n",
    "f5 = 10*10**9  #  frequency in Hz\n",
    "omega5 = 2*pi*f5  #  angular frequency in rad/sec\n",
    "print \"When frequency = 10GHz:\"\n",
    "k5 = sigma/(omega5*epsilon)\n",
    "print \"K5 is equal to\",k5\n",
    "print \"since k5<<1 hence it behaves like a good dielectric:\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.21,Page Number 120"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ratio k is equal to 1.73763020468e+16\n",
      "since k>>1 therefore it is very good conductor:\n",
      "attenuation constant in m**-1: 117.21\n",
      "phase constant in m**-1: 117.21\n",
      "propagation constant in m**-1: (117.21+117.21j)\n",
      "intrinsic impedence in ohm: (2.0209e-06+2.0209e-06j)\n",
      "wavelength in cm: 5.36\n",
      "phase velocity of wave in m/s: 3.216\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi\n",
    "import cmath\n",
    "import numpy as np\n",
    "\n",
    "#variable declaration\n",
    "f = 60  # frequency in Hz\n",
    "omega = 2*pi*f  # angular frequency in rad/sec\n",
    "sigma = 5.8*10**7  # conductivity in mho/m\n",
    "epsilon_0 = 8.854*10**-12  # permittivity in free space in F/m\n",
    "mu_0 = 4*pi*10**-7  #  permeability in free space in H/m\n",
    "epsilon_r = 1  # relative permittivity\n",
    "mu_r = 1  # relative permeability\n",
    "\n",
    "\n",
    "#calculations\n",
    "epsilon = epsilon_r*epsilon_0  # permittivity\n",
    "mu = mu_0*mu_r  # permeability\n",
    "k = sigma/(omega*epsilon)  # ratio\n",
    "print \"ratio k is equal to\",k\n",
    "print \"since k>>1 therefore it is very good conductor:\"\n",
    "alpha = sqrt(omega*mu*sigma/2)  # attenuation constant in m**-1\n",
    "Beta = sqrt(omega*mu*sigma/2)  # phase constant in m**-1\n",
    "Gamma = alpha+(1j*Beta)  # propagation constant in m**-1\n",
    "lamda = (2*pi)/Beta  # wavelength\n",
    "eta = cmath.sqrt(((1j*omega*mu)/sigma))  # intrinsic impedence in ohm\n",
    "v = lamda*f  # phase velocity of wave in m/s\n",
    "\n",
    "\n",
    "#result\n",
    "print \"attenuation constant in m**-1:\",round(alpha,2)\n",
    "print \"phase constant in m**-1:\",round(Beta,2)\n",
    "print \"propagation constant in m**-1:\",np.around(Gamma,2)\n",
    "print \"intrinsic impedence in ohm:\",np.around(eta,10)\n",
    "print \"wavelength in cm:\",round(lamda*100,2)\n",
    "print \"phase velocity of wave in m/s:\",round(v,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.22,Page Number 120"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "At f = 60Hz\n",
      "ratio k is equal to 1.73763020468e+16\n",
      "since k>>1 therefore it is very good conductor at f = 60Hz:\n",
      "depth of penetration delta1 in m: 0.00853160047351\n",
      "At f = 100Hz\n",
      "ratio k is equal to 10425781228.1\n",
      "since k2>>1 therefore it is very good conductor at f = 100Hz:\n",
      "depth of penetration delta2 in m: 6.60854931008e-06\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi\n",
    "\n",
    "\n",
    "#variable Declaration\n",
    "\n",
    "f1 = 60  #  frequency in Hz\n",
    "omega1 = 2*pi*f1  #  angular frequency in Hz\n",
    "f2 = 100          #  frequency in MHz\n",
    "f2 = 100*10**6    #  frequency in Hz\n",
    "omega2 = 2*pi*f2  #  angular frequency in Hz\n",
    "sigma = 5.8*10**7 #  conductivity in mho/m\n",
    "epsilon_0 = 8.854*10**-12  #  permittivity in free space in F/m\n",
    "mu_0 = 4*pi*10**-7         #  permeability in free space in H/m\n",
    "epsilon_r = 1    #  relative permittivity\n",
    "mu_r = 1         #  relative permeability\n",
    "epsilon = epsilon_r*epsilon_0  #  permittivity\n",
    "mu = mu_0*mu_r   #  permeability\n",
    "\n",
    "print \"At f = 60Hz\"\n",
    "k1 = (sigma)/(omega1*epsilon)  #  ratio\n",
    "print \"ratio k is equal to\",k1\n",
    "print \"since k>>1 therefore it is very good conductor at f = 60Hz:\"\n",
    "delta1 = (sqrt(2/(omega1*mu*sigma)))  #  depth of penetration in m\n",
    "print \"depth of penetration delta1 in m:\",delta1\n",
    "\n",
    "print \"At f = 100Hz\"\n",
    "k2 = sigma/(omega2*epsilon)  #  ratio\n",
    "print \"ratio k is equal to\",k2\n",
    "print \"since k2>>1 therefore it is very good conductor at f = 100Hz:\"\n",
    "delta2 = (sqrt(2/(omega2*mu*sigma)))  #  depth of penetration in m\n",
    "print \"depth of penetration delta2 in m:\",delta2\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.23,Page Number 121"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "when f = 1MHz\n",
      "displacement current when f = 1MHz in A: 9.59160736375e-12\n",
      "when f = 100MHz\n",
      "displacement current when f = 100MHz in A: 9.59160736375e-10\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi\n",
    "\n",
    "\n",
    "#variable Declaration\n",
    "\n",
    "Ic = 10  #  conduction current in ampere\n",
    "epsilon_r = 1  #  relative permittivity\n",
    "epsilon_0 = 8.854*10**-12  #  permittivity in free space\n",
    "epsilon = epsilon_r*epsilon_0  #  permittivity\n",
    "sigma = 5.8*10**7  #  conductivity in mho/m\n",
    "\n",
    "print \"when f = 1MHz\"\n",
    "f = 1  #  frequency in MHz\n",
    "f = 1*10**6  #  frequency in Hz\n",
    "Id = (2*pi*f*epsilon*Ic)/sigma  #  printlacement current\n",
    "print \"displacement current when f = 1MHz in A:\",Id\n",
    "print \"when f = 100MHz\"\n",
    "f = 100  #  frequency in MHz\n",
    "f = 100*10**6  #  frequency in Hz\n",
    "Id = (2*pi*f*epsilon*Ic)/sigma  #  printlacement current\n",
    "print \"displacement current when f = 100MHz in A:\",Id\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.25,Page Number 122"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ratio k is equal to:\n",
      "ratio: 221.92\n",
      "K is >>1 so sea water is a good conductor\n",
      "depth in the sea that can be reached by the aeroplane in m: 1.41095\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,sin,cos,radians,log\n",
    "\n",
    "#variable declaration\n",
    "Em = 20          # minimum signal level required for vessel under sea water in microV/m\n",
    "Em = 20*10**-6   # minimum signal level required for vessel under sea water in V/m\n",
    "E = 100          # electric intensity of wave in V/m\n",
    "v = 3*10**8      # speed of light in m/s\n",
    "f = 4            # frequency in MHz\n",
    "f = 4*10**6      # frequency in Hz\n",
    "omega = 2*pi*f   # angular frequency in Hz\n",
    "sigma = 4        # conductivity of sea water in mho/m\n",
    "epsilon_r = 81   # relative permittivity\n",
    "epsilon_0 = 8.854*10**-12     # permittivity in free space\n",
    "epsilon = epsilon_r*epsilon_0 # permittivity\n",
    "mu_r = 1             # relative permeability\n",
    "mu_0 = 4*pi*10**(-7) # permeability in free space\n",
    "mu = mu_r*mu_0    # permeability\n",
    "k = (sigma)/(omega*epsilon)  #ratio\n",
    "print \"ratio k is equal to:\"\n",
    "print \"ratio:\",round(k,3)\n",
    "print \"K is >>1 so sea water is a good conductor\"\n",
    "eta_1 = 377   # intrinsic impedance in free space in ohm\n",
    "alpha_1 = 0   # attenuation constant in free space in m**-1\n",
    "\n",
    "\n",
    "#calculations\n",
    "beta_1 = omega/v  # phase constant in m**-1\n",
    "mageta_2 = sqrt((omega*mu)/sigma)   # magnitude of eta_2(intrinsic impedance of sea water in ohm) \n",
    "argeta_2 = 45                     # argument of eta_2 in degrees\n",
    "eta_2 = mageta_2*cos(radians(argeta_2))+(1j*mageta_2*sin(radians(argeta_2)))    #intrinsic impedance in complex form (r*cos(theta)+1j*r*sin(theta))\n",
    "TC = 2*eta_2/(eta_1+eta_2)          # transmission cofficient\n",
    "Et = abs(TC)*E                      # transmitted electric field in V/m\n",
    "alpha_2 = sqrt((omega*mu*sigma)/2)  # attenuation constant for sea water in m**-1\n",
    "# formula: Et*exp(-alpha_2*d) = Em\n",
    "d = -(1/alpha_2)*(log(Em/Et))   # depth in the sea that can be reached by the aeroplane in m\n",
    "\n",
    "\n",
    "#result\n",
    "print \"depth in the sea that can be reached by the aeroplane in m:\",round(d,5)\n",
    "\n",
    "\n",
    "# note 1: the value of alpha_2 in book is 7.905 but it is \"7.94\" exactly calculated by python.\n",
    "#note 2 : The correct answer of the Depth(d) is \"1.41095\" the answer in the book is wrong.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.27,Page Number 124"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "E=sin(omega*t-beta*z)ax+2*sin(omega*t-beta*z+75)ay  #  electric field in V/m\n",
      "power per unit area conveyed by the wave in free space in mW/m**2: 6.631\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt\n",
    "\n",
    "#variable declaration\n",
    "\n",
    "eta_0=377  #  intrinsic impedance in free space in ohm\n",
    "print \"E=sin(omega*t-beta*z)ax+2*sin(omega*t-beta*z+75)ay  #  electric field in V/m\"\n",
    "Ex=1  #  magnitude of Ex\n",
    "Ey=2  #  magnitude of Ey\n",
    "\n",
    "#calculations\n",
    "E=sqrt(Ex**2+Ey**2)       #  resultant magnitude\n",
    "Pav=((1/2)*E**2)/(eta_0)  #  power per unit area conveyed by the wave in free space\n",
    "\n",
    "#results\n",
    "print \"power per unit area conveyed by the wave in free space in mW/m**2:\",round(Pav*1000,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.28,Page Number 125"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average power in micro*w/m**2: 2354.59\n",
      "maximum energy density of the wave in PJ/m*3: 31.416\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi\n",
    "\n",
    "#variable declaration\n",
    "\n",
    "epsilon_0 = 8.854*10**-12  # permittivity in free space in F/m\n",
    "mu_0 = 4*pi*10**-7  #  permeability in free space in H/m\n",
    "epsilon_r = 4  # relative permittivity\n",
    "mu_r = 1  # relative permeability\n",
    "epsilon = epsilon_r*epsilon_0  # permittivity\n",
    "mu = mu_0*mu_r  # permeability\n",
    "H = 5  # magnitude of magnetic field in mA/m\n",
    "H = 5*10**-3  # magnitude of magnetic field in A/m\n",
    "\n",
    "#calculations\n",
    "eta = sqrt(mu/epsilon) # intrinsic impedence in ohm\n",
    "E = H*sqrt(mu/epsilon)  # magnitude of electric field\n",
    "P_av = E**2/(2*eta)  # average power\n",
    "W_E = epsilon*E**2  # maximum energy density of the wave\n",
    "\n",
    "\n",
    "#results\n",
    "print \"Average power in micro*w/m**2:\",round(P_av*10**6,2)\n",
    "print \"maximum energy density of the wave in PJ/m*3:\",round(W_E*10**12,3)\n",
    "\n",
    "\n",
    "#note: P_av is =  2353.75 in book but it is 2354.58 correctly calculated by python.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.29,Page Number 125"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "electric energy density of the wave in nJ/m**3: 139.078\n",
      "magnetic energy density of wave in nJ/m**3: 139.078\n",
      "Total energy density in nJ/m**3: 278.157\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi\n",
    "\n",
    "#variable declaration\n",
    "\n",
    "epsilon_0 = 8.854*10**-12 #  permittivity in free space in F/m\n",
    "mu_0 = 4*pi*10**-7 #   permeability in free space in H/m\n",
    "epsilon_r = 1 #  relative permittivity\n",
    "mu_r = 1 #  relative permeability\n",
    "epsilon = epsilon_r*epsilon_0 #  permittivity\n",
    "mu = mu_0*mu_r #  permeability\n",
    "E = 100*sqrt(pi) #  magnitude of electric field in V/m\n",
    "\n",
    "\n",
    "#calculations\n",
    "W_E = (1/2)*epsilon*E**2 #  electric energy density of the wave\n",
    "W_H = W_E #  as the energy density is equal to that of magnetic field for a pla`ne travelling wave\n",
    "W_T = W_E+W_H #  total energy density\n",
    "\n",
    "#results\n",
    "print \"electric energy density of the wave in nJ/m**3:\",round(W_E*10**9,3)\n",
    "print \"magnetic energy density of wave in nJ/m**3:\",round(W_H*10**9,3)\n",
    "print \"Total energy density in nJ/m**3:\",round(W_T*10**9,3)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.30,Page Number 126"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "when frequency = 25kHz\n",
      "transmitted distance in m: 3.274\n",
      "when frequency = 25MHz\n",
      "transmitted distance in m: 0.105\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi\n",
    "\n",
    "#variable Declaration\n",
    "\n",
    "sigma = 5 #  conductivity of sea water in mho/m\n",
    "f1 = 25 #  frequency in kHz\n",
    "f1 = 25*10**3 #  frequency in Hz\n",
    "omega1 = 2*pi*f1 #  angular frequency in Hz\n",
    "f2 = 25 #  frequency in MHz\n",
    "f2 = 25*10**6 #  frequency in Hz\n",
    "omega2 = 2*pi*f2 #  angular frequency in Hz\n",
    "epsilon_r = 81 #  relative permittivity\n",
    "epsilon_0 = 8.854*10**(-12) #  permittivity in free space\n",
    "epsilon = epsilon_r*epsilon_0 #  permittivity\n",
    "mu_r = 1 #  relative permeability\n",
    "mu_0 = 4*pi*10**(-7) #  permeability in free space\n",
    "mu = mu_r*mu_0 #  permeability\n",
    "\n",
    "#calculations and results\n",
    "\n",
    "print \"when frequency = 25kHz\"\n",
    "alpha_1 = omega1*sqrt((mu*epsilon)/2*(sqrt(1+(sigma**2/(omega1**2*epsilon**2)))-1)) #  attenuation constant when f = 25kHz\n",
    "# formula: exp(-alpha*x) = 0.1\n",
    "x1 = 2.3/alpha_1 #  transmitted distance in m\n",
    "print \"transmitted distance in m:\",round(x1,3)\n",
    "print \"when frequency = 25MHz\"\n",
    "alpha_2 = omega2*sqrt((mu*epsilon)/2*(sqrt(1+(sigma**2/(omega2**2*epsilon**2)))-1)) #  attenuation constant when f = 25MHz\n",
    "x2 = 2.3/alpha_2 #  transmitted distance in m\n",
    "print \"transmitted distance in m:\",round(x2,3)\n",
    "\n",
    "\n",
    "# note: the values of epsilon_r = 81 and of mu_r = 1 for sea water which are not given in the book.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.31,Page Number 126"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "reflection cofficient of electric field in mV/m: 0.489\n",
      "incident cofficient of magnetic field in micro*A/m: 7.739\n",
      "reflection cofficient of magnetic field in micro*A/m: 3.786\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,radians,asin,cos,sin,degrees\n",
    "\n",
    "#variable Declaration\n",
    "\n",
    "E_i = 1  #  magnitude of incident electric field in mV/m\n",
    "E_i = 1*10**-3  #  magnitude of incident electric field in V/m\n",
    "epsilon_0 = 8.854*10**-12  #  permittivity in free space in F/m\n",
    "mu_0 = 4*pi*10**-7  #   permeability in free space in H/m\n",
    "theta_i = 15  #  incident angle in degrees\n",
    "epsilon_r1 = 8.5  #  relative permittivity of medium 1\n",
    "mu_r1 = 1  #  relative permeability of medium 1\n",
    "epsilon1 = epsilon_r1*epsilon_0  #  permittivity\n",
    "mu1 = mu_0*mu_r1  #  permeability\n",
    "eta1 = sqrt(mu1/epsilon1)  #  intrinsic impedence of medium 1 in ohm\n",
    "epsilon2 = epsilon_0  #  permittivity of medium 2\n",
    "mu2 = mu_0  #  permeability of medium 2\n",
    "eta2 = sqrt(mu2/epsilon2)  #  intrinsic impedence of medium 2 in ohm\n",
    "\n",
    "#calculations and result\n",
    "\n",
    "# formula : sin(theta_i)/sin(theta_t) = sqrt(epsilon2/epsilon1)\n",
    "theta_t = asin(sin(radians(theta_i)))/(sqrt(epsilon2/epsilon1))  #  transmitted angle in degrees\n",
    "E_r = (E_i*(((eta2*cos(radians(theta_i))))-(eta1*cos(radians((theta_i))))))/((eta2*cos(radians(theta_i)))+(eta1*cos(radians(theta_i))))  #  reflection cofficient of electric field\n",
    "print \"reflection cofficient of electric field in mV/m:\",round(E_r*1000,3)\n",
    "H_i = E_i/eta1  #  incident cofficient of magnetic field\n",
    "print \"incident cofficient of magnetic field in micro*A/m:\",round(H_i*10**6,3)\n",
    "H_r = E_r/eta1  #  reflection cofficient of electric field\n",
    "print \"reflection cofficient of magnetic field in micro*A/m:\",round(H_r*10**6,3)\n",
    "\n",
    "\n",
    "#note : minute difference in decimel in the value of H_i and H_r.\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2.32,Page Number 127"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "average power density absorbed by copper in mW/m**2: 3.83\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi,sqrt\n",
    "\n",
    "#variable declaration\n",
    "\n",
    "sigma = 5.8*10**7 #  conductivity in mho/m\n",
    "f = 2 #  frequency in MHz\n",
    "f = 2*10**6 #  frequency in Hz\n",
    "omega = 2*pi*f #  angular frequency in rad/sec\n",
    "E = 2 #  magnitude of electric field in mV/m\n",
    "E = 2*10**-3 #  magnitude of electric field in V/m\n",
    "epsilon_0 = 8.854*10**-12 #  permittivity in free space in F/m\n",
    "mu_0 = 4*pi*10**-7 #   permeability in free space in H/m\n",
    "epsilon_r = 1 #  relative permittivity\n",
    "mu_r = 1 #  relative permeability\n",
    "epsilon = epsilon_r*epsilon_0 #  permittivity\n",
    "mu = mu_0*mu_r #  permeability\n",
    "\n",
    "# calculations\n",
    "eta = sqrt(mu*omega/sigma) #  intrinsic impedence in ohm\n",
    "P_av = (1/2)*E**2/eta #  average power density anbsorbed by copper\n",
    "\n",
    "#result\n",
    "print \"average power density absorbed by copper in mW/m**2:\",round(P_av*1000,2)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}