{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter3 - Wave propagation in planor waveguides"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.1 : Page 45"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "range of propagation constant is 1.10880e+07  to 1.1014e+07  m**-1\n",
      "number of modes are 4.0\n"
     ]
    }
   ],
   "source": [
    "from math import pi, sqrt\n",
    "#range of propagation constants and maximum no. of modes\n",
    "n1=1.5##core refractive index\n",
    "n2=1.49##cladding refrative index\n",
    "t=9.83##thickness of guided layer in micro meter\n",
    "h=0.85##wavelength in µm\n",
    "b1=((2*pi*n1)/(h*10**-6))##phase propagation constant in m**-1\n",
    "b2=((2*pi*n2)/(h*10**-6))##phase propagation constant in m**-1\n",
    "m=((4*t)/h)*(sqrt(n1**2-n2**2))##number of modes\n",
    "print \"range of propagation constant is %0.5e\"%(b1),\" to %0.4e\"%(b2),\" m**-1\"\n",
    "print\"number of modes are\",round(m/2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.2 : Page 51"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "thicknes of the slab should not be greater than 0.794  µm\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt\n",
    "#thickness\n",
    "n1=3.6##core refractive index\n",
    "n2=3.56##cladding refrative index\n",
    "h=0.85##wavelength in µm\n",
    "a=((h/(2*sqrt(n1**2-n2**2))))##thickness in µm\n",
    "print \"thicknes of the slab should not be greater than %0.3f\"%(a),\" µm\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.3 : Page 52"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "part (a)\n",
      "number of modes are :  5.0\n",
      "part (b)\n",
      "m \tuma(rad) \tum(m**-1) \twma(rad) \twm(m**-1) \tbm((wma/v)**2] \t\n",
      "\n",
      "0      1.30644         2.5845e+05        4.8263         9.5476e+05        0.93077\n",
      "1      2.59574         5.1350e+05        4.27342         8.4538e+05        0.72974\n",
      "2      3.83747         7.5914e+05        3.20529         6.3408e+05        0.41053\n",
      "3      4.9063         9.7058e+05        0.963466         1.9060e+05        0.03709\n"
     ]
    }
   ],
   "source": [
    "from math import pi, sqrt\n",
    "#no. of modes\n",
    "print \"part (a)\"\n",
    "n1=1.5##core refractive index\n",
    "n2=1.48##cladding refrative index\n",
    "t=10.11##thickness of guided layer in micro meter\n",
    "h=1.55##wavelength in µm\n",
    "b1=((2*pi*n1)/(h*10**-6))##phase propagation constant in m**-1\n",
    "b2=((2*pi*n2)/(h*10**-6))##phase propagation constant in m**-1\n",
    "m=((2*pi*t)/h)*(sqrt(n1**2-n2**2))##number of modes\n",
    "print \"number of modes are : \",round(m/2)\n",
    "\n",
    "print \"part (b)\"\n",
    "t1=10.11##thickness of guided layer in micro meter\n",
    "t=t1/2#\n",
    "h=1.55##wavelength in µm\n",
    "b1=((2*pi*n1)/(h*10**-6))##phase propagation constant in m**-1\n",
    "b2=((2*pi*n2)/(h*10**-6))##phase propagation constant in m**-1\n",
    "mo=(((2*pi*t1)/h)*(sqrt(n1**2-n2**2)))/2##number of modes\n",
    "uma0=1.30644## for m=0 from the curve\n",
    "uma1=2.59574## for m=1 from the curve\n",
    "uma2=3.83747## for m=2 from the curve\n",
    "uma3=4.9063## for m=3 from the curve\n",
    "wma0=4.8263## for m=0 from the curve\n",
    "wma1=4.27342## for m=1 from the curve\n",
    "wma2=3.20529## for m=2 from the curve\n",
    "wma3=0.963466## for m=3 from the curve\n",
    "um0=uma0/(t*10**-6)##in m**-1\n",
    "um1=uma1/(t*10**-6)##in m**-1\n",
    "um2=uma2/(t*10**-6)##in m**-1\n",
    "um3=uma3/(t*10**-6)##in m**-1\n",
    "wm0=wma0/(t*10**-6)##in m**-1\n",
    "wm1=wma1/(t*10**-6)##in m**-1\n",
    "wm2=wma2/(t*10**-6)##in m**-1\n",
    "wm3=wma3/(t*10**-6)##in m**-1\n",
    "bm0=((wm0*t*10**-6)/mo)**2##for m=0 \n",
    "bm1=((wm1*t*10**-6)/mo)**2##for m=1\n",
    "bm2=((wm2*t*10**-6)/mo)**2##for m=2 \n",
    "bm3=((wm3*t*10**-6)/mo)**2##for m=3\n",
    "m0=sqrt((bm0*(b1**2-b2**2))+b2**2)##for m=0 in m**-1\n",
    "m1=sqrt((bm1*(b1**2-b2**2))+b2**2)##for m=1 in m**-1\n",
    "m2=sqrt((bm2*(b1**2-b2**2))+b2**2)##for m=2 in m**-1\n",
    "m3=sqrt((bm3*(b1**2-b2**2))+b2**2)##for m=3 in m**-1\n",
    "params = [\"m\", \"uma(rad)\", \"um(m**-1)\", \"wma(rad)\", \"wm(m**-1)\", \"bm((wma/v)**2]\" ]\n",
    "for x in params:\n",
    "    print x,'\\t',\n",
    "\n",
    "print '\\n'\n",
    "a = range(0,4)\n",
    "b = [uma0, uma1, uma2, uma3]\n",
    "c = [um0, um1, um2, um3]\n",
    "d = [wma0, wma1, wma2, wma3]\n",
    "e = [wm0, wm1, wm2, wm3]\n",
    "f = [bm0, bm1, bm2, bm3]\n",
    "from numpy import nditer\n",
    "for k,l,m,n,o,p in nditer([a,b,c,d,e,f]) :\n",
    "    print k,'    ',l,'        %0.4e'%m,'      ',n,'        %0.4e'%o,'       %0.5f'%p\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3.4 : Page 56"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "G factor is 0.5622\n"
     ]
    }
   ],
   "source": [
    "from math import sin, cos, pi\n",
    "#G factor\n",
    "d=0.793##in micro meter\n",
    "v=pi/2##point of intersection\n",
    "ua=0.934##\n",
    "wa=1.262##\n",
    "Y=(wa*(1+(sin(ua*pi/180))*(cos(ua*pi/180))/ua))\n",
    "G=(1+((cos(ua*pi/180))**2)/Y)**(-1)\n",
    "print \"G factor is %0.4f\"%G\n",
    "#answer is wrong in the textbook"
   ]
  }
 ],
 "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
}