{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 23 : State Estimation In Power Systems"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 23.1, Page No 148"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "C1=0.02*100\n",
      "C2=0.05\n",
      "Fs=100\n",
      "S1=complex(0.41,-0.11)\n",
      "S2=complex(-0.4, 0.10)\n",
      "S3=complex(-.105,0.11)\n",
      "S4=complex(-.105,.11)\n",
      "S5=complex(0.14,-.14)\n",
      "S6=complex(-0.7,.35)\n",
      "Z12=complex(0.08,.24)\n",
      "Z23=complex(0.06,.18)\n",
      "Z31=complex(0.02,.06)\n",
      "Z21=Z12\n",
      "Z32=Z23\n",
      "Z13=Z31\n",
      "\n",
      "#Calculations\n",
      "W1=(50*10**(-6))/((C1*abs(S1)+(C2*(Fs)))**2)\n",
      "W2=(50*10**(-6))/((C1*abs(S2)+C2*(Fs))**2)\n",
      "W3=(50*10**(-6))/((C1*abs(S3)+C2*(Fs))**2)\n",
      "W4=(50*10**(-6))/((C1*abs(S4)+C2*(Fs))**2)\n",
      "W5=(50*10**(-6))/((C1*abs(S5)+C2*(Fs))**2)\n",
      "W6=(50*10**(-6))/((C1*abs(S6)+C2*(Fs))**2)\n",
      "print(\"W1= %.2f\" %W1)\t\t\t#Answers for W1,W2,W3,W4,W5,W6 in the book is wrongly Calculated\n",
      "print(\"W2= %.2f\" %W2)\t\n",
      "print(\"W3= %.2f\" %W3)\t\n",
      "print(\"W4= %.2f\" %W4)\t\n",
      "print(\"W5= %.2f\" %W5)\t\n",
      "print(\"W6= %.2f\" %W6)\t\n",
      "a1=W1/(abs(13)**2)\n",
      "[D]=diag([W1/(abs(Z13)**2)W2/(abs(Z31)**2)W3/(abs(Z12)**2)W4/(abs(Z21)**2)W5/(abs(Z23)**2)W6/(abs(Z32)**2)])\n",
      "A=[-1 0 11 0 -11 -1 0-1 1 00 1 -10 -1 1]\n",
      "B=[-1 01 01 -1-1 10 10 -1]\n",
      "b=[1-100-11]\n",
      "C=(B')*D#Assuming Transpose(B)D=C\n",
      "F=(B')*D*B#Assuming Transpose(B)*D*B=F\n",
      "G=(inv(F))*C#Assuming(BTDB)-1*(BT)*D=F\n",
      "E1=1.05\n",
      "E2=E1\n",
      "E3=E1\n",
      "invH=diag([Z31/E3Z13/E1Z12/E1Z21/E2Z23/E2Z32/E2])\n",
      "Sm=[.41+%i*.11-.4-%i*.1-.105-%i*.11.14+%i*.14.72+%i*.37-.7+%i*.35]\n",
      "EMo=invH*Sm\n",
      "a=EMo-b*E1\n",
      "E=G*a\n",
      "\n",
      "#Results\n",
      "print(E,\"E=\")  #Answers differs due to wrong calculation of W1,W2,W3,W4,W5,W6"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(i) For p.f unity , Eth= 1.34000+0.00000i\n",
        "(i) For p.f .8 , Eth= 1.59500+0.00000i\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 22.3, Page No 149"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "X=.625\n",
      "P=1.0\n",
      "Q=0.6\n",
      "V=1.0\n",
      "\n",
      "#Calculations\n",
      "Eth=V+(Q*X/V)+complex(P*X/V)\n",
      "Phase_Eth=math.degrees(math.atan(Eth.imag/Eth.real))\n",
      "\n",
      "#Results\n",
      "print(\"Eth=%.2f at an angle %.0f degrees\" %(abs(Eth),Phase_Eth))"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Eth=2.00 at an angle 0 degrees\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 22.4, Page No 149"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "P=0.5\n",
      "toff=4.0\n",
      "\n",
      "#Calculations\n",
      "ton=(P*toff-0*toff)/(0.8-P)\n",
      "\n",
      "#Results\n",
      "print(\"Toff= 4min .\")\n",
      "print(\"ton(min.)=%.3f min.\" %ton)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Toff= 4min .\n",
        "ton(min.)=6.667 min.\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 22.6 Page No 150"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "V=1.0\n",
      "Qload=1.0*V\n",
      "Qcap=-0.75*V**2\n",
      "\n",
      "#Calculations\n",
      "Qnet=Qload+Qcap\n",
      "VS=1-0.75*2*V     # voltage sensitivity\n",
      "\n",
      "#Results\n",
      "print(\"Voltage sensitivity=%.3f\" %VS)\n",
      "print(\"since the voltage sensitivity is negative,\\nvoltage regulation by tap changing will reduce net reactive load and improive voltage stability \")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Voltage sensitivity=-0.500\n",
        "since the voltage sensitivity is negative,\n",
        "voltage regulation by tap changing will reduce net reactive load and improive voltage stability \n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 22.7, Page No 151"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "Y=complex(-10)\n",
      "n=1+0.1\n",
      "\n",
      "#Calculations\n",
      "Y1=n*(n-1)*Y\n",
      "Y2=(1-n)*Y\n",
      "\n",
      "#Results\n",
      "print(\"Y1= {0:.2f}+{1:.2f}i\".format(Y1.real, Y1.imag))\n",
      "print(\"Y2= {0:.2f}+{1:.2f}i\".format(Y2.real, Y2.imag))\n",
      "print(\"The shunt elements equal to a reactor of 1.1V1^2 size oin the primary side and a capacitive of sixe 1V2**2 on the secondary side\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Y1= -1.10+0.00i\n",
        "Y2= 1.00+-0.00i\n",
        "The shunt elements equal to a reactor of 1.1V1^2 size oin the primary side and a capacitive of sixe 1V2**2 on the secondary side\n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 22.8, Page No 152"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import math\n",
      "#initialisation of variables\n",
      "P=1.0\t\t#assuming\n",
      "S1=P/.95\t#For pf .95\n",
      "S2=P/.8\t\t#For pf .8\n",
      "\n",
      "#Calculations\n",
      "dMVA=(S2-S1)*100.0/P\t\t#Increase in MVA rating \n",
      "Q1=P*math.tan(math.radians(math.degrees(math.acos(0.95))))\t\t#Q for pf .95\n",
      "Q2=P*math.tan(math.radians(math.degrees(math.acos(0.8))))\t\t#Q for pf .8\n",
      "dPc=(Q2-Q1)*100.0/Q1\t\t#Percent additional Reactive Power Capability \n",
      "\n",
      "#Results\n",
      "print(\"Percent additional Reactive Power Capability is %.2f\" %dPc)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Percent additional Reactive Power Capability is 128.18\n"
       ]
      }
     ],
     "prompt_number": 17
    }
   ],
   "metadata": {}
  }
 ]
}