{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 12 - Diodes and Transistors"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 1 - pg 395"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "V0 (V) =  0.36\n"
     ]
    }
   ],
   "source": [
    "#pg 395\n",
    "#calculate the voltage\n",
    "#Given:\n",
    "import math\n",
    "sigma_n = 10**4; #conductivity in mho/m\n",
    "sigma_p = 10**2; # conductivity in mho/m\n",
    "e = 1.6*10**-19;# charge of an electron in C\n",
    "kT = 0.026 ;# k*T value at room temperature in eV\n",
    "ni = 2.5*10**19; # per m**3\n",
    "mue = 0.38; # mobility of free electrons in m**2/Vs\n",
    "muh = 0.18;# mobility of free electrons in m**2/Vs\n",
    "# sigma_n = e*n*mue  and sigma_p = e*p*muh\n",
    "#calculations\n",
    "nn0 = sigma_n/(e*mue); # per m**3\n",
    "pp0 = sigma_p/(e*muh);# per m**3\n",
    "np0 =(ni**2)/pp0; # in m**-3\n",
    "# V0 = (kT/e)*log(nn0/np0) , but we consider only kT because kT/e = 0.026 eV/e  , both the e's cancel each other.Finally we obtain the answer in Volts\n",
    "V0 = (kT)*math.log(nn0/np0); # in V\n",
    "#results\n",
    "print \"V0 (V) = \",round(V0,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 2 - pg 396"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(a) np = 47.0 x np0\n",
      "(b) np = 1.98 x 10^-17 x np0\n"
     ]
    }
   ],
   "source": [
    "### pg 396\n",
    "#calculate the np \n",
    "#Given :\n",
    "import math\n",
    "#(a)Forward bias of 0.1 V\n",
    "# np = np0*exp[eV/kT] , here we dont have np0 value, so we will calculate the remaining part.\n",
    "kT = 0.026; # in eV\n",
    "#calculations and results\n",
    "np = math.exp(0.1/kT); \n",
    "print \"(a) np =\",round(np,0),\"x np0\"\n",
    "#(b)Reverse bias of 1 V\n",
    "# np = np0*exp[-eV/kT] , here we dont have np0 value, so we will calculate the remaining part.\n",
    "np1 = math.exp(-1/kT);\n",
    "print \"(b) np =\",round(np1*10**17,2),\"x 10^-17 x np0\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 3 - pg 398"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Current (muA) =  4.58\n"
     ]
    }
   ],
   "source": [
    "#pg 398\n",
    "#calculate the Current\n",
    "#import math\n",
    "#Given :\n",
    "import math\n",
    "I0 = 0.1; # muA\n",
    "kT = 0.026; # kT value at room temperature\n",
    "#calculations\n",
    "#Forward bias of 0.1 V\n",
    "# I = I0[exp(eV/kT) - 1]\n",
    "#  since I = I0*(exp(0.1 eV/kT (eV))), both the eV's cancel each other , so it is only  I = I0*(exp(0.1/kT) - 1) while evaluating.\n",
    "I = I0*(math.exp(0.1/kT) - 1) # in muA\n",
    "#results\n",
    "print \"Current (muA) = \",round(I,2)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 4 - pg 420"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Input voltage = 41 V , Iz (mA) =  4.0\n",
      "Load resistance = 4k ohm , Iz (mA) =  4.5\n"
     ]
    }
   ],
   "source": [
    "#pg 420\n",
    "#calculate the Input voltage and load resistance\n",
    "#Given :\n",
    "Vin = 36.; # Input Voltage in V\n",
    "Vb = 6.; # Zerner Breakdown Voltage in V\n",
    "R = 5.*10**3; # resistance in ohm\n",
    "Rl = 2.*10**3; # load resistance in ohm\n",
    "#calculations\n",
    "Vr = Vin-Vb; # Volatge drop across resistor\n",
    "I = Vr/R; # current in A\n",
    "Il = Vb/Rl; # current  in A\n",
    "Iz = I - Il ;# current in A\n",
    "#(a)\n",
    "Vin1 = 41; # Input Voltage in V\n",
    "I1 = (Vin1-Vb)/R; # current in A\n",
    "Iz1 = I1-Iz; # current in A\n",
    "#(b)\n",
    "Rl1 = 4*10**3; #load  resistance in ohm\n",
    "Il1 = Vb/Rl1; # current in A\n",
    "Iz2 = I - Il1; # current in A\n",
    "#results\n",
    "print \"Input voltage = 41 V , Iz (mA) = \",Iz1*10**3\n",
    "print \"Load resistance = 4k ohm , Iz (mA) = \",Iz2*10**3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 5 - pg 430"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Voltage gain =  997.5\n"
     ]
    }
   ],
   "source": [
    "#pg 430\n",
    "#calculate the Voltage gain\n",
    "#Given :\n",
    "deltaIE = 2.; # in mA\n",
    "deltaIB = 5.; # in mA\n",
    "Rl = 200.*10**3; # load resistance in ohm\n",
    "ri = 200.; # input resistance in ohm\n",
    "# IE= IB + IC  ,   1 muA = 1.0*10**-3 mA\n",
    "#calculations\n",
    "deltaIC = deltaIE - deltaIB*10**-3 ;# in mA\n",
    "alpha = deltaIC/deltaIE; \n",
    "A = alpha*(Rl/ri);\n",
    "#results\n",
    "print \"Voltage gain = \",A\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
}
