{
 "metadata": {
  "name": "",
  "signature": "sha256:2ec5bac642048fe4f0a8791f1d0a50f56c601f2689b76ecde0a87424ce5a550e"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 1: Review of Electric Circuit Theory"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 1.1, Page 5"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Calculations&Results\n",
      "#on applying KVL we get \n",
      "i=75./50;#in Amperes\n",
      "v_th=(30*i)+25;#Equivalent Thevenin voltage (in Volts)\n",
      "r_th=(20*30)/(20+30);#Equivalent thevenin resistance (in Ohms)\n",
      "R_load=r_th;#Load resistance=thevenin resistance (in Ohms)\n",
      "print \"load resistance (in ohms)= %.f\"%R_load #in ohms\n",
      "i_load=v_th/(r_th+R_load);#in Amperes\n",
      "p_max=(i_load**2)*r_th;#in Watts\n",
      "print 'max power (in watts)= %.2f'%p_max#maximum power dissipiated "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "load resistance (in ohms)= 12\n",
        "max power (in watts)= 102.08\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 1.2, Page 13"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "import cmath\n",
      "import matplotlib.pyplot as plt\n",
      "import numpy as np\n",
      "\n",
      "#Variable declaration\n",
      "#Refer to figure 1.5a\n",
      "L=1*10**-3;#henery\n",
      "R=3.;#ohms\n",
      "C=200*10**-6;#faraday\n",
      "print \"v(t)=14.142cos1000t\"\n",
      "V_m=14.142;#Peak value of applied voltage (in Volts)\n",
      "\n",
      "#Calculations&Results\n",
      "V=V_m/math.sqrt(2);#RMS value of applied voltage (in Volts)\n",
      "#On comparing with standard equation v(t)=acoswt\n",
      "w=1000;#in radian/second\n",
      "#Inductive impedance=jwL\n",
      "Z_L=complex(0,w*L);#in ohms\n",
      "#capacitive impedance=-j/wC\n",
      "Z_c=complex(0,-1/(w*C));#in ohms\n",
      "#Impedance of the circuit is given by\n",
      "Z=Z_L+Z_c+R;#in ohms\n",
      "I=V/Z#Current in the circuit#in Amperes\n",
      "r=I.real;\n",
      "i=I.imag;\n",
      "magn_I=math.sqrt((r**2)+(i**2));#magnitude of current (in Amperes)\n",
      "phase_I=math.degrees(math.atan(i/r));#phase of current (in degree)\n",
      "print 'magnitude of current (in Amperes)= %.f'%magn_I\n",
      "print 'phase of current (in Degrees) = %.2f'%phase_I\n",
      "\n",
      "Vr = I*R\n",
      "Vl = I*Z_L\n",
      "Vc = I*Z_c\n",
      "print \"\\nCurrent in time domain is:\\ni(t)=2.828cos(1000t+53.13)A\"\n",
      "S = V*I   #complex power supplied by source(VA)\n",
      "magn_S = math.sqrt((S.real**2)+(S.imag**2))\n",
      "print \"\\nApparent power S = %.f VA\"%magn_S\n",
      "print \"Reactive power P = %.f W\"%S.real\n",
      "print \"Reactive power Q = %.f VAR\"%(-S.imag)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "v(t)=14.142cos1000t\n",
        "magnitude of current (in Amperes)= 2\n",
        "phase of current (in Degrees) = 53.13\n",
        "\n",
        "Current in time domain is:\n",
        "i(t)=2.828cos(1000t+53.13)A\n",
        "\n",
        "Apparent power S = 20 VA\n",
        "Reactive power P = 12 W\n",
        "Reactive power Q = -16 VAR\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 1.3, Page 17"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "import cmath\n",
      "\n",
      "#Variable declaration\n",
      "I=10;#Current drawn by the load (in Amperes)\n",
      "pf1=0.5;#lagging power factor\n",
      "pf2=0.8;\n",
      "V=120;#source voltage (in Volts)\n",
      "f=60;#frequency of source (in Hertz)\n",
      "\n",
      "#Calculations\n",
      "Vl = complex(120,0)\n",
      "Il = complex(5,8.66)   #10/_60  in polar\n",
      "S = Vl*Il\n",
      "i = 600/(V*pf2)   #Since power at source is 600W\n",
      "\n",
      "#Refer to fig 1.6(b)\n",
      "#I_Lc=I_L+I_c\n",
      "I = complex(5,-3.75)    #Writing I from polar to cartesian form\n",
      "Il = complex(5,-8.66)   #Writing Il from polar to cartesian forms\n",
      "Ic = I - Il\n",
      "Zc = V/Ic\n",
      "Xc = Zc/complex(0,1)\n",
      "C = 1/(2*math.pi*f*Xc)\n",
      "\n",
      "#Result\n",
      "print \"The required value of capacitor is %.2f\"%(C.real*10**6)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The required value of capacitor is -108.53\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 1.4, Page 26"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "import cmath\n",
      "\n",
      "#Variable declaration\n",
      "#Make delta -star conversion of load\n",
      "Z_L=complex(1,2);#Impedance of each wire (in Ohms)\n",
      "Z_p=complex(177,-246);#per-phase impedance (in Ohms)\n",
      "Z_pY=Z_p/3;#per-phase impedance in Y-connection (in Ohms)\n",
      "Z=Z_L+Z_pY;#Total per phase impedance (in Ohms)\n",
      "V=866/math.sqrt(3);#Per-phase voltage (in Volts)\n",
      "V_phase=0;\n",
      "I=V/Z;#Current in the circuit (in Ampere)\n",
      "\n",
      "#Calculations&Results\n",
      "I_mag=math.sqrt((I.real**2)+(I.imag**2));#magnitude of current (in Amperes)\n",
      "I_phase=math.degrees(math.atan(I.imag/I.real));#phase of current (in Degrees)\n",
      "pf=math.cos(math.atan(I.imag/I.real));#power factor\n",
      "#Refer to fig:1.13(b)\n",
      "#Source are connected in star,so phase currents = line currents\n",
      "I_na_mag=I_mag;#Magnitude of Source current through n-a (in Amperes)\n",
      "I_nb_mag=I_mag;#Magnitude of Source current through n-b (in Amperes)\n",
      "I_nc_mag=I_mag;#Magnitude of Source current through n-c (in Amperes)\n",
      "I_na_phase=I_phase+(0);#phase angle of current through n-a (in Degree)\n",
      "I_nb_phase=I_phase+(-120);#phase angle of current through n-b (in Degree)\n",
      "I_nc_phase=I_phase+(120);#phase angle of current through n-c (in Degree)\n",
      "print 'Source currents are:'\n",
      "print 'I_na_mag (in Amperes)= %.f'%I_na_mag\n",
      "print 'I_na_phase (in Degrees)=%.2f'%I_na_phase\n",
      "print 'I_nb_mag (in Amperes)=%.f'%I_nb_mag\n",
      "print 'I_nb_phase (in Degrees)=%.2f'%I_nb_phase\n",
      "print 'I_nc_mag (in Amperes)=%.f'%I_nc_mag\n",
      "print 'I_nc_phase (in Degrees)=%.2f'%I_nc_phase\n",
      "\n",
      "#Load is connected in delta network\n",
      "I_AB_mag=I_mag/math.sqrt(3);#magnitude of current through AB (in Amperes)\n",
      "I_BC_mag=I_mag/math.sqrt(3);#magnitude of current through BC (in Amperes)\n",
      "I_CA_mag=I_mag/math.sqrt(3);#magnitude of current through CA (in Amperes)\n",
      "I_AB_phase=I_na_phase+30;#phase angle of current through AB (in Degrees)\n",
      "I_BC_phase=I_nb_phase+30;#phase angle of current through BC (in Degrees)\n",
      "I_CA_phase=I_nb_phase-90;#phase angle of current through CA (in Degrees)\n",
      "print '\\nPhase currents through the load are:'\n",
      "print 'I_AB_mag (in Amperes)= %.3f'%I_AB_mag\n",
      "print 'I_AB_phase (in Degrees)= %.2f'%I_AB_phase\n",
      "print 'I_BC_mag (in Amperes)= %.3f'%I_BC_mag\n",
      "print 'I_BC_phase (in Degrees)= %.2f'%I_BC_phase\n",
      "print 'I_CA_mag (in Amperes)= %.3f'%I_CA_mag\n",
      "print 'I_CA_phase (in Degrees)= %.2f'%I_CA_phase\n",
      "\n",
      "\n",
      "I_AB=complex((I_AB_mag*math.cos(I_AB_phase*math.pi/180)),(I_AB_mag*math.sin(I_AB_phase*math.pi/180)));#(in Amperes)\n",
      "V_AB = I_AB*Z_p\n",
      "V_AB_mag = math.sqrt(V_AB.real**2+V_AB.imag**2)\n",
      "V_AB_phase = math.degrees(math.atan(V_AB.imag/V_AB.real))\n",
      "print '\\nLine or phase voltages at the load are:'\n",
      "print 'V_AB = %.2f,angle = %.2f V'%(V_AB_mag,V_AB_phase)\n",
      "print 'V_BC = %.2f,angle = %.2f V'%(V_AB_mag,V_AB_phase-120)\n",
      "print 'V_CA = %.2f,angle = %.2f V'%(V_AB_mag,V_AB_phase+120)\n",
      "\n",
      "P_AB=I_AB_mag**2*(Z_p.real);#in watts\n",
      "P_load = 3*P_AB\n",
      "print '\\nPower dissipated (in Watts)=%.2f'%(P_load)\n",
      "\n",
      "P_line=3*I_mag**2*(Z_L.real);#in watts\n",
      "print 'Power dissipated by transmission line (in Watts)= %.f'%P_line\n",
      "P_source = P_load+P_line\n",
      "print 'Total power supplied by three-phase source is %.2f W'%P_source"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Source currents are:\n",
        "I_na_mag (in Amperes)= 5\n",
        "I_na_phase (in Degrees)=53.13\n",
        "I_nb_mag (in Amperes)=5\n",
        "I_nb_phase (in Degrees)=-66.87\n",
        "I_nc_mag (in Amperes)=5\n",
        "I_nc_phase (in Degrees)=173.13\n",
        "\n",
        "Phase currents through the load are:\n",
        "I_AB_mag (in Amperes)= 2.887\n",
        "I_AB_phase (in Degrees)= 83.13\n",
        "I_BC_mag (in Amperes)= 2.887\n",
        "I_BC_phase (in Degrees)= -36.87\n",
        "I_CA_mag (in Amperes)= 2.887\n",
        "I_CA_phase (in Degrees)= -156.87\n",
        "\n",
        "Line or phase voltages at the load are:\n",
        "V_AB = 874.83,angle = 28.87 V\n",
        "V_BC = 874.83,angle = -91.13 V\n",
        "V_CA = 874.83,angle = 148.87 V\n",
        "\n",
        "Power dissipated (in Watts)=4424.74\n",
        "Power dissipated by transmission line (in Watts)= 75\n",
        "Total power supplied by three-phase source is 4499.74 W\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 1.5, Page 29"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Variable declaration\n",
      "R1 = 25  #in ohms\n",
      "R2 = 100 #in ohms\n",
      "Rt = 100 #in ohms\n",
      "V = 100.  #in volts\n",
      "\n",
      "#Calculations\n",
      "Rp = (R1*R2)/(R1+R2)\n",
      "It = V/Rt   #total current in circuit in Amps\n",
      "V_25 = It*Rp  #voltage across 25 ohm resistor, in volts\n",
      "I_25 = V_25/R1 #current through 25 ohm resistor, in Amps\n",
      "P_25 = V_25*I_25\n",
      "\n",
      "#Result\n",
      "print \"Power dissipated by the 25ohm resistor is %.f W\"%P_25"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Power dissipated by the 25ohm resistor is 16 W\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 1.6, Page 33"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "#Refer to the fig:1.16\n",
      "R=40;#in ohms\n",
      "L=complex(0,30);#in ohms\n",
      "\n",
      "\n",
      "#Calculations&Results\n",
      "V=117*(complex(math.cos(0),math.sin(0)));#in Volts\n",
      "#Equivalent load impedance is obtained by parallel combination of Resistance R and Inductance L\n",
      "Z_L=(R*L)/(R+L);#load impedance (in Ohms)\n",
      "Z1=complex(0.6,16.8);# in Ohms\n",
      "Z=Z_L+Z1;#Equivalent impedance of circuit (in Ohms) \n",
      "I=V/Z;#current through load (in Amperes)\n",
      "I_mag=math.sqrt(I.real**2+I.imag**2);#magnitude of current flowing through load (in Amperes)\n",
      "I_phase=math.degrees(math.atan(I.imag/I.real))\n",
      "print 'Reading of ammeter (in Amperes)=%.f,angle = %.2f'%(I_mag,I_phase)\n",
      "\n",
      "V_L=I*Z_L;#voltage across load (in Volts)\n",
      "V_L_mag=math.sqrt(V_L.real**2+V_L.imag**2);#magnitude of voltage across load (in Volts)\n",
      "V_L_phase = math.degrees(math.atan(V_L.imag/V_L.real))\n",
      "print '\\nReading of voltmeter (in Volts)= %.f,angle = %.2f'%(V_L_mag,V_L_phase)\n",
      "\n",
      "P=(V_L*I.conjugate());#Power developed (in Watts)\n",
      "print 'Reading of wattmeter (in Watts)=%.1f'%P.real\n",
      "\n",
      "pf=P.real/(V_L_mag*I_mag);#Power factor\n",
      "print 'power factor=%.2f(lagging)'%pf"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Reading of ammeter (in Amperes)=3,angle = -67.38\n",
        "\n",
        "Reading of voltmeter (in Volts)= 72,angle = -14.25\n",
        "Reading of wattmeter (in Watts)=129.6\n",
        "power factor=0.60(lagging)\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 1.7, Page 38"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "#transforming delta connected source into an equivalent Star-connected source\n",
      "V_s=1351;#source voltage (in Volts)\n",
      "V=1351/math.sqrt(3);#in volts\n",
      "V_phase=0;\n",
      "\n",
      "#Calculations&Results\n",
      "Z=complex(360,150);#per-phase impedance(in ohms)\n",
      "I=V/Z;#current in the circuit (in Amperes)\n",
      "I_mag=math.sqrt(I.real**2+I.imag**2);#in ampere\n",
      "I_phase=math.degrees(math.atan(I.imag/I.real));#degree\n",
      "\n",
      "#Refer to fig 1.19(a)\n",
      "V_ab=1351*complex(math.cos(-30*math.pi/180),math.sin(-30*math.pi/180));#in Volts\n",
      "I_aA=2*complex(math.cos(I_phase*math.pi/180),math.sin(I_phase*math.pi/180));#in Amperes\n",
      "V_cb=1351*complex(math.cos(-90*math.pi/180),math.sin(-90*math.pi/180));#in Volts\n",
      "I_cC=2*complex(math.cos((I_phase-120)*math.pi/180),math.sin((I_phase-120)*math.pi/180));#in Amperes\n",
      "P1=V_ab*I_aA.conjugate();#reading of wattmeter 1 (in Watts)\n",
      "print 'Reading of wattmeter W1 (in Watts) =%.2f'%P1.real\n",
      "P2=V_cb*I_cC.conjugate();#reading of wattmeter 2 (in Watts)\n",
      "print 'Reading of wattmeter W2 (in Watts)=%.2f'%P2.real\n",
      "P=P1.real+P2.real;#total power developed (in Watts)\n",
      "print 'Total power developed (in Watts)= %.f' %P\n",
      "\n",
      "pf=math.cos(math.atan(I.imag/I.real));#power factor\n",
      "print 'power factor= %.3f(lagging)'%pf"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Reading of wattmeter W1 (in Watts) =2679.62\n",
        "Reading of wattmeter W2 (in Watts)=1640.39\n",
        "Total power developed (in Watts)= 4320\n",
        "power factor= 0.923(lagging)\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 1.8, Page 44"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "V = 120  #Voltage(V)\n",
      "I = 5    #current(A)\n",
      "P = 480.  #power(W)\n",
      "f = 60    #Hz\n",
      "\n",
      "#Calculations&Results\n",
      "S = V*I  #apparent power(W)\n",
      "theta = math.degrees(math.acos(P/S))   #power factor angle\n",
      "#In phasor form,\n",
      "Vp = V*complex(math.cos(0*math.pi/180),math.sin(0*math.pi/180))\n",
      "Ip = I*complex(math.cos(theta*math.pi/180),math.sin(theta*math.pi/180))\n",
      "\n",
      "#For series circuit\n",
      "Zs = Vp/Ip\n",
      "print \"Equivalent Impedance of series circuit = \",Zs\n",
      "Xc = -Zs.imag\n",
      "C = 1./(2*math.pi*f*Xc)\n",
      "print \"Equivalent capacitance of series circuit = %.2f uF\"%(C*10**6)\n",
      "\n",
      "#For parallel circuit\n",
      "I_mag = I*math.cos(theta*math.pi/180)\n",
      "I_imag = I*math.sin(theta*math.pi/180)\n",
      "Rp = V/I_mag\n",
      "print \"\\nEquivalent resistance of parallel circuit = %d ohms\"%Rp\n",
      "Xp = V/I_imag\n",
      "Cp = 1./(2*math.pi*f*Xp)\n",
      "print \"Equivalent capacitance of parallel circuit = %.1f uF\"%(Cp*10**6)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Equivalent Impedance of series circuit =  (19.2-14.4j)\n",
        "Equivalent capacitance of series circuit = 184.21 uF\n",
        "\n",
        "Equivalent resistance of parallel circuit = 29 ohms\n",
        "Equivalent capacitance of parallel circuit = 66.3 uF\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 1.9, Page 46"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "\n",
      "#Variable declaration\n",
      "P = 3246   #power consumed(W)\n",
      "Vl = 208.   #line voltage(V)\n",
      "Il = 10.6   #line current(A)\n",
      "\n",
      "#Calculations&Results\n",
      "\n",
      "#Y-Connection\n",
      "V_phi = Vl/math.sqrt(3)  #pre-phase voltage(V)\n",
      "I_phi = Il               #pre-phase current(A)\n",
      "P_phi = P/3   #pre-phase power(W)\n",
      "S_phi = V_phi*I_phi      #pre-phase apparent power(VA)\n",
      "theta = math.degrees(math.acos((P_phi/S_phi)))   #lag\n",
      "#In phasor form,\n",
      "V_AN = V_phi*complex(math.cos(0*math.pi/180),math.sin(0*math.pi/180))\n",
      "I_AN = I_phi*complex(math.cos(-theta*math.pi/180),math.sin(-theta*math.pi/180))\n",
      "Zy = V_AN/I_AN\n",
      "Zy_phase = math.degrees(math.atan(Zy.imag/Zy.real))\n",
      "I_mag = I_phi*math.cos(Zy_phase*math.pi/180)\n",
      "I_imag = I_phi*math.sin(Zy_phase*math.pi/180)\n",
      "Rp = V_phi/I_mag  #ohms\n",
      "Xp = V_phi/I_imag #ohms\n",
      "print \"For Y-connection:\"\n",
      "print \"Impedance = \",Zy\n",
      "print \"Resistance = %.2f ohms, Reactance = %.2f ohms\"%(Rp,Xp)\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "For Y-connection:\n",
        "Impedance =  (9.62976148095+5.96800193442j)\n",
        "Resistance = 13.33 ohms, Reactance = 21.51 ohms\n"
       ]
      }
     ],
     "prompt_number": 9
    }
   ],
   "metadata": {}
  }
 ]
}