{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 03 : Transformers"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.1, Page No 148"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "# To determine no load power factor,core loss current and magnetising current\n",
      "#  and no load ckt parameters of transformer\n",
      "\n",
      "Pi=50.0\n",
      "V1=230.0\n",
      "Io=2\n",
      "\n",
      "#Calculations\n",
      "pf=Pi/(V1*Io)\n",
      "print(\"No load power factor %.2f v \" %pf)\n",
      "Im=Io*math.sin(math.radians(math.degrees(math.acos(pf))))\n",
      "print(\"Magnetising current(A) %.2f v \" %Im)\n",
      "Ii=Io*pf\n",
      "print(\"core loss current(A) %.2f v \" %Ii)\n",
      "Gi=Pi/V1**2\n",
      "print(\"Gi(mho) %.2f v \" %Gi)\n",
      "Bm=Im/V1\n",
      "\n",
      "#Results\n",
      "print(\"Bm(mho) %.2f v \" %Bm)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "No load power factor 0.00 v \n",
        "Magnetising current(A) 2.00 v \n",
        "core loss current(A) 0.00 v \n",
        "Gi(mho) 0.00 v \n",
        "Bm(mho) 0.01 v \n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.2, Page No 149"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# To calculate no load current and its pf and no load power drawn from mains\n",
      "\n",
      "\n",
      "E=200 \n",
      "f=50 \n",
      "N1=150         # no of turns\n",
      "b1=.1 \n",
      "b2=.05 \n",
      "phi_max=E/(4.44*f*N1) \n",
      "print(\"flux(Wb)%.2f v \" %phi_max)\n",
      "B_max=phi_max/(b1*b2) \n",
      "print(\"B_max(T) = %.2f v \" %B_max)\n",
      "\n",
      "H_max=250         #According to B_max, H_max is 250AT/m\n",
      "l_c=.2*(3.0+3.5)     #length of core\n",
      "AT_max=H_max*l_c \n",
      "print(\"AT_max = %.2f v \" %AT_max)\n",
      "T_max=N1 \n",
      "I_mmax=AT_max/T_max \n",
      "I_mrms=I_mmax/2**.5 \n",
      "print(\"I_mrms(A) = %.2f v \" %I_mrms)\n",
      "v=2*(20*10*5)+2*(45*10*5) \n",
      "d=.0079             #density of core material\n",
      "w=v*d \n",
      "cl=3                 #core loss/kg\n",
      "closs=w*cl \n",
      "print(\"core loss(W) = %.2f v \" %closs)\n",
      "I_i=closs/E \n",
      "print(\"I_i(A) = %.2f v \" %I_i)\n",
      "def rect2polar(x,y):\n",
      "    r=math.sqrt(x**2+y**2)\n",
      "    return r\n",
      "\n",
      "def rect2polar2(x,y):\n",
      "    pff=math.cos(math.radians(math.degrees(math.acos(y/x))))\n",
      "    return pff\t\n",
      "\n",
      "I_o=rect2polar(I_i,-I_mmax) \n",
      "pf=rect2polar(I_i,-I_mmax) \n",
      "print(\"no load current(A) = %.2f v \" %I_o)\n",
      "print(\"no load power factor = %.2f v \" %pf)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "flux(Wb)0.01 v \n",
        "B_max(T) = 1.20 v \n",
        "AT_max = 325.00 v \n",
        "I_mrms(A) = 1.53 v \n",
        "core loss(W) = 154.05 v \n",
        "I_i(A) = 0.77 v \n",
        "no load current(A) = 2.30 v \n",
        "no load power factor = 2.30 v \n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.3, Page No 149"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# To calculate primary and scondary side impedences,current and their pf and real power\n",
      "# and calculate terminal voltage\n",
      "N_1=150.0 \n",
      "N_2=75.0 \n",
      "\n",
      "a=N_1/N_2 \n",
      "\n",
      "Z_2=[5,30]                 #polar(magnitude,phase diff)\n",
      "I_2=[0,0]\n",
      "I_1=[0,0]\n",
      "print(Z_2,'secondary impedence(ohm)') \n",
      "Z_1=[a**2*Z_2[0],Z_2[1]] \n",
      "print(Z_1,'primary impedence(ohm)') \n",
      "\n",
      "V_1=[200,0]                 #polar(magnitde,phase diff)\n",
      "V_2=[V_1[0]/a,V_1[1]] \n",
      "print(V_2,'secondary terminal voltage(V)') \n",
      "\n",
      "I_2[0]=V_2[0]/Z_2[0] \n",
      "I_2[1]=V_2[1]-Z_2[1] \n",
      "print(I_2,'I_2=') \n",
      "pf=math.cos(math.radians(I_2[1]))\n",
      "print(pf,'pf lagging=') \n",
      "\n",
      "I_1[0]=I_2[0]/a \n",
      "I_1[1]=I_2[1] \n",
      "print(I_1,'I_1(A)') \n",
      "pf=math.cos(math.radians(I_1[1]))\n",
      "print(pf,'pf lagging=') \n",
      "\n",
      "P_2=V_2[0]*I_2[0]*math.cos(math.radians(I_2[1]))  \n",
      "print(P_2,'secondary power output(W)=') \n",
      "#P_1=primary power output\n",
      "P_1=P_2                            #as the transormer is lossless\n",
      "print(P_1,'primary power output(W)=') \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "([5, 30], 'secondary impedence(ohm)')\n",
        "([20, 30], 'primary impedence(ohm)')\n",
        "([100, 0], 'secondary terminal voltage(V)')\n",
        "([20, -30], 'I_2=')\n",
        "(0.8660254037844387, 'pf lagging=')\n",
        "([10, -30], 'I_1(A)')\n",
        "(0.8660254037844387, 'pf lagging=')\n",
        "(1732.0508075688774, 'secondary power output(W)=')\n",
        "(1732.0508075688774, 'primary power output(W)=')\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.4 Page No 150"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# To calculate primary current and its pf\n",
      "\n",
      "def polar2rect(r,theta):\n",
      "\tx=r*math.cos(math.radians(theta))\n",
      "\treturn x\n",
      "\n",
      "def polar2rect2(r,theta):\n",
      "\ty=r*math.sin(math.radians(theta))\n",
      "\treturn y\n",
      "\t\n",
      "def rect2polar(x,y):\n",
      "\tr=math.sqrt(x**2+y**2) \n",
      "\treturn r\n",
      "\n",
      "def rect2polar2(x,y):\n",
      "\ttheta=math.degrees(math.atan(y/x))\n",
      "\treturn theta\n",
      "\n",
      "#Calculations\n",
      "I_2=[10,-30] \n",
      "I_2r=[0,0] \n",
      "I_2r[0]=polar2rect(I_2[0],I_2[1]) \n",
      "I_2r[1]=polar2rect2(I_2[0],I_2[1]) \n",
      "\n",
      "I_0=[1.62,-71.5] \n",
      "I_0r=[0,0] \n",
      "I_0r[0]=polar2rect(I_0[0],I_0[1]) \n",
      "I_0r[1]=polar2rect2(I_0[0],I_0[1]) \n",
      "\n",
      "I_1r=I_0r+I_2r \n",
      "I_1[0]=rect2polar(I_1r[0],I_1r[1]) \n",
      "I_1[1]=rect2polar2(I_1r[0],I_1r[1]) \n",
      "print(I_1[0],'primary current(A)=') \n",
      "pf=math.cos(math.radians(I_1[1]))\n",
      "print(pf,'power factor=') \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(1.62, 'primary current(A)=')\n",
        "(0.3173046564050921, 'power factor=')\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.5, Page No 152"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "# Equivalent circuit referred to(i)HV side (ii)LV side\n",
      "\n",
      "N_1=2000 \n",
      "N_2=200 \n",
      "\n",
      "a=N_1/N_2 \n",
      "\n",
      "#Calculations\n",
      "Z_2=p=complex(0.004,0.005)  #low voltage impedence\n",
      "Z_2hv=a**2*Z_2 \n",
      "print(Z_2hv,'Z_2 referred to hv side(ohm)')                         #when referred to hv side\n",
      "\n",
      "Y_0=complex(0.002,-0.015)             #shunt branch admittance\n",
      "Y_0hv=Y_0/a**2 \n",
      "print(Y_0hv,'Y_0 referred to hv side(mho)') \n",
      "\n",
      "Z_1=complex(0.42,-0.52)                    #low voltage impedence\n",
      "Z_1lv=Z_1/a**2 \n",
      "print(Z_1lv,'Z_1 referred to lv side(ohm)') "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "((0.4+0.5j), 'Z_2 referred to hv side(ohm)')\n",
        "((2e-05-0.00015j), 'Y_0 referred to hv side(mho)')\n",
        "((0.0042-0.0052j), 'Z_1 referred to lv side(ohm)')\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.6 Page No 163"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "# To find the voltage at the load end of the transformer when load is drawing transformer current\n",
      "\n",
      "I=20/2                     #rated load current(hv side)\n",
      "\n",
      "Z1=[.25,1.4]                     #impedence of feeder    (REAL,IMAGINERY)\n",
      "Z2=[.82,1.02]                    #impedence of transformer    (REAL,IMAGINERY)\n",
      "\n",
      "Z=Z1+Z2 \n",
      "print(Z,'Z(ohm)') \n",
      "\n",
      "pf=.8 \n",
      "phi=math.degrees(math.acos(pf))\n",
      "#from phasor diagram\n",
      "   \n",
      "#Calculations\n",
      "R=Z[0]\n",
      "X=Z[0]\n",
      "AF=I*X*math.cos(math.radians(phi))\n",
      "FE=I*R*math.sin(math.radians(phi))\n",
      "AE=AF-FE \n",
      "OA=2000 \n",
      "OE=math.sqrt(OA**2-AE**2)                                                         \n",
      "\n",
      "BD=I*R*math.cos(math.radians(phi))\n",
      "DE=I*X*math.sin(math.radians(phi))\n",
      "\n",
      "BE=BD+DE \n",
      "V1=OE    \n",
      "print(V1,'V1(V)')  \n",
      "V2=V1-BE     \n",
      "print(V2,'V2(V)') \n",
      "\n",
      "loadvol=V2/10                         #referred to LV side\n",
      "print(loadvol,'load voltage(V)') \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "([0.25, 1.4, 0.82, 1.02], 'Z(ohm)')\n",
        "(1999.999937499999, 'V1(V)')\n",
        "(1996.499937499999, 'V2(V)')\n",
        "(199.6499937499999, 'load voltage(V)')\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.7, Page No 164"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "# Approx equivalent ckt referred to hv and lv sides resp,\n",
      "\n",
      "#open ckt test data with HV side open\n",
      "ocv=200.0 \n",
      "oci=4.0 \n",
      "ocp=120.0 \n",
      "#short ckt test data with LV side open\n",
      "scv=60.0 \n",
      "sci=10.0 \n",
      "scp=300.0 \n",
      "#OC test(LV side)\n",
      "\n",
      "#Calculations\n",
      "Y_o=oci/ocv     \n",
      "print(\"Y_o %.4f v \" %Y_o)\n",
      "G_i=ocp/ocv**2   \n",
      "print(\"G_i %.4f v \" %G_i)\n",
      "B_m=math.sqrt(Y_o**2-G_i**2) \n",
      "print(\"B_m %.4f v \" %B_m)   \n",
      "#SC test(HV side)\n",
      "Z=scv/sci      \n",
      "print(\"Z(ohm) %.4f v \" %Z) \n",
      "R=scp/sci**2   \n",
      "print(\"R(ohm) %.4f v \" %R)   \n",
      "X=math.sqrt(Z**2-R**2) \n",
      "print(\"X(ohm) %.4f v \" %X)\n",
      "\n",
      "N_H=2000 \n",
      "N_L=200 \n",
      "a=N_H/N_L                             #transformation ratio\n",
      "\n",
      "#Equivalent ckt referred to HV side\n",
      "G_iHV=G_i/a**2        \n",
      "print(\"G_i(HV)mho %.4f v \" %G_iHV) \n",
      "B_mHV=B_m/a**2    \n",
      "print(\"B_m(HV)mho %.4f v \" %B_mHV) \n",
      "\n",
      "#Equivalent ckt referred to LV side\n",
      "RLV=R/a**2       \n",
      "print(\"R(LV)ohm %.4f v \" %RLV) \n",
      "XLV=X/a**2         \n",
      "print(\"X(LV)ohm %.4f v \" %XLV) "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Y_o 0.0200 v \n",
        "G_i 0.0030 v \n",
        "B_m 0.0198 v \n",
        "Z(ohm) 6.0000 v \n",
        "R(ohm) 3.0000 v \n",
        "X(ohm) 5.1962 v \n",
        "G_i(HV)mho 0.0000 v \n",
        "B_m(HV)mho 0.0002 v \n",
        "R(LV)ohm 0.0300 v \n",
        "X(LV)ohm 0.0520 v \n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.8 Page No 165"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "# to calculate (a)open ckt current,power and pf when LV excited at rated voltage\n",
      "# (b) voltage at which HV side is excited, ip power and its pf\n",
      "\n",
      "r=150000                                     #rating(VA)\n",
      "V1=2400.0 \n",
      "V2=240.0 \n",
      "a=V1/V2 \n",
      "\n",
      "R_1=.2 \n",
      "X_1=.45 \n",
      "R_i=10000 \n",
      "R_2=2*10**-3 \n",
      "X_2=4.5*10**-3 \n",
      "X_m=1600 \n",
      "#Referring the shunt parameters to LV side\n",
      "\n",
      "#Calculations\n",
      "R_iLV=R_i/a**2 \n",
      "X_mLV=X_m/a**2 \n",
      "I_oLV=[V2/100.0,V2/16.0] \n",
      "I_o=math.sqrt(I_oLV[0]**2+I_oLV[1]**2)     \n",
      "print(I_o,'I_o(A)') \n",
      "pf=math.cos(math.radians(math.degrees(math.atan(I_oLV[1]/I_oLV[0]))))\n",
      "print(\"pf = %.2f v \" %pf) \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(15.190786681406594, 'I_o(A)')\n",
        "pf = 0.16 v \n"
       ]
      }
     ],
     "prompt_number": 24
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.10 Page No 165"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#To find exciting current and expess impedence in pu in both HV and LV sides\n",
      "\n",
      "V_BHV=2000.0 \n",
      "I_BHV=10.0 \n",
      "Z_BHV=V_BHV/I_BHV \n",
      "\n",
      "V_BLV=200.0 \n",
      "I_BLV=100.0 \n",
      "Z_BLV=V_BLV/I_BLV \n",
      "\n",
      "I_o=3.0 \n",
      "a=V_BHV/V_BLV \n",
      "\n",
      "\n",
      "#Calculations\n",
      "I_oLV=I_o/100     \n",
      "print(I_oLV,'I_o(LV)pu=') \n",
      "I_oHV=I_o/(a*10)     \n",
      "print(I_oHV,'I_o(HV)pu=') \n",
      "\n",
      "Z=complex(8.2,10.2) \n",
      "ZHV=Z/Z_BHV     \n",
      "print(ZHV,'Z(HV)pu=') \n",
      "z=Z/a**2     \n",
      "ZLV=z/Z_BLV     \n",
      "print(ZLV,'Z(LV)pu=') "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(0.03, 'I_o(LV)pu=')\n",
        "(0.03, 'I_o(HV)pu=')\n",
        "((0.040999999999999995+0.051j), 'Z(HV)pu=')\n",
        "((0.040999999999999995+0.051j), 'Z(LV)pu=')\n"
       ]
      }
     ],
     "prompt_number": 29
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.11 Page No 172"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "\n",
      "V_2=200 \n",
      "I_2=100 \n",
      "pf=.8 \n",
      "P_o=V_2*I_2*pf             #power output\n",
      "\n",
      "P_i=120.0 \n",
      "P_c=300.0 \n",
      "k=1 \n",
      "\n",
      "#Calculations\n",
      "P_L=P_i+k**2*P_c             #total losses\n",
      "\n",
      "n=1-(P_L/(P_o+P_L))        \n",
      "print(\"n percent = %.2f v \" %(n*100))\n",
      "\n",
      "K=math.sqrt(P_i/P_c)             #max efficiency\n",
      "\n",
      "n_max=1-(2*P_i/(P_o*K+2*P_i))         #pf=.8\n",
      "\n",
      "#Results\n",
      "print(\"n_max percent = %.2f v \" %(n_max*100))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "n percent = 97.44 v \n",
        "n_max percent = 97.68 v \n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.13, Page No 176"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "# Comparing all-day efficiencies for diff given load cycles\n",
      "\n",
      "r=15.0              # kva rating\n",
      "n_max=.98 \n",
      "pf=1.0 \n",
      "P_o=20.0 \n",
      "P_i=r*(1-n_max)/2  \n",
      "k=r*pf/P_o \n",
      "P_c=P_i/(k**2) \n",
      "\n",
      "def power(P_o,h):\n",
      "    k=P_o/20\n",
      "    P_c=P_i*P_o/r\n",
      "    W_o=P_o*h\n",
      "    W_in=(P_o+P_i+(k**2)*P_c)*h\n",
      "    return W_o,W_in\n",
      "\n",
      "#(a)full load of 20kva 12hrs/day and no load rest of the day\n",
      "\n",
      "#Calculations\n",
      "a=[20,12] \n",
      "W_oa=[0,0]\n",
      "W_ina=[0,0]\n",
      "[W_oa[0],W_ina[0]]=power(a[0],a[1]) \n",
      "aa=[0,12] \n",
      "[W_oa[1],W_ina[1]]=power(aa[0],aa[1]) \n",
      "print(W_oa,'W_o(kWh) for a') \n",
      "print(W_ina,'W_in(kWh) for a') \n",
      "n_ada=sum(W_oa)/sum(W_ina)     \n",
      "print(n_ada*100,'n_allday(a) in %age') \n",
      "\n",
      "#(b)full load of 20kva 4hrs/day and .4 of full load rest of the day\n",
      "b=[20,4] \n",
      "W_ob=[0,0]\n",
      "W_inb=[0,0]\n",
      "[W_ob[0],W_inb[0]]=power(b[0],b[1]) \n",
      "bb=[8,20] \n",
      "[W_ob[1],W_inb[1]]=power(bb[0],bb[1]) \n",
      "print(W_ob,'W_o(kWh) for b') \n",
      "print(W_inb,'W_in(kWh) for b') \n",
      "n_adb=sum(W_ob)/sum(W_inb) \n",
      "\n",
      "#Results\n",
      "print(n_adb*100,'n_allday(b) in %age')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "([240, 0], 'W_o(kWh) for a')\n",
        "([244.2, 1.8000000000000016], 'W_in(kWh) for a')\n",
        "(97.5609756097561, 'n_allday(a) in %age')\n",
        "([80, 160], 'W_o(kWh) for b')\n",
        "([81.39999999999999, 163.0], 'W_in(kWh) for b')\n",
        "(98.19967266775778, 'n_allday(b) in %age')\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.14, Page No 186"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "\n",
      "# To calculate volatage regulation, volatage at load terminals and operating efficiency\n",
      "\n",
      "S=20*1000 \n",
      "V1=200 \n",
      "V2=2000 \n",
      "I1=S/V1 \n",
      "I2=S/V2 \n",
      "Rh=3 \n",
      "Xh=5.2 \n",
      "pf=0.8             \n",
      "\n",
      "#Calculations\n",
      "phi=math.degrees(math.acos(pf))\n",
      "Vha=V2+I2*(Rh*math.cos(math.radians(phi))+Xh*math.sin(math.radians(phi)))         #lagging\n",
      "Vrega=(Vha-V2)*100/V2      \n",
      "print(Vrega,'vol-reg lagging(%)') \n",
      "Vhb=V2+I2*(Rh*math.cos(math.radians(phi))-Xh*math.sin(math.radians(phi)))         #leading\n",
      "Vregb=(Vhb-V2)*100/V2      \n",
      "print(Vregb,'vol-reg leading(%)') \n",
      "V11=V2-I2*(Rh*math.cos(math.radians(phi))+Xh*math.sin(math.radians(phi))) \n",
      "v1=V11/I2         \n",
      "print(v1,'V_L(V)') \n",
      "ploss=120+10*10*3 \n",
      "pop=v1*I1*math.cos(math.radians(phi)) \n",
      "eff=(1-(ploss/(ploss+pop)))*100.0\n",
      "\n",
      "#Results\n",
      "print(eff,'eff(%)') \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(2.759999999999991, 'vol-reg lagging(%)')\n",
        "(-0.36000000000000226, 'vol-reg leading(%)')\n",
        "(194.48, 'V_L(V)')\n",
        "(97.37145145947028, 'eff(%)')\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.15, Page No 187"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "# To determine voltage regulation and efficiency\n",
      "r=150*1000.0                     #rating in va\n",
      "v1=2400.0 \n",
      "v2=240.0 \n",
      "a=v2/v1 \n",
      "R_hv=.2+.002/a**2 \n",
      "X_hv=.45+.0045/a**2 \n",
      "I_2fl=r/v2 \n",
      "pf=0.8        #lagging\n",
      "\n",
      "#Calculations\n",
      "phi=math.degrees(math.acos(pf))\n",
      "I_2=I_2fl*a \n",
      "vd=I_2*(R_hv*math.cos(math.radians(phi))+X_hv*math.sin(math.radians(phi))) \n",
      "V2=v1 \n",
      "vr=(vd/V2)*100         \n",
      "print(vr,'vol reg(%)') \n",
      "V1=v1+vd \n",
      "P_out=r*pf \n",
      "P_c=(I_2**2)*R_hv         #copper loss\n",
      "P_i=(V1**2)/10000 \n",
      "P_L=P_c+P_i \n",
      "n=P_out/(P_out+P_L)         \n",
      "print(n*100,'eff(%)') \n",
      "I_o=[0,0]\n",
      "I2=[0,0]\n",
      "I_o[0]=V1/(10*1000) \n",
      "I_o[1]=-V1/(1.6*1000)        #inductive effect\n",
      "I2[0]=I_2*(math.cos(math.radians(phi)))     \n",
      "I2[1]=I_2*(-math.sin(math.radians(phi))) \n",
      "I_1=I_o+I2      \n",
      "b=math.sqrt(I_1[0]**2+I_1[1]**2) \n",
      "print(b,'I_1(A)') \n",
      "pff=math.cos(math.radians(math.degrees(math.atan(I_1[1]/I_1[0]))))\n",
      "\n",
      "#Results\n",
      "print(pff,'pf') "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(2.239583333333333, 'vol reg(%)')\n",
        "(98.22813719947018, 'eff(%)')\n",
        "(1.5530997008125598, 'I_1(A)')\n",
        "(0.15799050110667276, 'pf')\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.16, Page No 197"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "# to calculate voltage ratings,kva ratings and efficieny of autotransformer\n",
      "\n",
      "AB=200.0\n",
      "BC=2000.0\n",
      "V_1=BC         \n",
      "print(V_1,'V_1(V)') \n",
      "V_2=AB+BC      \n",
      "print(V_2,'V_2(V)') \n",
      "r=20000             #rating of transformer\n",
      "I_2=r/AB \n",
      "I_1=I_2+10 \n",
      "\n",
      "#Calculations\n",
      "rr=V_2*I_2/1000         #kva rating of autotransformer\n",
      "print(rr,'kva rating') \n",
      "ri=V_1*(I_1-I_2)/1000     #kva inductive\n",
      "rc=rr-ri \n",
      "print(ri,'kva transferred inductively') \n",
      "print(rc,'kva transferred conductively') \n",
      "W_c=120             #core loss\n",
      "W_cu=300             #cu loss\n",
      "W_t=W_c+W_cu         #total loss\n",
      "pf=0.8 \n",
      "W=V_2*I_2*pf         #full load output\n",
      "n=1-(W_t/W) \n",
      "\n",
      "#Results\n",
      "print(n*100,'eff(%)') "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(2000.0, 'V_1(V)')\n",
        "(2200.0, 'V_2(V)')\n",
        "(220.0, 'kva rating')\n",
        "(20.0, 'kva transferred inductively')\n",
        "(200.0, 'kva transferred conductively')\n",
        "(99.76136363636363, 'eff(%)')\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.17, Page No 198"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "# To determine the rating and full load efficiency of autotransformer\n",
      "\n",
      "#when used as transformer\n",
      "v1=240.0\n",
      "v2=120.0\n",
      "r=12000.0\n",
      "I1=r/v1 \n",
      "I2=r/v2 \n",
      "\n",
      "#Calculations\n",
      "#when connected as autotransformer\n",
      "V1=240.0\n",
      "V2=v1+v2 \n",
      "rr=I2*V2             \n",
      "print(rr,'rating of autotransformer(va)') \n",
      "\n",
      "pf=1 \n",
      "P_o=r*pf             #output power\n",
      "n=.962            #efficiency at upf\n",
      "P_L=P_o*(1-n)/n \n",
      "\n",
      "pff=.85            #if pf=.85\n",
      "Po=rr*pff \n",
      "nn=1/(1+P_L/Po)         \n",
      "\n",
      "#Results\n",
      "print(nn*100,'efficiency(%) at .85 pf is') "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(36000.0, 'rating of autotransformer(va)')\n",
        "(98.4745694673036, 'efficiency(%) at .85 pf is')\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.18, Page No 198"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "# To calculate sec. line voltage, line current and output va\n",
      "\n",
      "print('(a)Y/D conn') \n",
      "V_LY=6600 \n",
      "V_PY=V_LY/math.sqrt(3) \n",
      "a=12 \n",
      "V_PD=V_PY/a \n",
      "V_LD=V_PD     \n",
      "print(V_LD,'sec line voltage(V)') \n",
      "\n",
      "I_PY=10 \n",
      "I_PD=I_PY*a \n",
      "I_LD=I_PD*math.sqrt(3)     \n",
      "print(I_LD,'sec. line current(A)') \n",
      "r=math.sqrt(3)*V_LD*I_LD     \n",
      "print(r,'output rating(va)') \n",
      "\n",
      "#Calculations\n",
      "print('(b)D/Y conn') \n",
      "I_LD=10 \n",
      "I_PD=I_LD/math.sqrt(3) \n",
      "I_LY=I_PD*a         \n",
      "print(I_LY,'sec. line current(A)') \n",
      "V_PD=6600 \n",
      "V_PY=V_PD/a \n",
      "V_LY=V_PY*math.sqrt(3.0)\n",
      "\n",
      "#Results\n",
      "print(V_LY,'sec line voltage(V)') \n",
      "r=math.sqrt(3)*V_LY*I_LY     \n",
      "print(r,'output rating(va)') "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)Y/D conn\n",
        "(317.5426480542942, 'sec line voltage(V)')\n",
        "(207.84609690826525, 'sec. line current(A)')\n",
        "(114315.3532995459, 'output rating(va)')\n",
        "(b)D/Y conn\n",
        "(69.2820323027551, 'sec. line current(A)')\n",
        "(952.6279441628825, 'sec line voltage(V)')\n",
        "(114315.3532995459, 'output rating(va)')\n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.19, Page No 223"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "\n",
      "# To compute all the currents and voltages in all windings of Y/D transformer\n",
      "\n",
      "S=complex(500,100)         #load is 500MW and 100MVar\n",
      "s=abs(S) \n",
      "r=s/3         #MVA rating of each single ph transformer\n",
      "\n",
      "V1=22         #D side\n",
      "V2=345         #Y side\n",
      "a=V2/(math.sqrt(3)*V1)         #voltage rating of each single phase\n",
      "print('Y side') \n",
      "V_A=(V2/math.sqrt(3))*complex(math.cos(math.radians(0)),math.sin(math.radians(0))) \n",
      "V_B=(V2/math.sqrt(3))*complex(math.cos(math.radians(-120)),math.sin(math.radians(-120)))\n",
      "V_C=(V2/math.sqrt(3))*complex(math.cos(math.radians(-240)),math.sin(math.radians(-240)))\n",
      "\n",
      "\n",
      "#Calculations\n",
      "V_AB=V_A-V_B     \n",
      "print(V_AB,'V_AB(V)') \n",
      "V_BC=V_B-V_C     \n",
      "print(V_BC,'V_BC(V)') \n",
      "V_CA=V_C-V_A     \n",
      "print(V_CA,'V_CA(V)') \n",
      "\n",
      "IA=S/(3*V_A)     \n",
      "print(IA,'IA(A)') \n",
      "IB=S/(3*V_B)     \n",
      "print(IB,'IB(A)') \n",
      "IC=S/(3*V_C)     \n",
      "print(IC,'IC(A)') \n",
      "print('D side') \n",
      "V_ab=V_A/a     \n",
      "print(V_ab,'V_ab(V)') \n",
      "V_bc=V_B/a     \n",
      "print(V_bc,'V_bc(V)') \n",
      "V_ca=V_C/a     \n",
      "print(V_ca,'V_ca(V)') \n",
      "\n",
      "I_ab=a*IA \n",
      "I_bc=a*IB \n",
      "I_ca=a*IC \n",
      "Ia=I_ab-I_bc     \n",
      "print(Ia,'Ia(A)') \n",
      "Ib=I_bc-I_ca     \n",
      "\n",
      "#Results\n",
      "print(Ib,'Ib(A)') \n",
      "Ic=I_ca-I_ab     \n",
      "print(Ic,'Ic(A)')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Y side\n",
        "((298.77876430563134+172.50000000000003j), 'V_AB(V)')\n",
        "((1.2789769243681803e-13-345j), 'V_BC(V)')\n",
        "((-298.77876430563146+172.49999999999997j), 'V_CA(V)')\n",
        "((0.8367395205646748+0.16734790411293496j), 'IA(A)')\n",
        "((-0.5632972965142212+0.6409637291029529j), 'IB(A)')\n",
        "((-0.2734422240504539-0.8083116332158876j), 'IC(A)')\n",
        "D side\n",
        "((22.000000000000004+0j), 'V_ab(V)')\n",
        "((-10.999999999999996-19.052558883257653j), 'V_bc(V)')\n",
        "((-11.00000000000001+19.052558883257646j), 'V_ca(V)')\n",
        "((12.675796066340055-4.288071240791203j), 'Ia(A)')\n",
        "((-2.624319405407383+13.121597027036948j), 'Ib(A)')\n",
        "((-10.051476660932671-8.833525786245746j), 'Ic(A)')\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.20, Page No 223"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "# to find the load voltage when it draws rated current from transformer\n",
      "\n",
      "# here pu method is used\n",
      "r=20         #kva rating of three 1-ph transformer\n",
      "MVA_B=r*3/1000.0\n",
      "v2=2*math.sqrt(3.0)         #in kv voltage base on hv side\n",
      "v1=.2         #in kv voltage base on lv side\n",
      "\n",
      "#Calculations\n",
      "z1=complex(.0004,.0015)         #feeder impedence\n",
      "Z1=z1*MVA_B/v1**2         # lv line(pu)\n",
      "z2=complex(.13,.95)         #load impedence\n",
      "Z2=z2*MVA_B/v2**2         # hv line(pu)\n",
      "z_T=complex(.82,1.02) \n",
      "ZTY=z_T*MVA_B/v2**2         # star side(pu)\n",
      "\n",
      "Ztot=Z1+Z2+ZTY \n",
      "V1=1         #sending end voltage [pu]\n",
      "I1=1         #rated current(pu)\n",
      "pf=.8 \n",
      "V2=V1-I1*((Ztot.real)*pf+(Ztot.imag)*.6)         #load voltage(pu)\n",
      "V2v=V2*v1\n",
      "\n",
      "#Results\n",
      "print(V2v,'load voltage(kv)') "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(0.197692, 'load voltage(kv)')\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.21, Page No 231"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "# to calculate fault currentin feeder lines,primary and secondary lines of receiving end transformers\n",
      "\n",
      "r=60.0         #kva rating of 3-ph common base\n",
      "s=200.0         #kva rating of 3ph transformer\n",
      "#sending end\n",
      "X_Tse=.06*r/s     #.06= reactance of transformer based on its own rating\n",
      "#in 2 kv feeder\n",
      "V_B=2000.0/math.sqrt(3)     #line to neutral\n",
      "I_B=r*1000.0/(math.sqrt(3)*2000) \n",
      "Z_B=V_B/I_B \n",
      "X_feeder=0.7/Z_B         #feeder reactance=0.7\n",
      "\n",
      "#Calculations\n",
      "#receiving end\n",
      "X_Tre=0.0051 \n",
      "X_tot=X_Tse+X_feeder+X_Tre \n",
      "V_se=20/20 \n",
      "I_fc=V_se/X_tot     #feeder current\n",
      "\n",
      "I_f=I_fc*I_B  \n",
      "\n",
      "#Results\n",
      "print(I_f,'current in 2kv feeder(A)') \n",
      "I_t1=I_f/math.sqrt(3)     \n",
      "print(I_t1,'current in 2kv winding of transformer(A)') \n",
      "I_t2=I_t1*10     \n",
      "print(I_t2,'current in 200kv winding of transformer(A)') \n",
      "I_l=I_t2*math.sqrt(3)     \n",
      "print(I_l,'current at load terminals(A)') "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(515.4913117764517, 'current in 2kv feeder(A)')\n",
        "(297.6190476190477, 'current in 2kv winding of transformer(A)')\n",
        "(2976.190476190477, 'current in 200kv winding of transformer(A)')\n",
        "(5154.913117764517, 'current at load terminals(A)')\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.22, Page No 231"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# To calculate voltage and kva rating of 1-ph transformer\n",
      "\n",
      "V_p=33.0     #primary side voltage(V)\n",
      "V_s=11.0     #secondary side voltage(V)\n",
      "\n",
      "#Calculations\n",
      "V_p1=V_p/math.sqrt(3)     #per ph primary side voltage(V)\n",
      "V_p2=V_s/math.sqrt(3)     #per ph secondary side voltage(V)\n",
      "\n",
      "r=6000.0     #kva rating 3-ph\n",
      "s=r/3.0     #per phase\n",
      "\n",
      "#Results\n",
      "print('Y/Y conn') \n",
      "print(V_p1,'primary side ph voltage(V)') \n",
      "print(V_p2,'secondary side ph voltage(V)') \n",
      "print(s,'kva rating of transformer') \n",
      "\n",
      "print('Y/D conn') \n",
      "print(V_p1,'primary side ph voltage(V)') \n",
      "print(V_s,'secondary side ph voltage(V)') \n",
      "print(s,'kva rating of transformer') \n",
      "\n",
      "print('D/Y conn') \n",
      "print(V_p,'primary side ph voltage(V)') \n",
      "print(V_p2,'secondary side ph voltage(V)') \n",
      "print(s,'kva rating of transformer') \n",
      "\n",
      "print('D/D conn') \n",
      "print(V_p,'primary side ph voltage(V)') \n",
      "print(V_s,'secondary side ph voltage(V)') \n",
      "print(s,'kva rating of transformer') \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Y/Y conn\n",
        "(19.05255888325765, 'primary side ph voltage(V)')\n",
        "(6.3508529610858835, 'secondary side ph voltage(V)')\n",
        "(2000.0, 'kva rating of transformer')\n",
        "Y/D conn\n",
        "(19.05255888325765, 'primary side ph voltage(V)')\n",
        "(11.0, 'secondary side ph voltage(V)')\n",
        "(2000.0, 'kva rating of transformer')\n",
        "D/Y conn\n",
        "(33.0, 'primary side ph voltage(V)')\n",
        "(6.3508529610858835, 'secondary side ph voltage(V)')\n",
        "(2000.0, 'kva rating of transformer')\n",
        "D/D conn\n",
        "(33.0, 'primary side ph voltage(V)')\n",
        "(11.0, 'secondary side ph voltage(V)')\n",
        "(2000.0, 'kva rating of transformer')\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.23, Page No 231"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "# to calculate (a)reactance in ohms(b)line voltage,kva rating,series reactance for Y/Y   and Y/D conn\n",
      "\n",
      "Xpu=0.12     # of 1-ph transformer\n",
      "\n",
      "def Xohm(kv,MVA):\n",
      "\tX=(Xpu*kv**2)/MVA\n",
      "\treturn X\n",
      "\n",
      "print('(a)') \n",
      "MVAa=75*10**-3 \n",
      "Vhv=6.6     \n",
      "Vlv=.4 \n",
      "\n",
      "#Calculations\n",
      "Xhv=Xohm(Vhv,MVAa)      \n",
      "print(Xhv,'X(ohm)of hv side') \n",
      "Xlv=Xohm(Vlv,MVAa)      \n",
      "print(Xlv,'X(ohm)of lv side') \n",
      "\n",
      "print('(b)') \n",
      "print('Y/Y') \n",
      "MVAb=MVAa*3 \n",
      "Vhv=6.6*math.sqrt(3)     \n",
      "print(Vhv,'V_hv(kV)') \n",
      "Vlv=.4*math.sqrt(3)      \n",
      "print(Vlv,'V_lv(kV)') \n",
      "Xhv=Xohm(Vhv,MVAb)      \n",
      "print(Xhv,'X(ohm)of hv side') \n",
      "Xlv=Xohm(Vlv,MVAb)      \n",
      "print(Xlv,'X(ohm)of lv side') \n",
      "\n",
      "print('Y/D') \n",
      "MVAb=MVAa*3 \n",
      "Vhv=6.6*math.sqrt(3)     \n",
      "print(Vhv,'V_hv(kV)') \n",
      "Vlv=.4              \n",
      "print(Vlv,'V_lv(kV)') \n",
      "Xhv=Xohm(Vhv,MVAb)     \n",
      "\n",
      "#Results\n",
      "print(Xhv,'X(ohm)of hv side') \n",
      "Xlv=Xohm(Vlv,MVAb)      \n",
      "print(Xlv,'X(ohm)of lv side') "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)\n",
        "(69.69599999999998, 'X(ohm)of hv side')\n",
        "(0.25600000000000006, 'X(ohm)of lv side')\n",
        "(b)\n",
        "Y/Y\n",
        "(11.431535329954588, 'V_hv(kV)')\n",
        "(0.6928203230275509, 'V_lv(kV)')\n",
        "(69.69599999999998, 'X(ohm)of hv side')\n",
        "(0.256, 'X(ohm)of lv side')\n",
        "Y/D\n",
        "(11.431535329954588, 'V_hv(kV)')\n",
        "(0.4, 'V_lv(kV)')\n",
        "(69.69599999999998, 'X(ohm)of hv side')\n",
        "(0.08533333333333334, 'X(ohm)of lv side')\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.24, Page No 231"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "#find how 2 transformers connected in parallel share the load\n",
      "\n",
      "Z1=complex(.012,.06) \n",
      "Z2=2*complex(.014,.045) \n",
      "Z=Z1+Z2 \n",
      "r=800         #kva rating\n",
      "pf=.8 \n",
      "\n",
      "#Calculations\n",
      "S_L=r*(complex(pf,-1*math.cos(math.radians(math.degrees(math.acos(pf)))))) \n",
      "S_1=S_L*Z2/Z \n",
      "print(S_1,'load by first transformer(kVA)') \n",
      "S_2=S_L*Z1/Z \n",
      "print(S_2,'load by second transformer(kVA)') \n",
      "\n",
      "S_2rated=300 \n",
      "S_Lmax=S_2rated*abs(Z)/abs(Z1) \n",
      "print(S_Lmax,'max load by both transformer(kVA)') \n",
      "\n",
      "r1=600         #kva\n",
      "V=440 \n",
      "Z1actual=Z1*V/(r1*1000/V) \n",
      "Z2actual=Z2*V/(r1*1000/V) \n",
      "Zactual=Z1actual+Z2actual \n",
      "Z_Lact=V**2/(S_L*1000) \n",
      "\n",
      "V1=445 \n",
      "I1=(V1*Z2actual-10*Z_Lact)/(Z1actual*Z2actual+Z_Lact*Zactual) \n",
      "I2=(V1*-1*Z1actual-10*Z_Lact)/(Z1actual*Z2actual+Z_Lact*Zactual) \n",
      "S1=V*I1/1000     \n",
      "print(S1,'kVA of first transformer') \n",
      "S2=V*I2/1000.0\n",
      "\n",
      "#Results\n",
      "print(S2,'kVA of second transformer') \n",
      "Pout=abs(S1)*math.cos(math.radians(math.degrees(math.atan((S1.imag)/(S1.real)))))+abs(S2)*math.cos(math.radians(math.degrees(math.atan((S2.imag)/(S2.real))))) \n",
      "print(Pout,'total output power(kW)') \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "((372.3153526970954-404.18257261410787j), 'load by first transformer(kVA)')\n",
        "((267.6846473029046-235.81742738589213j), 'load by second transformer(kVA)')\n",
        "(761.1352856601269, 'max load by both transformer(kVA)')\n",
        "((328.8923360471516-318.290570499325j), 'kVA of first transformer')\n",
        "((-271.1465723386868+316.1011277711098j), 'kVA of second transformer')\n",
        "(600.0389083858385, 'total output power(kW)')\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.25, Page No 231"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "#find pu value of the equivalent ckt,steady state short ckt current and voltages\n",
      "\n",
      "r=5.0         #MVA rating\n",
      "V_Bp=6.35     #for primary\n",
      "I_Bp=r*1000/V_Bp \n",
      "V_Bs=1.91     #for secondary\n",
      "I_Bs=r*1000/V_Bs \n",
      "#from resp tests\n",
      "V1=.0787 \n",
      "I1=.5 \n",
      "V2=.1417 \n",
      "I2=.5 \n",
      "V3=.1212 \n",
      "I3=.5 \n",
      "\n",
      "#Calculations\n",
      "X12=V1/I1 \n",
      "X13=V2/I2 \n",
      "X23=V3/I3 \n",
      "X1=I1*(X12+X13-X23) \n",
      "X2=I2*(X23+X12-X13) \n",
      "X3=I3*(X13+X23-X12) \n",
      "print(X1,'X1(pu)') \n",
      "print(X2,'X2(pu)') \n",
      "print(X3,'X3(pu)') \n",
      "\n",
      "V1=1 \n",
      "I_sc=V1/X13 \n",
      "I_scp=I_sc*I_Bp     \n",
      "print(I_scp,'sc current primary side(A)') \n",
      "I_sct=I_sc*r*1000.0*1000/(400/math.sqrt(3.0))  \n",
      "\n",
      "#Results\n",
      "print(I_sct,'sc current tertiary side(A)') \n",
      "V_A=I_sc*X3 \n",
      "V_Aact=V_A*1.91*math.sqrt(3) \n",
      "print(V_Aact,'V_A(actual) line to line(kV)') "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(0.09919999999999998, 'X1(pu)')\n",
        "(0.05820000000000003, 'X2(pu)')\n",
        "(0.18420000000000003, 'X3(pu)')\n",
        "(2778.410637978651, 'sc current primary side(A)')\n",
        "(76396.03067964349, 'sc current tertiary side(A)')\n",
        "(2.1502243444618827, 'V_A(actual) line to line(kV)')\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.26, Page No 231"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "# to calculate line currents of 3 ph side\n",
      "\n",
      "N1=6600.0 \n",
      "N2=100.0 \n",
      "a=N1/N2 \n",
      "b=(math.sqrt(3)/2)*a \n",
      "P=400.0     #kW\n",
      "pfa=.707 \n",
      "pfb=1 \n",
      "V=100 \n",
      "\n",
      "#Calculations\n",
      "Ia=P*1000/(V*pfa) \n",
      "Ib=P*2*1000/(V*pfb) \n",
      "I_A=Ia/b \n",
      "print(I_A,'I_A(A)') \n",
      "I_BC=Ib/a \n",
      "I_B=I_BC-49.5*complex(pfa,pfa) \n",
      "\n",
      "#Results\n",
      "print(abs(I_B),'I_B(A)') \n",
      "I_C=I_BC+49.5*complex(pfa,-1*pfa) \n",
      "print(abs(I_C),'I_C(A)') \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(98.98423028410711, 'I_A(A)')\n",
        "(93.04777457436566, 'I_B(A)')\n",
        "(160.08088066112694, 'I_C(A)')\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.27, Page No 231"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "#to calculate magnitude and phase of secondary current\n",
      "\n",
      "X1=505.0     #uohm\n",
      "X2=551.0     #uohm\n",
      "R1=109.0     #uohm\n",
      "R2=102.0     #uohm\n",
      "Xm=256.0     #mohm\n",
      "I1=250.0     #A\n",
      "\n",
      "#Calculations\n",
      "I22=complex(0,Xm*1000)*I1/(complex(R1,X2+Xm*1000)) \n",
      "N1=250.0\n",
      "N2=5.0 \n",
      "I2=I22*(N2/N1) \n",
      "print(abs(I2),'current magnitude(A)') \n",
      "print(math.degrees(math.atan((I2.imag)/(I2.real))),'phase(degree)') \n",
      "print('now Rb is introduced in series') \n",
      "Rbb=200     #uohm\n",
      "Rb=(N2/N1)**2*Rbb \n",
      "I22=complex(0,Xm*1000)*I1/(complex((R1+Rb),X2+Xm*1000)) \n",
      "I2=I22*(N2/N1) \n",
      "\n",
      "#Results\n",
      "print(abs(I2),'current magnitude(A)') \n",
      "print(math.degrees(math.atan((I2.imag)/(I2.real))),'phase(degree)') \n",
      "print('no chnage as Rb is negligible') \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(4.989260944110411, 'current magnitude(A)')\n",
        "(0.02434307249297878, 'phase(degree)')\n",
        "now Rb is introduced in series\n",
        "(4.989260943449164, 'current magnitude(A)')\n",
        "(0.024360938966050547, 'phase(degree)')\n",
        "no chnage as Rb is negligible\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.28, Page No 231"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "#to calculate sec voltage magnitude and ph\n",
      " \n",
      "a=6000.0/100     #turn ratio\n",
      "R1=780.0 \n",
      "R2=907.0 \n",
      "X1=975.0 \n",
      "X2=1075.0 \n",
      "Xm=443.0*1000 \n",
      "print('sec open') \n",
      "#Zb=inf \n",
      "V1=6500.0\n",
      "\n",
      "#Calculations\n",
      "V22=complex(0,Xm)*V1/complex(R1,Xm) \n",
      "V2=V22/a \n",
      "print(abs(V2),'voltage magnitude(V)') \n",
      "print(math.degrees(math.atan((V2.imag)/(V2.real))),'phase(deg)') \n",
      "\n",
      "print('when Zb=Rb') \n",
      "Rb=1 \n",
      "Rbb=Rb*a**2 \n",
      "Zm=complex(0,Xm/1000)*Rbb/complex(0,Xm/1000)+Rbb \n",
      "R=complex(R1/1000,X1/1000)+Zm \n",
      "Vm=Zm*V1/R \n",
      "V2=Vm/a \n",
      "print(abs(V2),'voltage magnitude(V)') \n",
      "print(math.degrees(math.atan((V2.imag)/(V2.real))),'phase(deg)') \n",
      "\n",
      "print('when Zb=jXb') \n",
      "Rb=complex(0,1) \n",
      "Rbb=Rb*a**2 \n",
      "Zm=complex(0,Xm/1000)*Rbb/complex(0,Xm/1000)+Rbb \n",
      "R=complex(R1/1000,X1/1000)+Zm \n",
      "Vm=Zm*V1/R \n",
      "V2=Vm/a \n",
      "\n",
      "#Results\n",
      "print(abs(V2),'voltage magnitude(V)') \n",
      "print(math.degrees(math.atan((V2.imag)/(V2.real))),'phase(deg)') \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "sec open\n",
        "(108.33316540930123, 'voltage magnitude(V)')\n",
        "(0.10088185516424111, 'phase(deg)')\n",
        "when Zb=Rb\n",
        "(108.32159750052864, 'voltage magnitude(V)')\n",
        "(-0.007757962982324285, 'phase(deg)')\n",
        "when Zb=jXb\n",
        "(108.31866454530893, 'voltage magnitude(V)')\n",
        "(0.006206202333075708, 'phase(deg)')\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.29, Page No 231"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "#to calculate L1 and L2 and coupling cofficient\n",
      "\n",
      "a=10.0 \n",
      "V_p=200.0 \n",
      "I_p=4.0 \n",
      "Xm=V_p/I_p \n",
      "f=50 \n",
      "\n",
      "#Calculations\n",
      "L1=Xm/(2*math.pi*f) \n",
      "print(L1,'L1(H)') \n",
      "V_s=1950.0 \n",
      "w_max=V_s/(math.sqrt(2)*math.pi*f) \n",
      "M=w_max/(math.sqrt(2)*I_p) \n",
      "\n",
      "v_s=2000 \n",
      "i_s=.41 \n",
      "w_max=math.sqrt(2)*i_s*M \n",
      "E1=math.sqrt(2)*math.pi*f*w_max \n",
      "L2=v_s/(math.sqrt(2)*math.pi*f*math.sqrt(2)*i_s) \n",
      "\n",
      "#Results\n",
      "print(L2,'L2(H)') \n",
      "k=M/(math.sqrt(L1)*math.sqrt(L2)) \n",
      "print(k,'coupling coeff') "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(0.15915494309189535, 'L1(H)')\n",
        "(15.527311521160522, 'L2(H)')\n",
        "(0.9871122656516838, 'coupling coeff')\n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.30, Page No 231"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "# to calculate leakage inductance, magnetisisng inductance,mutual inductance and self-inductance\n",
      " \n",
      "V1=2400.0\n",
      "V2=240.0 \n",
      "a=V1/V2 \n",
      "R1=.2 \n",
      "X1=.45 \n",
      "Rl=10000.0 \n",
      "R2=2*10**-3 \n",
      "X2=4.5*10**-3 \n",
      "Xm=1600.0 \n",
      "f=50.0 \n",
      "\n",
      "#Calculations\n",
      "l1=X1/(2*math.pi*f) \n",
      "print(l1,'leakage inductance ie l1(H)') \n",
      "l2=X2/(2*math.pi*f) \n",
      "print(l2,'l2(H)') \n",
      "Lm1=Xm/(2*math.pi*f) \n",
      "print(Lm1,'magnetising inductance(H)') \n",
      "L1=Lm1+l1 \n",
      "print(L1,'self-inductance ie L1(H)') \n",
      "M=Lm1/a \n",
      "L2=l2+M/a \n",
      "print(L2,'L2(H)') \n",
      "k=M/math.sqrt(L1*L2) \n",
      "\n",
      "#Results\n",
      "print(k,'coupling factor') "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(0.001432394487827058, 'leakage inductance ie l1(H)')\n",
        "(1.4323944878270581e-05, 'l2(H)')\n",
        "(5.092958178940651, 'magnetising inductance(H)')\n",
        "(5.094390573428478, 'self-inductance ie L1(H)')\n",
        "(0.050943905734284776, 'L2(H)')\n",
        "(0.9997188290793214, 'coupling factor')\n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.31, Page No 231"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "#to calculate %voltage reg and efficiency\n",
      "\n",
      "P=500000.0 \n",
      "V1=2200.0 \n",
      "V2=1100.0 \n",
      "V0=110.0 \n",
      "I0=10.0 \n",
      "P0=400.0 \n",
      "\n",
      "#Calculations\n",
      "Y0=I0/V0 \n",
      "Gi=P0/(V0**2) \n",
      "Bm=math.sqrt(Y0**2-Gi**2) \n",
      "Vsc=90 \n",
      "Isc=20.5 \n",
      "Psc=808 \n",
      "Z=Vsc/Isc \n",
      "R=Psc/Isc**2 \n",
      "X=math.sqrt(Z**2-R**2) \n",
      "TR=V1/V2 \n",
      "Gi_HV=Gi/TR**2 \n",
      "Bm_HV=Bm/TR**2 \n",
      "R_LV=R/TR**2 \n",
      "X_LV=X/TR**2 \n",
      "I2=P/V2 \n",
      "pf=.8 \n",
      "Th=math.acos(pf) \n",
      "dV=I2*(R_LV*math.cos(Th)+X_LV*math.sin(Th)) \n",
      "VR=(dV/V2)*100     \n",
      "print(VR,'voltage regulation(%)') \n",
      "Pi=P0 \n",
      "Pc=Psc \n",
      "n=P*100/(P+Pi+Pc) \n",
      "\n",
      "#Results\n",
      "print(n,'eff(%)') "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(40.35372116523329, 'voltage regulation(%)')\n",
        "(99.75898229876618, 'eff(%)')\n"
       ]
      }
     ],
     "prompt_number": 22
    }
   ],
   "metadata": {}
  }
 ]
}