{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 01:Electromagnetics and Optics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex1.6:pg-25"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Refractive index of the glass =  1.5\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#To find refractive index of of the glass\n",
    "import math\n",
    "\n",
    "# Given data\n",
    "phi=0.7297;                          # Critical angle for glass-air interface\n",
    "n2=1;                                # Refractive index of air\n",
    "n1=n2/math.sin(phi);                      # Refractive index of glass\n",
    "\n",
    "# Displaying the result in command window\n",
    "print \"\\n Refractive index of the glass = \",round(n1,1)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex1.7:pg-25"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " \n",
      "Speed of light in medium = 2.069  X 10^8 m/s',\n",
      " \n",
      "Wavelenght of laser in medium = 1.0889  micrometer\n",
      "\n",
      "Wavenumber in medium = 5.77  X 10^6 m^-1\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#To calculate a)the speed of light b) The wavelenght in medium c) The wavenumber in medium\n",
    "import math\n",
    "\n",
    "\n",
    "#a)The speed of light\n",
    "c=3*10**8;                               #Speed of light in free space (m/s)\n",
    "n=1.45;                                 #Given refractive index of dielectric medium\n",
    "v=(c/n);                               #Speed of light in medium (in m/s)\n",
    "\n",
    "#Displaying the result in command window\n",
    "print\" \\nSpeed of light in medium =\",round(v*10**-8,3),\" X 10^8 m/s',\"\n",
    "\n",
    "#b) The wavelenght in medium \n",
    "f=190*10**12;                           #Given operating frequency of laser\n",
    "lambdam=(v/f);                         #Wavelenght in medium \n",
    "\n",
    "#Displaying the result in command window\n",
    "print\" \\nWavelenght of laser in medium =\",round(lambdam*10**(6),4),\" micrometer\"\n",
    "\n",
    "#c) The wavenumber in medium\n",
    "k=(2*math.pi)/lambdam;                    #Wavenumber in medium\n",
    "\n",
    "#Displaying the result in command window\n",
    "print \"\\nWavenumber in medium =\",round(k*10**-6,2),\" X 10^6 m^-1\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex1.8:pg-26"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " Magnitude of the wave vector of the refracted wave is same as wave number = 5.77  X 10^6 m^-1\n",
      "\n",
      " z-component of the wave vector = 4.63  X 10^6 m**-1\n",
      "\n",
      " x-component of the wave vector =  3.45  X 10^6 m**-1\n"
     ]
    }
   ],
   "source": [
    "\n",
    "# To calculate a)magnitude of the wave vector of the refracted wave b)x-component and z-component of the wave vector\n",
    "\n",
    "import math\n",
    "#Given data\n",
    "n1=1;                                               # Refractive index of air\n",
    "n2=1.45;                                            # Refractive index of slap\n",
    "theta1=math.pi/3;                                       # Angle of incidence\n",
    "lambdam=1.0889*10**(-6);                             # Wavelength in medium\n",
    "theta2=math.asin(math.sin(theta1)/n2);                        # Angle of refraction\n",
    "\n",
    "# a)To calculate magnitude of the wave vector of the refracted wave\n",
    "k=((2*math.pi)/lambdam);                               # Wavenumber\n",
    "\n",
    "# Displaying the result in command window\n",
    "print\" Magnitude of the wave vector of the refracted wave is same as wave number =\",round(k*10**(-6),2),\" X 10^6 m^-1\"\n",
    "\n",
    "# b)To calculate x-component and z-component of the wave vector\n",
    "kx=k*math.sin(theta2);                                   # x-component of the wave vector\n",
    "kz=k*math.cos(theta2);                                   # z-component of the wave vector\n",
    "\n",
    "# Displaying the result in command window\n",
    "print\"\\n z-component of the wave vector =\",round(kz*10**(-6),2),\" X 10^6 m**-1\"\n",
    "print\"\\n x-component of the wave vector = \",round(kx*10**(-6),2),\" X 10^6 m**-1\"\n",
    "# The answer is varrying due to round-off error \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex1.9:pg-30"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " Length of the medium = 500.0  m\n"
     ]
    }
   ],
   "source": [
    "#To find length of the medium\n",
    "import math\n",
    "\n",
    "\n",
    "bandwidth=100*10**9;                        #Bandwidth of optical signal\n",
    "w=2*math.pi*bandwidth;                      #Bandwidth of optical signal in rad/s\n",
    "T=3.14*10**(-12);                           #Delay between minimum and maximum frequency component\n",
    "beta2=10*(10**(-12))**2/10.0**3;            #Group velocity dispersion parameter in s^2/km\n",
    "L=T/(beta2*w);                              #Length of the medium\n",
    "\n",
    "# Displaying the result in command window\n",
    "print\" Length of the medium =\",round(L),\" m\"\n",
    "\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.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
