{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 13 - Charged Particles in Electric and Magnetic Fields"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1 - pg 434"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "v_x = 4.4 x 10^5 m/s\n",
      "x = 7.33 mm\n",
      "t = 0.95 x 10^-7 s\n"
     ]
    }
   ],
   "source": [
    "#pg 434\n",
    "#calculate the x,t\n",
    "#Given :\n",
    "import scipy.integrate\n",
    "# E = 2*10^9*t  V/m\n",
    "# a_x = 3.52*10^20*t m/s^2\n",
    "# v_x = integral of a_x dt\n",
    "#(a)\n",
    "#calculations and results\n",
    "def f(t):\n",
    "\ta_x = 3.530*10**20*t\n",
    "\treturn a_x\n",
    "\n",
    "v_x = scipy.integrate.quad(f,0,50*10**-9); # electron speed in m/s at time = 50 ns\n",
    "print \"v_x =\",round(v_x[0]*10**-5,1),\"x 10^5 m/s\"\n",
    "#(b)\n",
    "#v_x = 1.76*10^20*t^2 m/s\n",
    "def v(t):\n",
    "\tvx=1.76*10**20*t**2\n",
    "\treturn vx\n",
    "\n",
    "x =scipy.integrate.quad(v,0,50*10**-9);# distance covered in m  in 50 ns\n",
    "print \"x =\",round(x[0]*10**3,2),\"mm\"\n",
    "#(c)\n",
    "#x = 5.87*10^19*t^3 m\n",
    "X = 5*10**-2; #distance between plates in m\n",
    "t = (X/(5.87*10**19))**(1./3); # time required in s\n",
    "print \"t =\",round(t*10**7,2),\"x 10^-7 s\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5 - pg 445"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "z_max (mm) =  1.2\n",
      "T = 1.63 x 10^-8 s \n",
      "H = 6.7 mm\n"
     ]
    }
   ],
   "source": [
    "#pg 445\n",
    "#calculate the z-max, T and H\n",
    "import math\n",
    "#Given :\n",
    "u = 5*10**5; #horizontal velocity in m/s\n",
    "alpha = 35/57.3; # in radians\n",
    "E = 200 ;# Electric field in V/m\n",
    "e = 1.6*10**-19; # electron charge in C\n",
    "m = 9.12*10**-31; # electron mass in kg\n",
    "#calculations\n",
    "a = (-e*E)/m; # horizontal range in m/s**2\n",
    "#(a);\n",
    "z_max = (-(u**2)*(math.sin(alpha))**2)/(2*a); # maximum penetration in m\n",
    "#(b)\n",
    "T = (-2*u*math.sin(alpha))/a; # Time of flight in s\n",
    "#(c)\n",
    "H = (-(u**2)*(math.sin(2*alpha)))/a; # horizontal range in m\n",
    "#results\n",
    "print \"z_max (mm) = \",round(z_max*10**3,1)\n",
    "print \"T =\",round(T*10**8,2),\"x 10^-8 s \"\n",
    "print \"H =\",round(H*1000.,1),\"mm\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7 - pg 448"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "B = 0.57 x 10^-3 Wb/m**2\n",
      "T = 6.28 x 10^-8 s\n",
      "p (m) =  2.72\n"
     ]
    }
   ],
   "source": [
    "#pg 448\n",
    "#calculate the values of B,T and P\n",
    "#Given :\n",
    "import math\n",
    "m = 9.12*10**-31;# electron mass in kg\n",
    "e = 1.6*10**-19;# electron charge in C\n",
    "u = 5*10**7; # electron speed in m/s\n",
    "alpha = 30/57.3; # angle in radians\n",
    "d = 0.5; # diameter in m\n",
    "#calculations\n",
    "#(a)\n",
    "#helix radius  = (m*u*sin(alpha))/B*e \n",
    "r = d/2; # radius in m\n",
    "B = (m*u*math.sin(alpha))/(r*e); # magnetic flux density in Wb/m**2\n",
    "#(b)\n",
    "T = (2*math.pi*m)/(B*e);# time in s\n",
    "#(c)\n",
    "p = T*u*math.cos(alpha); # pitch in m\n",
    "#results\n",
    "print \"B =\",round(B*1000.,2),\"x 10^-3 Wb/m**2\"\n",
    "print \"T =\",round(T*10**8,2),\"x 10^-8 s\"\n",
    "print \"p (m) = \",round(p,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 9 - pg 449"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "T = 3.58 x 10^-11 / B \n"
     ]
    }
   ],
   "source": [
    "#pg 449\n",
    "#calculate the value of T\n",
    "import math\n",
    "#Given :\n",
    "m = 9.109*10**-31;# eletcron mass in kg\n",
    "e = 1.6*10**-19; # electron charge in C\n",
    "#calculations\n",
    "#T = (2*pi*m)/(B*e) , here B is not given\n",
    "T = (2*math.pi*m)/e;# time in s\n",
    "#results\n",
    "print \"T =\",round(T*10**11,2),\"x 10^-11 / B \"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 11 - pg 455"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "theta2 (degrees) =  30.0\n"
     ]
    }
   ],
   "source": [
    "#pg 455\n",
    "#calculate the angle required\n",
    "#Given :\n",
    "import math\n",
    "V1 = 250.; # potential in V\n",
    "V2 = 500.;# potential in V\n",
    "theta1 = 45.;# angle in degrees\n",
    "#Law of electron refraction = sin(theta1)/sin(theta2)  = (V2/V1)^0.5\n",
    "#calculations\n",
    "theta2 = math.asin(((V1/V2)**(1./2))*math.sin(45/57.3))*57.3;\n",
    "#results\n",
    "print \"theta2 (degrees) = \",round(theta2,0)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 12 - pg 463"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "S2-S1 (mm) =  8.0\n"
     ]
    }
   ],
   "source": [
    "#pg 463\n",
    "#calculate the difference of S2_S1\n",
    "#Given :\n",
    "M1 = 20.; # neon isotope mass in amu\n",
    "M2 = 22.;#neon isotope mass in amu\n",
    "E = 7*10**4; # Electric field in V/m\n",
    "e = 1.6*10**-19;# electron charge in C\n",
    "B = 0.5;# Magnetic field in Wb/m**2\n",
    "B1 = 0.75; # Magnetic field in Wb/m**2\n",
    "# Linear seperation = S2 - S1  = (2*E*(M2-M1))/(B*B1*e) \n",
    "# 1 amu = 1.66*10**-27 kg\n",
    "#calculations\n",
    "S2_S1 =  (2*E*(M2-M1)*1.66*10**-27)/(B*B1*e) ; # linear seperation in m\n",
    "#results\n",
    "print \"S2-S1 (mm) = \",round(S2_S1*10**3,0)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 13 - pg 466"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "B (Wb/m^2) =  1.2\n",
      "f (MHz) =  9.15\n",
      "t (mu s) =   5.47\n"
     ]
    }
   ],
   "source": [
    "#pg 466\n",
    "#calculate the values of B,f and t\n",
    "import math\n",
    "#Given:\n",
    "m = 2.01*1.66*10**-27; # deuteron mass in kg\n",
    "q = 1.6*10**-19; # deuteron charge in C\n",
    "#We know , 1/2(m*v**2) = q*V\n",
    "#for a 5 MeV deuteron \n",
    "#calculations\n",
    "# 1 MeV = 10**6*1.6*10**-19 J\n",
    "v =((2*5*10**6*1.6*10**-19)/m)**(1./2) ; # velocity in m/s\n",
    "#(a)\n",
    "R = 15; # inches \n",
    "#1 inch = 2.54*10**-2 m\n",
    "B = (m*v)/(q*R*2.54*10**-2);# magnetic field intensity in Wb/m**2\n",
    "#(b)\n",
    "f = (q*B)/(2*math.pi*m); # frequency in Hz\n",
    "#(c)\n",
    "t = 50/f; # time in s\n",
    "#results\n",
    "print \"B (Wb/m^2) = \",round(B,1)\n",
    "print \"f (MHz) = \",round(f*10**-6,2)\n",
    "print \"t (mu s) =  \",round(t*10**6,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.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
