{
 "metadata": {
  "name": "",
  "signature": "sha256:08d693988f55ded7946a3910c4b750b4a1419d79f72e5b56719c0d924a66fd5a"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h1>Chapter 5: Electric Fields in Material Space<h1>"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 5.1, Page number: 167<h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "import scipy\n",
      "import scipy.integrate\n",
      "\n",
      "#Variable Declaration\n",
      "\n",
      "r1= 0.2                # radius of hemispherical shell in metres\n",
      "r2= 0.1                # radius of spherical shell in metres\n",
      "\n",
      "#Calculations\n",
      "\n",
      "#Calculation of current through hemispherical shell \n",
      "\n",
      "def J1(phi,theta):\n",
      "\ts1=(1/r1)*(2* scipy.cos(theta)* scipy.sin(theta))\n",
      "\treturn s1\n",
      "\n",
      "if __name__ == '__main__':\n",
      "\n",
      " I1, error = scipy.integrate.dblquad(lambda theta , phi: J1(phi,theta),    \n",
      "             0, 2*scipy.pi, lambda theta: 0, lambda theta: scipy.pi/2) \n",
      "\t                 \n",
      "#Calculation of current through spherical shell \n",
      "\n",
      "def J2(phi,theta):\n",
      "\ts2=(1/r2)*(2* scipy.cos(theta)* scipy.sin(theta))\n",
      "\treturn s2\n",
      "\n",
      "if __name__ == '__main__':\n",
      "\n",
      " I2, error = scipy.integrate.dblquad(lambda theta , phi: J1(phi,theta),    \n",
      "              0, 2*scipy.pi, lambda theta: 0, lambda theta: scipy.pi) \n",
      "\t                 \n",
      "#Results\n",
      "\n",
      "print 'Current through hemispherical shell=',round(I1,1),'A' \n",
      "print 'Current through spherical shell=',round(I2,0),'A'\n",
      "\t"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Current through hemispherical shell= 31.4 A\n",
        "Current through spherical shell= 0.0 A\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 5.2, Page number: 168<h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "#Variable Declaration\n",
      "\n",
      "ps=10**-7     #Surface charge density of the belt in Couloumb/metre^2\n",
      "u=2           #Speed of the belt in metres/sec\n",
      "w=0.1         #Width of the belt in metres\n",
      "t=5           #Time taken in seconds \n",
      "\n",
      "#Calculations\n",
      "\n",
      "I=ps*u*w      #Current in amperes\n",
      "Q=I*t*10**9   #Charge collected in 5 seconds in nano Coloumbs\n",
      "\n",
      "#Result\n",
      "\n",
      "print \"The charge collected in 5 seconds is \",Q,\"nC\" "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The charge collected in 5 seconds is  100.0 nC\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 5.3, Page number: 169<h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "#Variable Declaration\n",
      "\n",
      "n=10**29              #Number density of electrons in m^-3\n",
      "e=-1.6*10**-19        #Electronic charge in Coloumbs\n",
      "sigma=5*10**7         #Current density in S/m\n",
      "E=10**-2              #Electric Field in V/m\n",
      "S=(3.14*10**-6)/4     #Cross sectional area of the wire in m^2\n",
      "\n",
      "#Calculations\n",
      "\n",
      "pv=n*e                #Charge density of free electrons in C/m^3\n",
      "J=sigma*E*10**-3      #Current density in kA/m^2\n",
      "I=J*S*10**3           #Current in amperes\n",
      "u=J*10**3/pv          #Drift velocity in m/s\n",
      "\n",
      "#Results\n",
      "\n",
      "print \"The charge density is \",pv,\"C/m^3\" \n",
      "print \"The current density is \",J,\"kA/m^2\" \n",
      "print \"The current is \",round(I,3), \"A\"\n",
      "print \"The drift velocity is \",-u,\"m/s\" "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The charge density is  -16000000000.0 C/m^3\n",
        "The current density is  500.0 kA/m^2\n",
        "The current is  0.393 A\n",
        "The drift velocity is  3.125e-05 m/s\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 5.4, Page number: 170<h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "import scipy\n",
      "\n",
      "#Variable Declaration\n",
      "\n",
      "l=4                            #Length of the lead bar in m\n",
      "d=3                            #Width of the lead bar in cm\n",
      "r=0.5                          #Radius of the hole drilled in cm\n",
      "sigma=5*10**6                  #Conductivity of the bar in S/m\n",
      "\n",
      "#Calculation\n",
      "\n",
      "S=(d**2-(scipy.pi*r**2))       #Cross sectional area in cm^2\n",
      "R=l/(S*sigma*10**-4)           #Resistance in ohms\n",
      "\n",
      "#Result\n",
      "\n",
      "print 'The resistance between the square ends is',round(R*10**6),'micro ohms'\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The resistance between the square ends is 974.0 micro ohms\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 5.6, Page number: 177<h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import scipy\n",
      "\n",
      "#Variable Declaration\n",
      "\n",
      "e0=10**-9/(36*scipy.pi)         #permittivity of free space in Farad/m\n",
      "er=2.55                         #relative permittivity (dimensionless)\n",
      "E=10*10**3                      #Electric field in V/m\n",
      "chi=er-1.0                      #Electric susceptibility (dimensionless)\n",
      "d=1.5                           #Distance between plates in mm\n",
      "\n",
      "#Calculations\n",
      "\n",
      "D=e0*er*E*10**9                 #D in nC/m^2\n",
      "\n",
      "P=chi*e0*E*10**9                #P in nC/m^2\n",
      "\n",
      "ps=D                            #The surface charge density of \n",
      "                                #free charge in nC/m^2\n",
      "                                \n",
      "pps =P                          #The surface charge density of\n",
      "                                #polarization charge in nC/m^2\n",
      "                                \n",
      "V=E*d*10**-3                    #The potential difference between \n",
      "                                #the plates in volts\n",
      "\n",
      "#Results\n",
      "\n",
      "print 'D =',round(D,2),'nC/m^2'\n",
      "print 'P =',round(P,0),'nC/m^2'\n",
      "print 'Surface charge density of free charge =',round(ps,2),'nC/m^2'\n",
      "print 'Surface charge density of polarization charge =',round(pps,0),'nC/m^2'\n",
      "print 'The potential difference between the plates =',V,'V'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "D = 225.47 nC/m^2\n",
        "P = 137.0 nC/m^2\n",
        "Surface charge density of free charge = 225.47 nC/m^2\n",
        "Surface charge density of polarization charge = 137.0 nC/m^2\n",
        "The potential difference between the plates = 15.0 V\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 5.7, Page number: 178<h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "\n",
      "import scipy\n",
      "\n",
      "#Variable Declaration\n",
      "\n",
      "e0=10**-9/(36*scipy.pi)                   #permittivity of free space\n",
      "                                          #in Farad/m\n",
      "                                          \n",
      "er=5.7                                    #relative permittivity\n",
      "                                          #(dimensionless)\n",
      "                                          \n",
      "chi=er-1                                  #Electric susceptibility\n",
      "                                          #(dimensionless)\n",
      "                                          \n",
      "r=0.1                                     #radius of sphere in m\n",
      "\n",
      "q1=2                                      #charge on sphere in pC\n",
      "\n",
      "q2=-4                                     #value of point charge in pC\n",
      "\n",
      "#Calculations\n",
      "\n",
      "E=q1/(4*scipy.pi*e0*er*r**2)              #Electric field on the\n",
      "                                          #sphere in pV/m\n",
      "                                          \n",
      "P=chi*e0*E                                #Polarisation in pC/m^2\n",
      "\n",
      "pps=P                                     #The surface density of polarization \n",
      "                                          #charge in pC/m^2\n",
      "                                          \n",
      "F=(q1*q2*10**-12)/(4*scipy.pi*e0*er*r**2) #Force exerted on point charge in pN\n",
      "\n",
      "#Results\n",
      "\n",
      "print 'The surface density of polarization'\n",
      "print 'charge on the surface of the sphere =',round(pps,2),'pC/m^2'\n",
      "print 'Force exerted on -4 pC charge =',round(F,3),'pN in the radial direction'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The surface density of polarization\n",
        "charge on the surface of the sphere = 13.12 pC/m^2\n",
        "Force exerted on -4 pC charge = -1.263 pN in the radial direction\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 5.9, Page number: 188<h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "#Variable Declarartion\n",
      "\n",
      "import scipy\n",
      "from numpy import *\n",
      "\n",
      "an=array([0,0,1])            #Unit vector normal to the interface\n",
      "E1=array([5,-2,3])           #Electric field for z >=0 in kV/m\n",
      "e_r1=4                       #Relative permittivity for z >=0 (dimensionless)\n",
      "e_r2=3                       #Relative permittivity for z <=0 (dimensionless)\n",
      "e0=(10**-9)/(36*scipy.pi)    #Permittivity of free space in Farad/m\n",
      "V=2*2*2                      #Volume of cube placed in region 2 in m^3\n",
      "\n",
      "#Calculations\n",
      "\n",
      "E1n=array([0,0,dot(E1,an)])   #The normal component of E1 in kV/m\n",
      "E1t=E1-E1n                    #Transverse component of E1 in kV/m\n",
      "E2t=E1t                       #Transverse component of E2 in kV/m\n",
      "E2n=e_r1*E1n/e_r2             #Normal Component of E2 in kV/m\n",
      "E2=E2n+E2t                    #The total field E2 in kV/m\n",
      "\n",
      "theta1= 90- 180*scipy.arccos(dot(E1,an)/        #Angle between E1 and \n",
      "             scipy.sqrt(dot(E1,E1)))/scipy.pi   #interface in degrees\n",
      "             \n",
      "theta2= 90- 180*scipy.arccos(dot(E2,an)/        #Angle between E2 and \n",
      "             scipy.sqrt(dot(E2,E2)))/scipy.pi   #interface in degrees\n",
      "\n",
      "\n",
      "We1= 0.5*e0*e_r1*dot(E1,E1)*10**6       # The energy density of E1 in J/m^3\n",
      "We2= 0.5*e0*e_r2*dot(E2,E2)*10**6       # The energy density of E2 in J/m^3\n",
      "W= We2*V                                # The energy within the cube in J\n",
      "\n",
      "#Results\n",
      "\n",
      "print 'The electric field for the region z <=0 is',E2,'kV/m'\n",
      "print 'The angle E1 makes with the boundary is',round(theta1,1),'degrees'\n",
      "print 'The angle E2 makes with the boundary is',round(theta2,1),'degrees'\n",
      "print 'The energy density in dielectric 1 is',round(We1*10**6,0),'J/m^3'\n",
      "print 'The energy density in dielectric 2 is',round(We2*10**6,0),'J/m^3'\n",
      "print 'The energy within the cube is',round(W*1000,3),'mJ'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The electric field for the region z <=0 is [ 5 -2  4] kV/m\n",
        "The angle E1 makes with the boundary is 29.1 degrees\n",
        "The angle E2 makes with the boundary is 36.6 degrees\n",
        "The energy density in dielectric 1 is 672.0 J/m^3\n",
        "The energy density in dielectric 2 is 597.0 J/m^3\n",
        "The energy within the cube is 4.775 mJ\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Example 5.10, Page number: 190<h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      " \n",
      "import scipy\n",
      "\n",
      "#Variable Declaration\n",
      "\n",
      "e=(10**-9)/(36*scipy.pi)     #Permittivity of free space in Farad/m\n",
      "er=2                         #Relative permittivity (dimensionless)\n",
      "ps=2                         #Surface charge in nC/m^2\n",
      "\n",
      "#Calculations\n",
      "\n",
      "#Point A is in the region y <=0. Hence E=D=0\n",
      "#For point B which is in the region y >=0,\n",
      "\n",
      "Dn=ps                        #Displacement current in nC/m^2\n",
      "En=Dn*10**-9/(e*er)          #Electric Field\n",
      "\n",
      "#Result\n",
      "\n",
      "print 'E at point A= 0'\n",
      "print 'D at point A= 0'\n",
      "print 'E at point B=',round(En,2),'V/m along positive y direction'\n",
      "print 'D at point B=',Dn,'nC/m^2 along positive y direction'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "E at point A= 0\n",
        "D at point A= 0\n",
        "E at point B= 113.1 V/m along positive y direction\n",
        "D at point B= 2 nC/m^2 along positive y direction\n"
       ]
      }
     ],
     "prompt_number": 8
    }
   ],
   "metadata": {}
  }
 ]
}