{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 3 Diode Applications"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_1 pg-3.14"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Refer to the circuit diagram shown in figure-3.7\n",
      "\n",
      " Therefore peak value of current is 10.75 mA \n",
      "\n",
      "\n",
      " Average current is 3.422 mA \n",
      "\n",
      "\n",
      " rms current is 5.375 mA \n",
      "\n",
      "\n",
      " DC output voltage is 34.22 V \n",
      "\n",
      "\n",
      " Efficiency is 40.19 % \n",
      "\n",
      "Ripple factor for half wave rectifier is 1.21\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "print \"Refer to the circuit diagram shown in figure-3.7\"\n",
    "Rf=75 #  diode forward resistance\n",
    "Rl=10e3 #  load resistance\n",
    "Rs=10 #  transformer secondary resistance\n",
    "Ep=230 #  rms value of primary voltage\n",
    "N2byN1=1/3 #  turns ratio\n",
    "Es=Ep*N2byN1 #  rms value of secondary voltage\n",
    "Esm=sqrt(2)*Es #  peak value of secondary voltage\n",
    "Im=Esm/(Rs+Rf+Rl)#\n",
    "Im=Im*1e3#\n",
    "print \"\\n Therefore peak value of current is %.2f mA \\n\"%(Im)\n",
    "Idc=Im/pi#\n",
    "print \"\\n Average current is %.3f mA \\n\"%(Idc)\n",
    "Irms=Im/2 #  for half wave rectifier\n",
    "print \"\\n rms current is %.3f mA \\n\"%(Irms)\n",
    "Idc1=Idc*1e-3#\n",
    "Edc=Idc1*Rl#\n",
    "print \"\\n DC output voltage is %.2f V \\n\"%(Edc)\n",
    "Pdc=Edc*Idc1 #  Dc output power\n",
    "Irms1=Irms*1e-3#\n",
    "Pac=Irms1**2*(Rs+Rf+Rl) #  AC output power\n",
    "n=Pdc/Pac*100 #  efficiency\n",
    "print \"\\n Efficiency is %.2f %% \\n\"%(n)\n",
    "print \"Ripple factor for half wave rectifier is 1.21\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_2 PG-3.15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Refer to the figure-3.8 shown\n",
      "For an ideal diode\n",
      "\n",
      " DC output voltage is -4.77 V\n",
      " \n",
      "-ve sign indicates that voltage is negative wrt ground\n",
      "For a silicon diode Vin=0.7V \n",
      "\n",
      " DC output voltage is -4.55 V\n",
      " \n",
      "-ve sign indicates that voltage is negative wrt ground\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "print \"Refer to the figure-3.8 shown\"\n",
    "Vin=0 #  cut-in voltage for an ideal diode is zero\n",
    "Rf=0 #  forward resistance for an ideaal diode is zero\n",
    "print \"For an ideal diode\"\n",
    "Vm=15#\n",
    "Vdc=-Vm/pi#\n",
    "print \"\\n DC output voltage is %.2f V\\n \"%(Vdc)\n",
    "print \"-ve sign indicates that voltage is negative wrt ground\"\n",
    "print \"For a silicon diode Vin=0.7V \"\n",
    "Vin=0.7#\n",
    "Vdc=-(Vm-Vin)/pi#\n",
    "print \"\\n DC output voltage is %.2f V\\n \"%(Vdc)\n",
    "print \"-ve sign indicates that voltage is negative wrt ground\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_3 PG-3.16"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "For an ideal diode Vin= 0V\n",
      "\n",
      " Dc voltage is 3.18 V and load current is 3.18 mA \n",
      "\n",
      "For a silicon diode Vin=0.7 V\n",
      "\n",
      " Dc voltage is 2.96 V and load current is 2.96 mA \n",
      "\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Rl=1 #  load resistance in kohm\n",
    "Vm=10#\n",
    "print \"For an ideal diode Vin= 0V\"\n",
    "Vin=0 #  for ideal diode\n",
    "Rf=0 #  for ideal diode\n",
    "Edc=Vm/pi#\n",
    "Idc=Edc/Rl#\n",
    "print \"\\n Dc voltage is %.2f V and load current is %.2f mA \\n\"%(Edc,Idc)\n",
    "print \"For a silicon diode Vin=0.7 V\"\n",
    "Vin=0.7#\n",
    "Edc=(Vm-Vin)/pi#\n",
    "Idc=Edc/Rl\n",
    "print \"\\n Dc voltage is %.2f V and load current is %.2f mA \\n\"%(Edc,Idc)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_4 Pg3.16"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " average output voltage is 95.493 V\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Esm=300 #  peak rms voltage\n",
    "Edc=Esm/pi #  average output voltage\n",
    "print \"\\n average output voltage is %.3f V\"%(Edc)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_5 PG-3.28"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " Power delivered to the load is 0.715 W \n",
      "\n",
      "\n",
      " Vnl=27.009489 \n",
      "\n",
      "\n",
      " Vfl=26.74 \n",
      "\n",
      "\n",
      " percentage regulation is 1.000000 % \n",
      "\n",
      "Efficiency of rectification =(DC output)/(AC output)\n",
      "\n",
      " Efficiency of rectification is 80.3 % \n",
      "\n",
      "\n",
      " TUF of secondary is 0.803\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Es=30 #  rms voltage\n",
    "Rf=2#\n",
    "Rs=8#\n",
    "Rl=1e3 #  in kohm\n",
    "Esm=sqrt(2)*Es #  peak value of voltage\n",
    "Im=Esm/(Rf+Rl+Rs) #  peak value of current\n",
    "Idc=2*Im/pi #  average current for full wave rectifier\n",
    "P=Idc**2*Rl#\n",
    "print \" Power delivered to the load is %.3f W \\n\"%(P)\n",
    "Vdc_noload=2*Esm/pi#\n",
    "print \"\\n Vnl=%f \\n\"%(Vdc_noload)\n",
    "Vdc_fullload=Idc*Rl#\n",
    "print \"\\n Vfl=%.2f \\n\"%(Vdc_fullload)\n",
    "reg=(Vdc_noload-Vdc_fullload)/Vdc_fullload*100#\n",
    "print \"\\n percentage regulation is %f %% \\n\"%(reg)\n",
    "print \"Efficiency of rectification =(DC output)/(AC output)\"\n",
    "x=(1+(Rf+Rs)/Rl)**(-1)#\n",
    "n=8/pi**2*x*100#\n",
    "print \"\\n Efficiency of rectification is %.1f %% \\n\"%(n)\n",
    "Irms=Im/sqrt(2)#\n",
    "AC_rating=Es*Irms#\n",
    "TUF=P/AC_rating#\n",
    "print \"\\n TUF of secondary is %.3f\"%(TUF)\n",
    "#The exact answer for percentage regulation is 1% not .97% as shown in the book ....\n",
    "#because in the book it has rounded off the value 27.009 to 27 only"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_6 PG-3.29"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Refer to the figure-3.16 shown\n",
      "We know Idc=Im/pi for each diode\n",
      "\n",
      " maximum peak to peak voltage is 628.32 V\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "print \"Refer to the figure-3.16 shown\"\n",
    "Rl=100#\n",
    "Idc=1 #  maximum value of DC current in each diode\n",
    "print \"We know Idc=Im/pi for each diode\"\n",
    "Vm=pi*Rl*Idc#\n",
    "Vp=2*Vm#\n",
    "print \"\\n maximum peak to peak voltage is %.2f V\"%Vp"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_7 PG-3.30"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Therefore o load DC output voltage is 9.0032 V \n",
      "\n",
      "We know that Idc=2Im/pi and Im=Esm/(Rf+rs+rl)\n",
      "\n",
      " DC output voltage at 100mA is 8.4032 V \n",
      " \n",
      "\n",
      " percentage regulation is 7.14 %\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Rf=1#\n",
    "Es=10#\n",
    "Rs=5#\n",
    "Esm=sqrt(2)*Es#\n",
    "Edc_nl=2*Esm/pi#\n",
    "print \"Therefore o load DC output voltage is %.4f V \\n\"%(Edc_nl)\n",
    "Idc=100e-3#\n",
    "print \"We know that Idc=2Im/pi and Im=Esm/(Rf+rs+rl)\"\n",
    "Im=Idc*pi/2#\n",
    "Rl=Esm/Im-Rf-Rs #  load resistance\n",
    "Edc_ol=Idc*Rl #  DC output voltage at 100mA\n",
    "print \"\\n DC output voltage at 100mA is %.4f V \\n \"%(Edc_ol)\n",
    "reg=(Edc_nl-Edc_ol)/Edc_ol*100#\n",
    "print \"\\n percentage regulation is %.2f %%\"%(reg)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_8 PG-3.31"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " We know that efficiency=Pdc/Pac \n",
      "for Half wave rectifier \n",
      "\n",
      " AC input power is 1231.527 W \n",
      "\n",
      "for Full wave rectifier \n",
      "\n",
      " AC input power is 615.764 W \n",
      "\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "Pdc=500 #  for half wave rectifier\n",
    "n=40.6 #  maximum efficiency for half wave rectifier\n",
    "print \" We know that efficiency=Pdc/Pac \"\n",
    "print \"for Half wave rectifier \"\n",
    "Pac=Pdc/n*100#\n",
    "print \"\\n AC input power is %.3f W \\n\"%(Pac)\n",
    "print \"for Full wave rectifier \"\n",
    "n=81.2 #  maximum efficiency for full wave rectifier \n",
    "Pac=Pdc/n*100#\n",
    "print \"\\n AC input power is %.3f W \\n\"%(Pac)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_9 PG-3.32"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average voltage is 24.55 V \n",
      "\n",
      "\n",
      " Efficiency is 73.69 %\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Rf=10#\n",
    "Rl=100#\n",
    "Es=30 #  transformer rms voltage\n",
    "Esm=sqrt(2)*Es #  peak value of the voltage\n",
    "Im=Esm/(Rf+Rl)#\n",
    "Idc=2*Im/pi#\n",
    "Edc=Idc*Rl#\n",
    "print \"Average voltage is %.2f V \\n\"%(Edc)\n",
    "Pdc=Idc**2*Rl#\n",
    "Irms=Im/sqrt(2) #  rms value of the current\n",
    "Pac=Irms**2*(Rf+Rl)#\n",
    "n=Pdc/Pac*100#\n",
    "print \"\\n Efficiency is %.2f %%\"%n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_10 PG-3.32"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "rms value of input current is 0.1000 A \n",
      "\n",
      "\n",
      " load value of current is 0.0900 A\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Es=100 #  rms value of current\n",
    "Rf=50 #  forward resistance\n",
    "Rl=950#\n",
    "Rs=0 #  resistance of the transformer secondary which is assumed to be 0 ohm\n",
    "Esm=sqrt(2)*Es #  peak value of the input voltage\n",
    "Im=Esm/(Rs+Rl+Rf)#\n",
    "Irms=Im/sqrt(2)#\n",
    "print \"rms value of input current is %.4f A \\n\"%(Irms)\n",
    "Idc=2*Im/pi#\n",
    "print \"\\n load value of current is %.4f A\"%(Idc)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_11 PG-3.38"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "We know that Im=Esm/(2Rf+Rs+Rl) for fullwave rectifier\n",
      "\n",
      " Therefore load resistance is 2.5 ohm \n",
      "\n",
      "\n",
      " Therefore efficiency is 75.05 % \n",
      "\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Rf=0.1#\n",
    "Idc=10#\n",
    "Rs=0#\n",
    "Es=30 #  rms value of input voltage\n",
    "Esm=sqrt(2)*Es #  peak value of the input voltage\n",
    "Im=Idc*pi/2 #  DC output current\n",
    "print \"We know that Im=Esm/(2Rf+Rs+Rl) for fullwave rectifier\"\n",
    "Rl=Esm/Im-2*Rf-0#\n",
    "print \"\\n Therefore load resistance is %.1f ohm \\n\"%(Rl)\n",
    "Pdc=Idc**2*Rl #  Dc output power rating\n",
    "Irms=Im/sqrt(2) #  rms value of input current\n",
    "Pac=Irms**2*(2*Rf+Rs+Rl) #  Ac input power\n",
    "n=Pdc/Pac*100 #  efficiency\n",
    "print \"\\n Therefore efficiency is %.2f %% \\n\"%(n)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_12 PG-3.39"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "  Therefore DC load current is 0.041415 A \n",
      "\n",
      "\n",
      "  DC load voltage is 207.073 V \n",
      "\n",
      "\n",
      "  Therefore ripple voltage is 99.8 V \n",
      "\n",
      " Peak value of bridge rectifier=PIV rating of each diode\n",
      "\n",
      "  Therefore PIV rating of each diode is 325.27 V\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Rl=5e3#\n",
    "N1toN2=2 #  transformer turns ratio\n",
    "Ep=460 #  rms value of primary voltage\n",
    "Es=Ep/N1toN2#\n",
    "Esm=sqrt(2)*Es #  peak value of the secondary voltage\n",
    "Im=Esm/Rl #  We neglect forward diode resistance\n",
    "Idc=2*Im/pi#\n",
    "print \"\\n  Therefore DC load current is %f A \\n\"%(Idc)\n",
    "Edc=Idc*Rl#\n",
    "print \"\\n  DC load voltage is %.3f V \\n\"%(Edc)\n",
    "Rf=.482 #  ripple factor for full bridge rectifier\n",
    "Vrip=Rf*Edc #  ripple voltage\n",
    "print \"\\n  Therefore ripple voltage is %.1f V \\n\"%(Vrip)\n",
    "print \" Peak value of bridge rectifier=PIV rating of each diode\"\n",
    "PIV=Esm#\n",
    "print \"\\n  Therefore PIV rating of each diode is %.2f V\"%(PIV)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_13 PG-3.40"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Therefore load voltage is 13.8 V\n",
      "\n",
      "\n",
      " ripple voltage is 6.6539 V\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Ep=230# #rms value of primary voltage\n",
    "N2toN1=1/15 #  turns ratio\n",
    "Rf=0 #  diode is ideal\n",
    "Rs=0 #  transformer is ideal\n",
    "Rl=50 #  load resistance\n",
    "Es=Ep*N2toN1 #  rms vaue of primary voltage\n",
    "Esm=sqrt(2)*Es #  peak value of input voltage\n",
    "Im=Esm/(Rs+2*Rf+Rl)#\n",
    "Idc=2*Im/pi#\n",
    "Edc=Idc*Rl #  load voltage\n",
    "print \"\\n Therefore load voltage is %.1f V\\n\"%(Edc)\n",
    "Rf=.482 #  ripple factor for full wave rectifier\n",
    "Vrip=Rf*Edc #  ripple voltage\n",
    "print \"\\n ripple voltage is %.4f V\"%(Vrip)\n",
    "#in the book the ripple voltage has been rounded off to \n",
    "#6.6516V but the actual ans is 6.6539V"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_14 PG-3.40"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " Average load current is 4.502 A \n",
      "\n",
      "\n",
      " Therefore efficiency is 81.06 % \n",
      "\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Rf=0 #  diode forward resistance\n",
    "Es=240 #  rms value of supply voltage\n",
    "Rl=48 #  load resistance\n",
    "Im=sqrt(2)*Es/(Rl+Rf)#\n",
    "Idc=2*Im/pi#\n",
    "print \" Average load current is %.3f A \\n\"%(Idc)\n",
    "Pdc=Idc**2*Rl#\n",
    "Irms=Im/sqrt(2) #  rms value of input current\n",
    "Pac=Irms**2*Rl#\n",
    "n=Pdc/Pac*100 #  efficiency\n",
    "print \"\\n Therefore efficiency is %.2f %% \\n\"%(n)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_15 PG-3.41"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " DC output voltage is 60.478878 V \n",
      "\n",
      "\n",
      " Therefore ripple factor is 0.4834 \n",
      "\n",
      "\n",
      " Therefore efficiency is 80.97 % \n",
      "\n",
      "Peak value of bridge rectifier=PIV rating of each diode\n",
      "\n",
      " Therefore PIV rating of each diode is 100.00 V\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Esm=100 #  peak value of supply voltage\n",
    "Rf=25 #  diode forward voltage\n",
    "Rl=950 #  load resistance\n",
    "Rt=(2*Rf)+Rl #  total resistance\n",
    "Im=Esm/Rt#\n",
    "Idc=2*Im/pi#\n",
    "Edc=Idc*Rl#\n",
    "print \"\\n DC output voltage is %f V \\n\"%(Edc)\n",
    "Irms=Im/sqrt(2) #  rms value of input current\n",
    "x=(Irms/Idc)**2-1#\n",
    "Rf=sqrt(x) #  ripple factor#\n",
    "print \"\\n Therefore ripple factor is %.4f \\n\"%(Rf)\n",
    "Pdc=Idc**2*Rl#\n",
    "Pac=Irms**2*(2*Rf+Rl) #  Ac input power\n",
    "n=Pdc/Pac*100 #  efficiency\n",
    "print \"\\n Therefore efficiency is %.2f %% \\n\"%(n)\n",
    "print \"Peak value of bridge rectifier=PIV rating of each diode\"\n",
    "PIV=Esm#\n",
    "print \"\\n Therefore PIV rating of each diode is %.2f V\"%(PIV)\n",
    "#In the book the answer for Edc=57.5985V which is wrong because they have taken \n",
    "#Rf=50 ohm instead of 25 ohm as given in the question similarly \n",
    "#the efficiency=73.3417% in the book is wrong \n",
    "#the correct answer for efficiency is 80.97%"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_16 PG-42"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Average DC voltage is 207 V \n",
      "\n",
      "\n",
      " Therefore DC load current is 2.07 A \n",
      "\n",
      "\n",
      " frequency of output waveform is 100 Hz\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Rl=100 #  load resistance\n",
    "Es=230 #  rms value of input voltage\n",
    "Rf=0 #  ideal diode resistance\n",
    "Rs=0 #  neglecting transformer resistance\n",
    "f=50 #  frequency of the supply\n",
    "Esm=sqrt(2)*Es #  peak value of the input voltage\n",
    "Edc=2*Esm/pi #  as Rf=0 ohm \n",
    "print \"\\n Average DC voltage is %.0f V \\n\"%(Edc)\n",
    "Im=Esm/Rl#\n",
    "Idc=2*Im/pi#\n",
    "print \"\\n Therefore DC load current is %.2f A \\n\"%(Idc)\n",
    "f=2*f #  frequency of output waveform\n",
    "print \"\\n frequency of output waveform is %.0f Hz\"%(f)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_17 PG-3.56"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " rms value of ripple voltage is 0.6 V \n",
      " \n",
      "\n",
      " ripple factor is 1.44 % \n",
      "\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Edc=12 #  output DC voltage\n",
    "f=50 #  frequency\n",
    "Idc=50e-3#\n",
    "C=100e-6 #  filter capacitor\n",
    "Rl=2e3 #  load resistance\n",
    "Vr=Edc/(2*f*C*Rl) #  rms value of ripple voltage\n",
    "print \"\\n rms value of ripple voltage is %.1f V \\n \"%(Vr)\n",
    "Rf=(4*sqrt(3)*f*C*Rl)**(-1)*100 #  ripple factor\n",
    "print \"\\n ripple factor is %.2f %% \\n\"%(Rf)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_18 PG-3.56"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " DC output voltage is 167.2056 V \n",
      "\n",
      "\n",
      " rms value of ripple voltage is 1.4434 V \n",
      " \n",
      "\n",
      " ripple factor is 0.008632 \n",
      "\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Es=120 #  rms value of input voltage\n",
    "f=50 #  frequency\n",
    "Idc=50e-3#\n",
    "C=100e-6 #  filter capacitor\n",
    "Esm=sqrt(2)*Es#\n",
    "Edc=Esm-Idc/(4*f*C)#\n",
    "print \"\\n DC output voltage is %.4f V \\n\"%(Edc)\n",
    "Vr=Idc/(4*sqrt(3)*f*C) #  rms value of ripple voltage\n",
    "print \"\\n rms value of ripple voltage is %.4f V \\n \"%(Vr)\n",
    "Rf=Vr/Edc#\n",
    "print \"\\n ripple factor is %f \\n\"%(Rf)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_19 PG-3.56"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Therefore load voltage is 20.7 V \n",
      "\n",
      "\n",
      " Ripple factor is 0.48\n",
      "\n",
      " ripple voltage is 9.9395 V \n",
      "\n",
      "If the capacitor filter is used then\n",
      "\n",
      " new DC load voltage is 28.12 V \n",
      "\n",
      "\n",
      " Ripple factor is 0.1228\n",
      "\n",
      " rms value of ripple voltage is 3.4544 V \n",
      " \n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Ep=230 #  rms value of primary voltage\n",
    "N1toN2=10 #  turns ratio\n",
    "Rl=50 #  load resistance\n",
    "f=50 #  frequency of the supply in Hz\n",
    "Es=Ep/N1toN2 #  rms vaue of secondary voltage or the input voltage\n",
    "Esm=sqrt(2)*Es #  peak value of input voltage\n",
    "Im=Esm/(Rl)#\n",
    "Idc=2*Im/pi#\n",
    "Edc=Idc*Rl #  load voltage\n",
    "print \"\\n Therefore load voltage is %.1f V \\n\"%(Edc)\n",
    "Rf=.48 #  ripple factor for full wave rectifier without filter\n",
    "Vrip=Rf*Edc #  ripple voltage\n",
    "print \"\\n Ripple factor is 0.48\"\n",
    "print \"\\n ripple voltage is %.4f V \\n\"%(Vrip)\n",
    "print \"If the capacitor filter is used then\"\n",
    "C=470e-6 #  filter capacitor\n",
    "Edc=Esm-Idc/(4*f*C)#\n",
    "print \"\\n new DC load voltage is %.2f V \\n\"%(Edc)\n",
    "Rf=((4*sqrt(3)*f*C*Rl))**(-1) #   new ripple factor\n",
    "Vrip=Rf*Edc #  new ripple voltage\n",
    "print \"\\n Ripple factor is %.4f\"%(Rf)\n",
    "print \"\\n rms value of ripple voltage is %.4f V \\n \"%(Vrip)\n",
    "# in the book the new ripple factor is 3.256e-3 which is wrong \n",
    "#the actual answer is 0.1228 hence the new ripple voltage is 3.4544V \n",
    "# not 0.09156V as shown in the book "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_20 PG-3.57"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the %ripple factor=Rf=((4*sqrt(3)*f*C*Rl))**(-1)*100 \n",
      "\n",
      " the filter capacitor is 14.434 mF\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Rf=.01 #  ripple factor in percentage\n",
    "Rl=2 #  load resistance in kohm\n",
    "f=50 #  frequency\n",
    "print \"the %ripple factor=Rf=((4*sqrt(3)*f*C*Rl))**(-1)*100 \"\n",
    "C=((4*sqrt(3)*f*Rf*Rl))**(-1)*100 #  filter capacitor\n",
    "print \"\\n the filter capacitor is %.3f mF\"%(C)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_21 PG-3.58"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " ripple factor is 3.40 % \n",
      "\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Idc=100e-3 #  average current\n",
    "C=500e-6 #  filter capacitor\n",
    "Esm=18 #  peak voltage\n",
    "f=50 #  frequency of the supply in Hz\n",
    "Edc=Esm-Idc/(4*f*C)#\n",
    "Rl=Edc/Idc #  load resistance\n",
    "Rf=(4*sqrt(3)*f*C*Rl)**(-1)*100 #  ripple factor\n",
    "print \"\\n ripple factor is %.2f %% \\n\"%(Rf)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_22 PG-3.58"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "conduction period of diode,T1=1ms\n",
      "Edc=Esm-Idc/(2*f*C) and Idc=Edc/Rl\n",
      "\n",
      " hence the diode should be rated for a minimum surge\n",
      " current of 6.66 A \n",
      "\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "f=50 #  frequency\n",
    "C=1000e-6 #  filter capacitor\n",
    "Rl=500 #  load resistance\n",
    "Vrms=120 #  rms value of voltage\n",
    "T1=1e-3 #  conduction period of diode,T1=1ms\n",
    "print \"conduction period of diode,T1=1ms\"\n",
    "Esm=sqrt(2)*Vrms #  peak value of input voltage\n",
    "print \"Edc=Esm-Idc/(2*f*C) and Idc=Edc/Rl\"\n",
    "Edc=Esm/(1+(2*Rl*f*C)**(-1)) #  output dc voltage\n",
    "Idc=Edc/Rl#\n",
    "T=1/f#\n",
    "#Idc*T=Ip*T1\n",
    "#Ip is the surge current\n",
    "Ip=Idc*T/T1#\n",
    "print \"\\n hence the diode should be rated for a minimum surge\\n current of %.2f A \\n\"%(Ip)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_23 PG-3.59"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " rms value of ripple voltage is 1 V \n",
      " \n",
      "\n",
      " peak to peak voltage is 2.8284 V \n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Rf=0.1 #  riplle facto\n",
    "Edc=10#\n",
    "Vrip=Rf*Edc #  rms value of voltage\n",
    "print \"\\n rms value of ripple voltage is %.0f V \\n \"%(Vrip)\n",
    "Vp_p=2*sqrt(2)*Vrip#\n",
    "print \"\\n peak to peak voltage is %.4f V \"%(Vp_p)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_24 PG-3.59"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Therefore DC output voltage is 207.07 V \n",
      "\n",
      "if the capacitor filter C=1000e-6 is use then \n",
      "\n",
      " ripple factor is 0.0289 \n",
      "\n",
      "\n",
      " Therefore new DC load voltage is 314.9155 V \n",
      "\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Es=230 #  rms value of input voltage\n",
    "f=50 #  frequency\n",
    "Idc=50e-6#\n",
    "Rl=100 #  load resistance\n",
    "C=1000e-6 #  filter capacitor\n",
    "Esm=sqrt(2)*Es#\n",
    "Edc=2*Esm/pi#\n",
    "print \"\\n Therefore DC output voltage is %.2f V \\n\"%(Edc)\n",
    "Idc=Edc/Rl#\n",
    "print \"if the capacitor filter C=1000e-6 is use then \"\n",
    "Rf=(4*sqrt(3)*f*C*Rl)**(-1) #  ripple factor\n",
    "print \"\\n ripple factor is %.4f \\n\"%(Rf)\n",
    "Edc=Esm-Idc/(4*f*C)#\n",
    "print \"\\n Therefore new DC load voltage is %.4f V \\n\"%(Edc)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_25 Pg-3.60"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " For a half wave rectifier Ripple factor=(2*sqrt(3)*f*C*Rl)**(-1)\n",
      "\n",
      "  Therefore capacitance required is 5.576 mF\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Es=230#\n",
    "f=50#frequency\n",
    "Rf=.005 #  ripple factor\n",
    "Il=0.5 #  average load current\n",
    "Esm=sqrt(2)*Es #  peak value of input voltage\n",
    "print \" For a half wave rectifier Ripple factor=(2*sqrt(3)*f*C*Rl)**(-1)\"\n",
    "Edc=Esm/pi#for half wave rectifier\n",
    "Rl=Edc/Il#\n",
    "C=(2*sqrt(3)*f*Rf*Rl)**(-1) #  for half wave rectifier\n",
    "C=C*1e3#\n",
    "print \"\\n  Therefore capacitance required is %.3f mF\"%(C)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_26 PG-3.60"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " ripple factor is 5.77 10**(-6) \n",
      "\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Rl=1000#\n",
    "C=500e-3\n",
    "f=50#\n",
    "Rf=(4*sqrt(3)*f*C*Rl)**(-1) #  ripple factor\n",
    "Rf=Rf*1e6#\n",
    "print \"\\n ripple factor is %.2f 10**(-6) \\n\"%(Rf)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_27 PG-3.60"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " For a half wave rectifier Ripple factor=1/(2*sqrt(3)*f*C*Rl)\n",
      "\n",
      "  Therefore minimum value of capacitance required is 9.619 microF\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Il=12e-3 #  load current\n",
    "Es=200 #  rms voltage\n",
    "Rf=0.02 #  riplle factor\n",
    "Esm=sqrt(2)*Es #  peak value of input voltage\n",
    "Edc=2*Esm/pi#\n",
    "Idc=Il#\n",
    "Rl=Edc/Idc #  load resistance\n",
    "f=50 #  frequency of the supply in Hz\n",
    "print \" For a half wave rectifier Ripple factor=1/(2*sqrt(3)*f*C*Rl)\"\n",
    "C=(4*sqrt(3)*f*Rf*Rl)**(-1) #  filter capacitor\n",
    "print \"\\n  Therefore minimum value of capacitance required is %.3f microF\"%(C*1e6)\n",
    "#C=9.619 microF not 9.622 microF"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_28 PG-3.61"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Therefore capacitance required is 13.94  microF\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Es=230 #  rms voltage\n",
    "f=50#\n",
    "Il=10e-3 #  load current\n",
    "Rf=.01 #  ripple factor\n",
    "Esm=sqrt(2)*Es #  peak value of input voltage\n",
    "Edc=2*Esm/pi #  for full wave\n",
    "Rl=Edc/Il#\n",
    "C=(4*sqrt(3)*f*Rf*Rl)**(-1) #  for full wave rectifier\n",
    "C=C*1e6#\n",
    "print \"\\n Therefore capacitance required is %.2f  microF\"%(C)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_29 PG-3.61"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Therefore Average DC load current is 0.09 A \n",
      "\n",
      "\n",
      " Therefore average DC voltage is 180 V \n",
      "\n",
      "\n",
      " rms value of ripple voltage is 86.4 V \n",
      " \n",
      "if a filter capacitor C=500 microF is used then\n",
      "\n",
      " rms value of new ripple voltage is 0.5198 V \n",
      " \n"
     ]
    }
   ],
   "source": [
    "from math import sqrt, pi\n",
    "from __future__ import division\n",
    "Rl=2e3 #  load resistance\n",
    "Es=200 #  rms voltage\n",
    "f=50#\n",
    "Esm=sqrt(2)*Es #  peak value of input voltage\n",
    "Rf=0 #  ideal diodes\n",
    "Rs=0#\n",
    "Ism=Esm/(Rf+Rs+Rl)#\n",
    "Idc=2*Ism/pi#\n",
    "print \"\\n Therefore Average DC load current is %.2f A \\n\"%(Idc)\n",
    "Edc=Idc*Rl#\n",
    "print \"\\n Therefore average DC voltage is %.0f V \\n\"%(Edc)\n",
    "Rf=0.48 #  ripple factor\n",
    "Vrip=Rf*Edc #   ripple voltage\n",
    "print \"\\n rms value of ripple voltage is %.1f V \\n \"%(Vrip)\n",
    "print \"if a filter capacitor C=500 microF is used then\"\n",
    "C=500e-6 #  capacitor filter\n",
    "Rf=(4*sqrt(3)*f*C*Rl)**(-1) #  for full wave rectifier\n",
    "Vrip=Rf*Edc #  new ripple voltage\n",
    "print \"\\n rms value of new ripple voltage is %.4f V \\n \"%(Vrip)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_30 PG-3.67"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " percentage load regulation is +2.04 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "Vnl=10 #  no load output voltage\n",
    "Vfl=9.8 #  full output voltage\n",
    "LR=Vnl-Vfl #  load regulation\n",
    "LR=(Vnl-Vfl)/Vfl*100 #  percentage load regulation\n",
    "print \"\\n percentage load regulation is +%.2f %%\"%(LR)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_31 PG-3.67"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " percentage load regulation is +0.02 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "LR=3e-3 #  load regulation\n",
    "Vnl=15 #  no load voltage or maximum voltage\n",
    "Vfl=Vnl-LR #  full load voltage\n",
    "LR=(Vnl-Vfl)/Vfl*100 #  percentage load regulation\n",
    "print \"\\n percentage load regulation is +%.2f %%\"%(LR)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_32 PG-3.67"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " percentage source regulation is 6 %\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "\n",
    "Vhl=10+.3 #  high line voltage\n",
    "Vll=10-.3 #  low line voltage\n",
    "SR=Vhl-Vll #  source regulation\n",
    "Vnom=10 #  nominal load voltage\n",
    "SR=SR/Vnom*100 #  percentage source regulation\n",
    "print \"\\n percentage source regulation is %.0f %%\"%(SR)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_33 PG-3.70"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Refer to the figure-3.45 shown\n",
      "\n",
      " minimum input voltage(Vin_min) is 25.02 V \n",
      "\n",
      "\n",
      " maximum input voltage(Vin_max) is 74.52 V \n",
      "\n",
      "\n",
      " range of input voltage is from 25.020 V to 74.52 V \n",
      "\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "print \"Refer to the figure-3.45 shown\"\n",
    "Vz=6.1 #  zener voltage\n",
    "Iz_min=2.5e-3 #  minimum zener current\n",
    "Iz_max=25e-3 #  maximum zener current\n",
    "rZ=0 #  ideal zener diode\n",
    "R=2.2e3#\n",
    "Rl=1e3 #  loadd resistance\n",
    "Il=Vz/Rl#\n",
    "#For minimum input voltage(Vin_min)\n",
    "Iz=Iz_min\n",
    "I=Iz_min+Il#\n",
    "Vin_min=Vz+I*R#\n",
    "print \"\\n minimum input voltage(Vin_min) is %.2f V \\n\"%(Vin_min)\n",
    "#For maximum input voltage(Vin_max)\n",
    "I=Iz_max+Il#\n",
    "Vin_max=Vz+I*R#\n",
    "print \"\\n maximum input voltage(Vin_max) is %.2f V \\n\"%(Vin_max)\n",
    "print \"\\n range of input voltage is from %.3f V to %.2f V \\n\"%(Vin_min,Vin_max)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_34 PG-3.70"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Step1 : Maximum power dissipation correesponds to Iz_max\n",
      "\n",
      " maximum current that should flow through the zener diode is 0.1 A \n",
      "\n",
      "Step2 : We know that Il is constant\n",
      "\n",
      " minimum resistance required is 83.33 ohm \n",
      "\n",
      "Iz is maximum when R=Rminimum\n",
      "Step3 : for calculation of Rmax I must be minimum ie I=Iz_min \n",
      "\n",
      " maximum resistance required is 133.33 ohm \n",
      "\n",
      "\n",
      " Thus R must be greater than 83.33 ohm and less than \n",
      " 133.33 ohm for proper regulation \n",
      "\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "Vo=5 #  output voltage\n",
    "Vin_min=12-3 #  min input voltage\n",
    "Vin_max=12+3 #  max input voltage\n",
    "Iz_min=10e-3 #  minimum zener current\n",
    "Il=20e-3 #  load current\n",
    "Pz=500e-3 #  Zener wattage\n",
    "Vz=Vo #  zener voltage\n",
    "print \"Step1 : Maximum power dissipation correesponds to Iz_max\"\n",
    "Iz_max=Pz/Vz#\n",
    "print \"\\n maximum current that should flow through the zener diode is %.1f A \\n\"%(Iz_max)\n",
    "print \"Step2 : We know that Il is constant\"\n",
    "#for Vin_max, Iz=Iz_max\n",
    "I=Il+Iz_max#\n",
    "Rmin=(Vin_max-Vz)/I#\n",
    "print \"\\n minimum resistance required is %.2f ohm \\n\"%(Rmin)\n",
    "print \"Iz is maximum when R=Rminimum\"\n",
    "print \"Step3 : for calculation of Rmax I must be minimum ie I=Iz_min \"\n",
    "I=Il+Iz_min\n",
    "Rmax=(Vin_min-Vz)/I#\n",
    "print \"\\n maximum resistance required is %.2f ohm \\n\"%(Rmax)\n",
    "print \"\\n Thus R must be greater than %.2f ohm and less than \\n %.2f ohm for proper regulation \\n\"%(Rmin,Rmax)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_35 PG-3.72"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "refer to the figure-3.47 shown\n",
      "\n",
      " minimum load current is 8.33 mA \n",
      "\n",
      "\n",
      " maximum load current is 28.33 mA \n",
      "\n",
      "\n",
      " minimum load resistance is 352.941 ohm \n",
      "\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "print \"refer to the figure-3.47 shown\"\n",
    "Vz=10 #  output voltage\n",
    "Vin=20 #  input voltage\n",
    "Iz_max=25e-3 #  maximum zener current\n",
    "Iz_min=5e-3 #  minimum zener current\n",
    "R=300#\n",
    "Rz=0 #  zener resistance\n",
    "I=(Vin-Vz)/R#\n",
    "#for Il_min Iz=Iz_max\n",
    "Il_min=I-Iz_max #  minimum load current\n",
    "print \"\\n minimum load current is %.2f mA \\n\"%(Il_min*1e3)\n",
    "#for Il_max, Iz=Iz_min\n",
    "Il_max=I-Iz_min #  maximum load current\n",
    "print \"\\n maximum load current is %.2f mA \\n\"%(Il_max*1e3)\n",
    "Rl_min=Vz/Il_max #  minimum load resistance\n",
    "print \"\\n minimum load resistance is %.3f ohm \\n\"%(Rl_min)\n",
    "# in the book in the question it given that Iz_max=50mA\n",
    "#but during the solution Iz_max is taken as 25mA I have taken Iz_max=25mA\n",
    "# in this program "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_38  Pg-3.75"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " maximum resistance required is 160 ohm \n",
      "\n",
      "\n",
      " minimum resistance required is 83.33 ohm \n",
      "\n",
      "\n",
      " So series resistance must be selected between 83.33 ohm to 160 ohm \n",
      "\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "Vo=5#\n",
    "Il=20e-3#\n",
    "Pz=500e-3#\n",
    "Rl=Vo/Il#\n",
    "Il_min=Il #  minimum load current\n",
    "Il_max=Il #  maximum load current\n",
    "Iz_max=Pz/Vo #  maximum zener current\n",
    "Iz_min=5e-3 #  minimum zener current\n",
    "V=12 #  input DC voltage\n",
    "Vin_min=12-3 #  min input voltage\n",
    "Vin_max=12+3 #  max input voltage\n",
    "Rmax=(Vin_min-Vo)/(Il_max+Iz_min)#\n",
    "print \"\\n maximum resistance required is %.0f ohm \\n\"%(Rmax)\n",
    "Rmin=(Vin_max-Vo)/(Il_min+Iz_max)#\n",
    "print \"\\n minimum resistance required is %.2f ohm \\n\"%(Rmin)\n",
    "print \"\\n So series resistance must be selected between %.2f ohm to %.0f ohm \\n\"%(Rmin,Rmax)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_39 Pg-3.76"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " maximum resistance required is 833.33 ohm \n",
      "\n",
      "\n",
      " minimum resistance required is 400 ohm \n",
      "\n",
      "\n",
      " So series resistance must be selected between 400 ohm to 833.33 ohm \n",
      "\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "Vo=10#\n",
    "Il_min=0 #  mainimum load current\n",
    "Il_max=10e-3 #  maximum load current\n",
    "Iz_max=50e-3 #  maximum zener current\n",
    "Iz_min=2e-3 #  minimum zener current\n",
    "Vin_min=20 #  min input voltage\n",
    "Vin_max=30 #  max input voltage\n",
    "Rl_min=Vo/Il_max#\n",
    "Rmax=(Vin_min-Vo)/(Il_max+Iz_min)#\n",
    "print \"\\n maximum resistance required is %.2f ohm \\n\"%(Rmax)\n",
    "Rmin=(Vin_max-Vo)/(Il_min+Iz_max)#\n",
    "print \"\\n minimum resistance required is %.0f ohm \\n\"%(Rmin)\n",
    "print \"\\n So series resistance must be selected between %.0f ohm to %.2f ohm \\n\"%(Rmin,Rmax)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_40  Pg-3.76"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " minimum resistance required is 320 ohm \n",
      "\n",
      "\n",
      " As Vin and Il are not changing R=Rmin=320 ohm\n",
      " is sufficient to work as a regulator\n",
      "\n",
      "For Rl=1200 ohm\n",
      " \n",
      " load current is: 0.02 A \n",
      "\n",
      "\n",
      " zener current is :0.005 A \n",
      "\n",
      " As Iz=Iz_min=0.005 A, the circuit will work as a regulator\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "Vo=24#\n",
    "Il_min=0 #  minimum load current\n",
    "Pz=600e-3#\n",
    "Vin=32 #  input voltage\n",
    "Iz_max=Pz/Vo#\n",
    "Rmin=(Vin-Vo)/(Il_min+Iz_max)#\n",
    "print \"\\n minimum resistance required is %.0f ohm \\n\"%(Rmin)\n",
    "print \"\\n As Vin and Il are not changing R=Rmin=%.0f ohm\\n is sufficient to work as a regulator\\n\"%(Rmin)\n",
    "print \"For Rl=1200 ohm\"\n",
    "Rl=1200#\n",
    "Il=Vo/Rl#\n",
    "print \" \\n load current is: %.2f A \\n\"%(Il)\n",
    "R=Rmin\n",
    "It=(Vin-Vo)/R#\n",
    "Iz=It-Il#\n",
    "print \"\\n zener current is :%.3f A \\n\"%(Iz)\n",
    "print \" As Iz=Iz_min=%.3f A, the circuit will work as a regulator\"%(Iz)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3_41 PG-3.79"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " maximum series resistance is 139.725 ohm \n",
      "\n",
      "\n",
      " maximum load current is 0.0443827 A \n",
      "\n",
      "\n",
      " voltage stability factor  is 0.052 \n",
      "\n",
      "\n",
      " line regulation is 0.9629 % \n",
      "\n",
      "\n",
      " load regulation is 4.1461 % \n",
      "\n",
      "\n",
      " ripple rejection ratio is 0.052 \n",
      "\n",
      "\n",
      " output resistance is 7.567 ohm \n",
      "\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "Pd=400e-3#\n",
    "Vz=8.1 #  output voltage\n",
    "Vo=Vz#\n",
    "Zz=8#\n",
    "Vin=15#\n",
    "Izm=Pd/Vz#\n",
    "Rmax=(Vin-Vz)/Izm#\n",
    "print \"\\n maximum series resistance is %.3f ohm \\n\"%(Rmax)\n",
    "Iz_min=5e-3 #  we select the minimum zener current\n",
    "Il_max=Izm-Iz_min #  maximum load current\n",
    "print \"\\n maximum load current is %.7f A \\n\"%(Il_max)\n",
    "Rl=Vz/Il_max #  load resistance\n",
    "deltaVin=.1*Vin #  change in input voltage is equal to 10% of the original input voltage\n",
    "R=Rmax #  series resistance\n",
    "x=(Rl*Zz)/(Rl+Zz)#\n",
    "deltaVo=(deltaVin*x)/(R+x)#\n",
    "Sv=deltaVo/deltaVin #  voltage stability factor \n",
    "print \"\\n voltage stability factor  is %.3f \\n\"%(Sv)\n",
    "SR=deltaVo/Vo*100 #   line regulation for a 10% change in Vin\n",
    "print \"\\n line regulation is %.4f %% \\n\"%(SR)\n",
    "deltaIL=Il_max#\n",
    "y=(R*Zz)/(R+Zz)\n",
    "deltaVo=deltaIL*y#\n",
    "LR=deltaVo/Vo*100 #  load regulation  \n",
    "print \"\\n load regulation is %.4f %% \\n\"%(LR)\n",
    "z=(Rl*Zz)/(Rl+Zz)\n",
    "RR=z/(R+z) #  ripple rejection ratio\n",
    "print \"\\n ripple rejection ratio is %.3f \\n\"%(RR)\n",
    "Ro=y #  output resistance\n",
    "print \"\\n output resistance is %.3f ohm \\n\"%(Ro)"
   ]
  }
 ],
 "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
}
