{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 12: X-ray Diffraction"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 1, Page number 378"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "wavelength of X-rays is 0.0842 nm\n",
      "maximum order of diffraction is 6\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "d=0.282;       #lattice spacing(nm)\n",
    "theta=(8+(35/60))*math.pi/180;     #glancing angle(radian)\n",
    "n1=1;                  #order\n",
    "\n",
    "#Calculation\n",
    "lamda=2*d*math.sin(theta)/n1;    #wavelength of X-rays(nm)\n",
    "n=2*d/lamda;                     #maximum order of diffraction\n",
    "\n",
    "#Result\n",
    "print \"wavelength of X-rays is\",round(lamda,4),\"nm\"\n",
    "print \"maximum order of diffraction is\",int(n)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 2, Page number 378"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "glancing angle for 1st order is 17 degrees 24 minutes\n",
      "glancing angle for 2nd order is 36 degrees 44 minutes\n",
      "answers given in the book are wrong\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "d=3.209;       #lattice spacing(angstrom)\n",
    "lamda=1.92;    #wavelength of X-rays(angstrom)\n",
    "n1=1;                  #order\n",
    "n2=2;                  #order \n",
    "\n",
    "#Calculation\n",
    "theta1=math.asin(n1*lamda/(2*d))*180/math.pi;    #glancing angle for 1st order(degrees)\n",
    "theta1d=int(theta1);                             #glancing angle for 1st order(degrees)  \n",
    "theta1m=(theta1-theta1d)*60;                     #glancing angle for 1st order(minutes)\n",
    "theta2=math.asin(n2*lamda/(2*d))*180/math.pi;    #glancing angle for 2nd order(degrees)\n",
    "theta2d=int(theta2);                             #glancing angle for 2nd order(degrees)\n",
    "theta2m=(theta2-theta2d)*60;                     #glancing angle for 2nd order(minutes)\n",
    "\n",
    "#Result\n",
    "print \"glancing angle for 1st order is\",theta1d,\"degrees\",int(theta1m),\"minutes\"\n",
    "print \"glancing angle for 2nd order is\",theta2d,\"degrees\",int(theta2m),\"minutes\"\n",
    "print \"answers given in the book are wrong\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 4, Page number 379"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "wavelength of X-rays is 1.268 angstrom\n",
      "answer given in the book is wrong\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "d=3.05;       #lattice spacing(angstrom)\n",
    "theta=12*math.pi/180;     #glancing angle(radian)\n",
    "n=1;                  #order\n",
    "\n",
    "#Calculation\n",
    "lamda=2*d*math.sin(theta)/n1;    #wavelength of X-rays(angstrom)\n",
    "\n",
    "#Result\n",
    "print \"wavelength of X-rays is\",round(lamda,3),\"angstrom\"\n",
    "print \"answer given in the book is wrong\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 5, Page number 380"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "wavelength of line A is 1.268 angstrom\n",
      "answer given in the book is wrong\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "thetaA=30*math.pi/180;     #glancing angle(radian)\n",
    "thetaB=60*math.pi/180;     #glancing angle(radian)\n",
    "n1=1;                  #order\n",
    "n2=2;                  #order\n",
    "lamdaB=0.9;            #wavelength of X-rays(angstrom)\n",
    "\n",
    "#Calculation\n",
    "lamdaA=2*lamdaB*math.sin(thetaA)/math.sin(thetaB);    #wavelength of line A(angstrom)\n",
    "\n",
    "#Result\n",
    "print \"wavelength of line A is\",round(lamda,3),\"angstrom\"\n",
    "print \"answer given in the book is wrong\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 6, Page number 380"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "wavelength of X-rays is 0.7853 angstrom\n",
      "glancing angle for 2nd order is 18.2 degrees\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "d=2.51;       #lattice spacing(angstrom)\n",
    "theta=9*math.pi/180;     #glancing angle(radian)\n",
    "n1=1;                    #order\n",
    "n2=2;                    #order\n",
    "\n",
    "#Calculation\n",
    "lamda=2*d*math.sin(theta)/n1;    #wavelength of X-rays(angstrom)\n",
    "theta=math.asin(n2*lamda/(2*d))*180/math.pi; #glancing angle for 2nd order(degrees)\n",
    "\n",
    "#Result\n",
    "print \"wavelength of X-rays is\",round(lamda,4),\"angstrom\"\n",
    "print \"glancing angle for 2nd order is\",round(theta,1),\"degrees\""
   ]
  }
 ],
 "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
}
