{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 3 - AC to DC Converters"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3.1 page 117"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Power delivered = 199.11 W\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,cos,sin\n",
    "R=100    #  ohm\n",
    "Vs=230    #  V\n",
    "f=50    #  Hz\n",
    "alpha=45    #  degree\n",
    "\n",
    "Vo=Vs*sqrt(2)/2/pi*(1+cos(pi/180*alpha))    #  V\n",
    "Io=Vo/R    #  A\n",
    "Vor=Vs/sqrt(2)*sqrt(1/180*((180-alpha)+sin(pi/180*2*alpha)/2))    #  V\n",
    "Ior=Vor/R    #  A\n",
    "P=Ior**2*R    #  W\n",
    "print 'Power delivered = %.2f W'%(P)\n",
    "\n",
    "#Ans in the textbook is not accurate."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3.2 page 118"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Power supplied to battery = 593 W\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,asin,cos,sin\n",
    "\n",
    "R=10    #  ohm\n",
    "E=165    #  V\n",
    "#vt=330*sin(314*t)\n",
    "Vm=330    #  V\n",
    "f=314/2/pi    #  Hz\n",
    "alpha1=asin(E/Vm)    #  radian\n",
    "alpha2=pi-alpha1    #  radian\n",
    "Io=1/2/pi/R*(2*Vm*cos(alpha1)-E*(alpha2-alpha1))    #  A\n",
    "P=E*Io    #  W\n",
    "\n",
    "print 'Power supplied to battery = %d W'%(P)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3.3 page 119"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "part (a)\n",
      "\n",
      " dc voltage Vo = 88.3 V\n",
      "\n",
      " & Current Io = 4.415 A\n",
      "\n",
      "\n",
      " part (b)\n",
      "\n",
      " rms voltage Vor = 154.943 V\n",
      "\n",
      " & Current Ior = 7.747 A\n",
      "\n",
      "\n",
      " part (c)\n",
      "\n",
      " dc Power = 389.85 W\n",
      "\n",
      " ac Power = 1200.37 W\n",
      "\n",
      " Rectification efficiency = 0.3248\n",
      "\n",
      "\n",
      " part (d)\n",
      "\n",
      " Form factor = 1.755 \n",
      "\n",
      " Ripple factor = 1.442 \n",
      "\n",
      "\n",
      " part (e)\n",
      "\n",
      " VA rating = 1781.8 VA\n",
      "\n",
      " Transformer Utilization factor = 0.2188\n",
      "\n",
      "\n",
      " part (f)\n",
      "\n",
      " Peak inverse voltage = 325 V\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,cos,sin\n",
    "\n",
    "#v2t = 325*sin(w*t)\n",
    "R=20    #  ohm\n",
    "alfa=45    #  degree\n",
    "vm=325    #  V\n",
    "V=230    #  V\n",
    "print 'part (a)\\n'\n",
    "Vo=vm/2/pi*(1+cos(pi/180*alfa))     #  V\n",
    "Io=Vo/R    #  A\n",
    "print ' dc voltage Vo = %.1f V'%(Vo)\n",
    "print '\\n & Current Io = %.3f A'%(Io)\n",
    "print '\\n\\n part (b)\\n'\n",
    "Vor=vm/2/sqrt(pi)*sqrt((pi-pi/180*alfa)+1/2*sin(pi/180*2*alfa))    #  V\n",
    "Ior=Vor/R    #  A\n",
    "print ' rms voltage Vor = %.3f V'%(Vor)\n",
    "print '\\n & Current Ior = %.3f A'%(Ior)\n",
    "print '\\n\\n part (c)'\n",
    "Pdc=Vo*Io    #  W\n",
    "Pac=Vor*Ior    #  W\n",
    "eta=Pdc/Pac    #  rectification efficiency\n",
    "print \"\\n dc Power = %.2f W\"%(Pdc)\n",
    "print \"\\n ac Power = %.2f W\"%(Pac)\n",
    "print \"\\n Rectification efficiency = %.4f\"% (eta)\n",
    "print '\\n\\n part (d)'\n",
    "FF=Vor/Vo    #  form factor\n",
    "RF=sqrt(FF**2-1)\n",
    "print '\\n Form factor = %.3f '%(FF)\n",
    "print '\\n Ripple factor = %.3f '%(RF)\n",
    "print '\\n\\n part (e)'\n",
    "VA=V*Ior    #  VA\n",
    "TUF=Pdc/V/Ior    #  Transformer Utilization factor\n",
    "print \"\\n VA rating = %.1f VA\"%(VA)\n",
    "print \"\\n Transformer Utilization factor = %.4f\"%TUF\n",
    "print '\\n\\n part (f)'\n",
    "Vp=vm    #  V\n",
    "print \"\\n Peak inverse voltage = %d V\"%Vp"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3.4 page 120"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(a) Average value of current = 3.60 A\n",
      "\n",
      " (b) Power supplied to battery = 593 W\n",
      "\n",
      " (c) Power dissipated in the resistor = 1216.14 W\n",
      "\n",
      " (d) Power factor = 0.7043\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,cos,sin,asin\n",
    "\n",
    "R=10    #  ohm\n",
    "E=165    #  V\n",
    "#vt=330*sin(314*t)\n",
    "Vm=330    #  V\n",
    "Vs=233    #  V\n",
    "f=314/2/pi    #  Hz\n",
    "theta1=asin(E/Vm)    #  radian\n",
    "#alpha2=pi-alpha1    #  radian\n",
    "Io=1/2/pi/R*(2*Vm*cos(theta1)-E*(pi-2*theta1))    #  A\n",
    "print '(a) Average value of current = %.2f A'%(Io)\n",
    "P=E*Io    #  W\n",
    "print '\\n (b) Power supplied to battery = %d W'%(P)\n",
    "Ior=sqrt(1/2/pi/R**2*((pi-2*theta1)*(Vs**2+E**2)+Vm**2*sin(2*theta1)-4*Vm*E*cos(theta1)))    #  A\n",
    "Pr=Ior**2*R    #  W\n",
    "print '\\n (c) Power dissipated in the resistor = %.2f W'%(Pr)\n",
    "pf=(Pr+P)/Vs/Ior    #  power factor\n",
    "print '\\n (d) Power factor = %.4f'%(pf)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3.5 page 122"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average load voltage = 193.2 V\n",
      "\n",
      " Average load current = 9.66 A\n",
      "\n",
      " rms load current = 11.33 A\n",
      "\n",
      " Average thyristor current = 4.83 A\n",
      "\n",
      " rms thyristor current = 8.014 A\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,cos,sin\n",
    "\n",
    "R=20    #  ohm\n",
    "V=230    #  V\n",
    "f=50    #  Hz\n",
    "alpha=30    #  degree\n",
    "Vm=V*sqrt(2)    # V\n",
    "Vo=Vm/pi*(1+cos(alpha*pi/180))    #  V\n",
    "print 'Average load voltage = %.1f V'%(Vo)\n",
    "Io=Vo/R    #  A\n",
    "print '\\n Average load current = %.2f A'%( Io)\n",
    "Vor=V/sqrt(pi)*sqrt((pi-alpha*pi/180)+sin(2*alpha*pi/180)/2)    #  V\n",
    "Ior=Vor/R    #  A\n",
    "print '\\n rms load current = %.2f A'%( Ior)\n",
    "Iav=Io/2    # A\n",
    "print '\\n Average thyristor current = %.2f A'%( Iav)\n",
    "Irms=Ior/sqrt(2)    #  A\n",
    "print '\\n rms thyristor current = %.3f A'%( Irms)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3.6 page 122"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Average load current = 4.642 A\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,cos,sin\n",
    "\n",
    "R=10    #  ohm\n",
    "L=100/1000    #  H\n",
    "E=100    #  V\n",
    "Vs=230    #  V\n",
    "f=50    #  Hz\n",
    "alpha = 45    #  degree\n",
    "Vm=Vs*sqrt(2)    #  V\n",
    "Vo=2*Vm/pi*cos(alpha*pi/180)    #  V\n",
    "Io=(Vo-E)/R    #  A\n",
    "print 'Average load current = %.3f A'%(Io)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3.7 page 123"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " Average load voltage = 179.33 V\n",
      "\n",
      " Average load current = 89.67 A\n",
      "\n",
      " Power factor = 0.7797\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,cos,sin\n",
    "\n",
    "R=2    #  ohm\n",
    "L=0.3    #  H\n",
    "E=100    #  V\n",
    "Vs=230    #  V\n",
    "f=50    #  Hz\n",
    "alpha = 30    #  degree\n",
    "Vm=Vs*sqrt(2)    #  V\n",
    "Vo=2*Vm/pi*cos(alpha*pi/180)    #  V\n",
    "print ' Average load voltage = %.2f V'%( Vo)\n",
    "Io=(Vo)/R    #  A\n",
    "print '\\n Average load current = %.2f A'%( Io)\n",
    "Is=Io    #  A\n",
    "Is1=4*Io/pi/sqrt(2)    #  A\n",
    "PF=Vo*Io/Vs/Is    #  power factor\n",
    "print '\\n Power factor = %.4f'%(PF)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3.8 page 123"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " Average load voltage = 176.75 V\n",
      "\n",
      " Average load current = 33.35 A\n",
      "\n",
      " Power factor = 0.7685\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,cos,sin\n",
    "\n",
    "R=5    #  ohm\n",
    "L=1    #  H\n",
    "E=10    #  V\n",
    "Vs=230    #  V\n",
    "f=50    #  Hz\n",
    "alpha = 45    #  degree\n",
    "Vm=Vs*sqrt(2)    #  V\n",
    "Vo=Vm/pi*(1+cos(alpha*pi/180))    #  V\n",
    "print ' Average load voltage = %.2f V'%( Vo)\n",
    "Io=(Vo-E)/R    #  A\n",
    "print '\\n Average load current = %.2f A'%( Io)\n",
    "PF=(Io**2*R+E*Io)/Vs/Io    #  power factor\n",
    "print '\\n Power factor = %.4f'%(PF)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3.9 page 124"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " (i) Average voltage across 50 ohm resistor = 179.33 V\n",
      "\n",
      " (ii) rms current = 2.5361 A\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,cos,sin\n",
    "\n",
    "R=50    #  ohm\n",
    "Vs=230    #  V\n",
    "f=50    #  Hz\n",
    "alpha = 30    #  degree\n",
    "Vm=Vs*sqrt(2)    #  V\n",
    "Vo=2*Vm/pi*cos(alpha*pi/180)    #  V\n",
    "print ' (i) Average voltage across 50 ohm resistor = %.2f V'%( Vo)\n",
    "Io=(Vo)/R    #  A\n",
    "Ior=Io/sqrt(2)    #  A\n",
    "print '\\n (ii) rms current = %.4f A'%( Ior)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3.10 page 124"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "emf on load side = 123.54 V\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,cos,sin\n",
    "\n",
    "R=2    #  ohm\n",
    "Vs=230    #  V\n",
    "f=50    #  Hz\n",
    "alpha = 120    #  degree\n",
    "Ia=10    #  A\n",
    "\n",
    "Vo=2*sqrt(2)*Vs*cos(alpha*pi/180)/pi\n",
    "V=Ia*R-Vo    #  V\n",
    "print 'emf on load side = %.2f V'%( V)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3.11 page 125"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "part(i)\n",
      "\n",
      " dc output voltage = 146.4 V\n",
      "\n",
      " Active power = 732.1 W\n",
      "\n",
      " Reactive power = 732.1 VAR\n",
      "\n",
      "\n",
      " part(ii)\n",
      "\n",
      " dc output voltage = 176.7 V\n",
      "\n",
      " Active power = 1066.8 W\n",
      "\n",
      " Reactive power = -441.9 VAR\n",
      "\n",
      "\n",
      " part(iii)\n",
      "\n",
      " Average load voltage = 88 V\n",
      "\n",
      " Average load current = 3.02 A\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,cos,sin\n",
    "\n",
    "Vs=230    #  V\n",
    "Io=5    #  A\n",
    "alpha = 45    #  degree\n",
    "print 'part(i)'\n",
    "Vo=2*sqrt(2)*Vs/pi*cos(alpha*pi/180)    #  V\n",
    "print '\\n dc output voltage = %.1f V'%(Vo)\n",
    "Pi=Vo*Io    #  W\n",
    "print '\\n Active power = %.1f W'%(Pi)\n",
    "Qi=2*sqrt(2)*Vs/pi*sin(alpha*pi/180)*Io    #  VAR\n",
    "print '\\n Reactive power = %.1f VAR'%(Qi)\n",
    "print '\\n\\n part(ii)'\n",
    "R=Vo/Io    #  ohm\n",
    "Vo=sqrt(2)*Vs/pi*(1+cos(alpha*pi/180))    #  V\n",
    "print '\\n dc output voltage = %.1f V'%(Vo)\n",
    "Io=Vo/R    #  A\n",
    "Pi=Vo*Io    #  W\n",
    "print '\\n Active power = %.1f W'%(Pi)\n",
    "Qi=sqrt(2)*Vs/pi*sin(alpha*pi/4)*Io    #  VAR\n",
    "print '\\n Reactive power = %.1f VAR'%(Qi)\n",
    "print '\\n\\n part(iii)'\n",
    "Vo=sqrt(2)*Vs/pi/2*(1+cos(alpha*pi/180))    #  \n",
    "print '\\n Average load voltage = %.0f V'%(Vo)\n",
    "Io=Vo/R    #  A\n",
    "print '\\n Average load current = %.2f A'%(Io)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3.12 page 126"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Average load voltage = 467.818 V\n",
      "\n",
      " Average load current = 23.391 A\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,cos,sin\n",
    "\n",
    "R=20    #  ohm\n",
    "Vs=400    #  V\n",
    "f=50    #  Hz\n",
    "alpha = 30    #  degree\n",
    "\n",
    "Vm=Vs*sqrt(2)    #  V\n",
    "Vo=3*Vm/pi*cos(alpha*pi/180)    #  V\n",
    "Io=Vo/R    #  A\n",
    "print '\\n Average load voltage = %.3f V'%(Vo)\n",
    "print '\\n Average load current = %.3f A'%(Io)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3.13 page 126"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " (i)\n",
      "\n",
      " Output voltage = 270 V\n",
      "\n",
      " Output power = 27009 W\n",
      "\n",
      "\n",
      " (ii)\n",
      "\n",
      " average current through thyristor = 33.33 A\n",
      "\n",
      " rms current through thyristor = 57.74 A\n",
      "\n",
      " peak current through thyristor = 100.00 A\n",
      "\n",
      "\n",
      " (iii)\n",
      "\n",
      " PIV of thyristor = 565.7 V\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,cos,sin\n",
    "\n",
    "n=3    #  no. of phase\n",
    "Vs=400    #  V\n",
    "f=50    #  Hz\n",
    "Io=100    #  A\n",
    "alpha = 60    #  degree\n",
    "\n",
    "Vm=Vs*sqrt(2)    #  V\n",
    "Vo=n*Vm/pi*cos(alpha*pi/180)    #  V\n",
    "Po=Vo*Io    #  W\n",
    "print ' (i)'\n",
    "print '\\n Output voltage = %.0f V'%(Vo)\n",
    "print '\\n Output power = %.0f W'%(Po)\n",
    "print '\\n\\n (ii)'\n",
    "Iav=Io*2*pi/3/2/pi    #  A\n",
    "print '\\n average current through thyristor = %.2f A'%( Iav)\n",
    "Ior=sqrt(Io**2*2*pi/3/2/pi)    #  A\n",
    "print '\\n rms current through thyristor = %.2f A'%( Ior)\n",
    "Ip=Io    # A\n",
    "print '\\n peak current through thyristor = %.2f A'%( Ip)\n",
    "print '\\n\\n (iii)'\n",
    "PIV=sqrt(2)*Vs    # V\n",
    "print '\\n PIV of thyristor = %.1f V'%(PIV)\n",
    "# Ans in the book is not accurate."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3.14 page 127"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Average load voltage = 467.818 V\n",
      "\n",
      " Average load current = 7.8 A\n",
      "\n",
      " input power factor = 0.6752\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,cos,sin\n",
    "\n",
    "n=3    #  no. of phase\n",
    "R=60    #  ohm\n",
    "Vs=400    #  V\n",
    "alpha = 30    #  degree\n",
    "\n",
    "Vm=Vs*sqrt(2)    #  V\n",
    "Vo=3*Vm/pi*cos(alpha*pi/180)    #  V\n",
    "Io=Vo/R    #  A\n",
    "P=Io**2*R    #  W\n",
    "pf=P/sqrt(3)/Vs/Io    #  power factor\n",
    "\n",
    "print '\\n Average load voltage = %.3f V'%(Vo)\n",
    "print '\\n Average load current = %.1f A'%(Io)\n",
    "print '\\n input power factor = %.4f'%(pf)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3.15 page 127"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Average load voltage = 461.08 V\n",
      "\n",
      " Average load current = 9.22 A\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,cos,sin\n",
    "\n",
    "n=3    #  no. of phase\n",
    "R=50    #  ohm\n",
    "Vs=400    #  V\n",
    "f=50    #  Hz\n",
    "alpha = 45    #  degree\n",
    "\n",
    "Vm=Vs*sqrt(2)    #  V\n",
    "Vo=3*Vm/2/pi*(1+cos(alpha*pi/180))    #  V\n",
    "Io=Vo/R    #  A\n",
    "print '\\n Average load voltage = %.2f V'%(Vo)\n",
    "print '\\n Average load current = %.2f A'%(Io)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3.16 page 128"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Firing angle = 33.59 degree\n",
      "\n",
      " Overlap angle = 10.20 degree\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,cos,sin,acos\n",
    "\n",
    "n=3    #  no. of phase\n",
    "Vs=400    #  V\n",
    "f=50    #  Hz\n",
    "Ls=5/1000    #  H\n",
    "Io=20    #  A\n",
    "Ri=1    #  ohm\n",
    "Vdc=400    #  V\n",
    "\n",
    "Vo=Vdc+Io*Ri    #  V\n",
    "# Vo=3*Vm/pi*cos(alpha*pi/180)-3*2*pi*f*Ls/pi*Io\n",
    "Vm=sqrt(2)*Vs    #  V\n",
    "alpha=acos((Vo+3*2*pi*f*Ls/pi*Io)/(3*Vm/pi))*180/pi    #  degree\n",
    "\n",
    "# Vo=3*Vm/pi*cos((alpha+mu)*pi/180)-3*2*pi*f*Ls/pi*Io\n",
    "mu=acos((Vo-3*2*pi*f*Ls/pi*Io)/(3*Vm/pi))*180/pi-alpha    #  degree\n",
    "print '\\n Firing angle = %.2f degree'%(alpha)\n",
    "print '\\n Overlap angle = %.2f degree'%(mu)\n",
    "# ans in the textbook is not accurate."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ex 3.17 page 128"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " Load resistance = 36 ohm\n",
      "\n",
      " Source inductance = 7.3 mH\n",
      "\n",
      " Overlap angle = 6 degree\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import sqrt,pi,cos,sin,acos\n",
    "\n",
    "n=3    #  no. of phase\n",
    "Vs=400    #  V\n",
    "f=50    #  Hz\n",
    "alpha = pi/4    #  radian\n",
    "Io=10    #  A\n",
    "Vo=360    #  V\n",
    "\n",
    "# Vo=n*Vs*sqrt(2)/pi/sqrt(2)-3*2*pi*f*Ls*Io/pi\n",
    "Ls=(n*Vs*sqrt(2)/pi/sqrt(2)-Vo)/(3*2*pi*f)/(Io/pi)*1000    #  mH\n",
    "R=Vo/Io    #  ohm\n",
    "print ' Load resistance = %.f ohm'%(R)\n",
    "print '\\n Source inductance = %.1f mH'%(Ls)\n",
    "# Vo = n*Vs*sqrt(2)/pi*cos(alpha+mu)+3*2*pi*f*Ls*Io/pi\n",
    "mu=acos((Vo-3*2*pi*f*Ls/1000*Io/pi)/(n*Vs*sqrt(2)/pi))-alpha    #  radian\n",
    "mu=mu*180/pi    #  degree\n",
    "print '\\n Overlap angle = %.d degree'%(mu)"
   ]
  }
 ],
 "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
}