{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#5: Elements of statistical mechanics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 5.1, Page number 5.10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "average thermal energy is 0.039 eV\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "k=1.38*10**-23;    #boltzmann constant(J)\n",
    "T=300;       #temperature(K)\n",
    "e=1.6*10**-19;     #charge(c)\n",
    "\n",
    "#Calculation\n",
    "E=3*k*T/(2*e);     #average thermal energy(eV)\n",
    "\n",
    "#Result\n",
    "print \"average thermal energy is\",round(E,3),\"eV\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 5.3, Page number 5.18"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fermi function is 0.269\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "kT=1;    #assume\n",
    "E_Ef=kT;\n",
    "\n",
    "#Calculation\n",
    "FE=1/(1+math.exp(1));     #fermi function\n",
    "\n",
    "#Result\n",
    "print \"fermi function is\",round(FE,3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 5.4, Page number 5.18"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " temperature is 290.2 K\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "FE=10/100;     #fermi function\n",
    "EF=5.5;     #energy function(eV)\n",
    "e=1.6*10**-19;     #charge(c)\n",
    "k=1.38*10**-23;    #boltzmann constant(J)\n",
    "\n",
    "#Calculation\n",
    "E=EF+(EF/100);    #energy(eV)\n",
    "x=math.log((1/FE)-1);\n",
    "T=(E-EF)*e/(k*x);     #temperature(K)\n",
    "\n",
    "#Result\n",
    "print \"temperature is\",round(T,1),\"K\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 5.5, Page number 5.19"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "fermi velocity is 0.86 *10**6 m s-1\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "k=1.38*10**-23;    #boltzmann constant(J)\n",
    "T=24600;     #temperature(K)\n",
    "m=9.108*10**-31;    #mass(kg)\n",
    "\n",
    "#Calculation\n",
    "vF=math.sqrt(2*k*T/m);     #fermi velocity(m s-1)\n",
    "\n",
    "#Result\n",
    "print \"fermi velocity is\",round(vF/10**6,2),\"*10**6 m s-1\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "##Example number 5.6, Page number 5.21"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "number of states is 1.1877 *10**26\n",
      "answer given in the book is wrong\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "from scipy.integrate import quad\n",
    "\n",
    "#Variable declaration\n",
    "EF=3.0;     #fermi energy(eV)\n",
    "e=1.6*10**-19;     #charge(c)\n",
    "m=9.14*10**-31;    #mass(kg)\n",
    "h=6.62*10**-34;    #planck's constant\n",
    "\n",
    "#Calculation\n",
    "E1=EF*e;     #energy(J)\n",
    "E2=(EF+0.01)*e;   #energy(J)\n",
    "def zintg(E):\n",
    "\treturn (4*math.pi*(2*m)**(3/2)*math.sqrt(E))/h**3;\n",
    "\n",
    "n=quad(zintg,E1,E2)[0];      #number of states\n",
    "\n",
    "#Result\n",
    "print \"number of states is\",round(n/10**26,4),\"*10**26\"\n",
    "print \"answer given in the book is wrong\""
   ]
  }
 ],
 "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
}