{ "metadata": { "name": "", "signature": "sha256:b3ef09fe669f6e389f68566c0a4c0c7f68ba17783f87d6b65b51a4db7cae692e" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Chapter7-Graph theory" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Ex7-pg7.18" ] }, { "cell_type": "code", "collapsed": false, "input": [ "## Graph Theory : example 7.7 : (pg 7.18 & 7.19)\n", "import numpy\n", "\n", "##Complete incidence matrix Aa\n", "print(\"\\nAa=\");\n", "print numpy.matrix([[1, 0 ,0 ,-1 ,1 ,0 ,0 ,0],[-1, 1, 0 ,0 ,0 ,1 ,0 ,0],[0 ,-1 ,1 ,0 ,0 ,0 ,1 ,0],[0, 0 ,-1, 1 ,0 ,0 ,0, 1],[0 ,0 ,0 ,0 ,-1, -1 ,-1, -1]]);\n", "##eliminating last row from Aa\n", "print(\"\\nA=\");\n", "print numpy.matrix([[1, 0 ,0 ,-1, 1 ,0 ,0 ,0],[-1, 1 ,0 ,0 ,0 ,1 ,0 ,0],[0 ,-1, 1, 0, 0 ,0 ,1 ,0],[0, 0, -1, 1 ,0 ,0 ,0 ,1]]);\n", "##Tieset matrix B\n", "print(\"\\ntwigs={1,3,5,7} \\nlinks={2,4,6,8} \\ntieset 2={2,7,5,1} \\ntieset 4={4,5,7,3} \\ntieset 6={6,5,1} \\ntieset 8={8,7,3}\");\n", "## forward direction = 1, reverse direction = -1\n", "print(\"\\nB=\");\n", "print numpy.matrix([[1, 1 ,0 ,0 ,-1, 0, 1, 1],[0, 0, 1 ,1 ,1 ,0, -1, 0],[1, 0 ,0 ,0 ,-1, 1, 0, 0],[0, 0 ,1 ,0 ,0 ,0 ,-1, 1]]);\n", "## f-cutset matrix Q\n", "print(\"\\nf-cutset 1={1,6,2} \\nf-cutset 3={3,4,8} \\nf-cutset 5={5,4,6,2} \\nf-cutset 7={7,2,8,4}\");\n", "print(\"\\nQ=\");\n", "print numpy.matrix([[1 ,-1, 0, 0, 0 ,-1, 0, 0],[0 ,0, 1, -1, 0, 0 ,0 ,-1],[0, 1, 0 ,-1, 1, 1, 0, 0],[0 ,-1, 0, 1, 0 ,0, 1, 1]]);" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\n", "Aa=\n", "[[ 1 0 0 -1 1 0 0 0]\n", " [-1 1 0 0 0 1 0 0]\n", " [ 0 -1 1 0 0 0 1 0]\n", " [ 0 0 -1 1 0 0 0 1]\n", " [ 0 0 0 0 -1 -1 -1 -1]]\n", "\n", "A=\n", "[[ 1 0 0 -1 1 0 0 0]\n", " [-1 1 0 0 0 1 0 0]\n", " [ 0 -1 1 0 0 0 1 0]\n", " [ 0 0 -1 1 0 0 0 1]]\n", "\n", "twigs={1,3,5,7} \n", "links={2,4,6,8} \n", "tieset 2={2,7,5,1} \n", "tieset 4={4,5,7,3} \n", "tieset 6={6,5,1} \n", "tieset 8={8,7,3}\n", "\n", "B=\n", "[[ 1 1 0 0 -1 0 1 1]\n", " [ 0 0 1 1 1 0 -1 0]\n", " [ 1 0 0 0 -1 1 0 0]\n", " [ 0 0 1 0 0 0 -1 1]]\n", "\n", "f-cutset 1={1,6,2} \n", "f-cutset 3={3,4,8} \n", "f-cutset 5={5,4,6,2} \n", "f-cutset 7={7,2,8,4}\n", "\n", "Q=\n", "[[ 1 -1 0 0 0 -1 0 0]\n", " [ 0 0 1 -1 0 0 0 -1]\n", " [ 0 1 0 -1 1 1 0 0]\n", " [ 0 -1 0 1 0 0 1 1]]\n" ] } ], "prompt_number": 1 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Ex8-pg7.19" ] }, { "cell_type": "code", "collapsed": false, "input": [ "## Graph Theory : example 7.8 :(pg 7.19 & 7.20)\n", "##Complete Incidence Matrix Aa\n", "import numpy\n", "from numpy import linalg\n", "print(\"\\nAa=\");\n", "import numpy\n", "print numpy.matrix([[1 ,0 ,-1 ,1],[-1, 1 ,0 ,0],[0 ,-1 ,1 ,-1]]);\n", "## Reduced Incidence matrix A (by eliminating last row from Aa)\n", "A=numpy.matrix([[1 ,0, -1, 1],[-1, 1 ,0 ,0]]);\n", "print(\"\\nA=\");\n", "print numpy.matrix([[1 ,0 ,-1 ,1],[-1, 1 ,0 ,0]]);\n", "A1=numpy.matrix([[1 ],[0], [-1], [1],[-1], [1] ,[0] ,[0]]);\n", "print(\"A1\")\n", "\n", "print(\"\\nNumber of possible trees=\");##A^T=A'= transpose of A\n", "x=(A*numpy.matrix.transpose(A));\n", "print (x);\n", "alp = numpy.linalg.det(x);\n", "\n", "print(alp)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\n", "Aa=\n", "[[ 1 0 -1 1]\n", " [-1 1 0 0]\n", " [ 0 -1 1 -1]]\n", "\n", "A=\n", "[[ 1 0 -1 1]\n", " [-1 1 0 0]]\n", "A1\n", "\n", "Number of possible trees=\n", "[[ 3 -1]\n", " [-1 2]]\n", "5.0\n" ] } ], "prompt_number": 5 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Ex11-pg7.21" ] }, { "cell_type": "code", "collapsed": false, "input": [ "# Graph Theory : example 7.11 :(pg 7.21 & 7.22)\n", "import numpy\n", "from numpy import linalg\n", "print (\"Aa=[0 -1 1 0 0;0 0 -1 -1 -1;-1 0 0 0 1;1 1 0 1 0]\");#Complete incidence matrix\n", "A=numpy.matrix([[0, -1, 1, 0, 0],[0, 0, -1, -1, -1],[-1, 0, 0, 0, 1]]);#Reduced incidence matrix\n", "print(\"\\nNumber of possible trees = |A*A^T|\");#A^T=A'=transpose of A \n", "x=(A*numpy.matrix.transpose(A));\n", "print (x);\n", "alp = numpy.linalg.det(x);\n", "print(\"\\n|A*A^T|= \",round(alp));#No. of possible trees\n", "#Tieset Matrix B\n", "print(\"\\ntwigs={3,4,5} \\nlinks={1,2} \\ntieset 1={1,4,5} \\ntieset 2={2,3,4}\");\n", "print (\"B=[1 0 0 -1 1;0 1 1 -1 0]\");\n", "#f-cutset Matrix Q\n", "print(\"\\nf-cutset 3={3,2} \\nf-cutset 4={4,2,1} \\nf-cutset 5={5,1}\");\n", "print (\"Q=[0 -1 1 0 0;1 1 0 1 0;-1 0 0 0 1]\");" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Aa=[0 -1 1 0 0;0 0 -1 -1 -1;-1 0 0 0 1;1 1 0 1 0]\n", "\n", "Number of possible trees = |A*A^T|\n", "[[ 2 -1 0]\n", " [-1 3 -1]\n", " [ 0 -1 2]]\n", "('\\n|A*A^T|= ', 8.0)\n", "\n", "twigs={3,4,5} \n", "links={1,2} \n", "tieset 1={1,4,5} \n", "tieset 2={2,3,4}\n", "B=[1 0 0 -1 1;0 1 1 -1 0]\n", "\n", "f-cutset 3={3,2} \n", "f-cutset 4={4,2,1} \n", "f-cutset 5={5,1}\n", "Q=[0 -1 1 0 0;1 1 0 1 0;-1 0 0 0 1]\n" ] } ], "prompt_number": 4 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Ex14-pg7.27" ] }, { "cell_type": "code", "collapsed": false, "input": [ "##Graph Theory : example 7.14 :(pg 7.37 & 7.38)\n", "##Tieset Matrix B\n", "import numpy\n", "import numpy\n", "from numpy import linalg\n", "print(\"\\ntieset1={1,4,5} \\ntieset2={2,4,6} \\ntieset={3,5,6} \\nB=\"); \n", "B=numpy.matrix([[1, 0 ,0 ,1 ,1 ,0],[0 ,1 ,0 ,-1, 0, -1],[0, 0 ,1 ,0 ,-1, 1]]);\n", "print(B);\n", "print(\"\\nThe KVL equation in matrix form \\nB.Zb.(B^T).Il = B.Vs-B.Zb.Is\");\n", "print(\"\\nB.Zb.(B^T).Il = B.Vs \\nZb=\");##Is=0\n", "import numpy as np\n", "Zb = np.array([1,1,1,2,2,2])\n", "d = np.diag(Zb)\n", "print(d)\n", "\n", "print(\"\\n(B^T)=\");\n", "Z= numpy.matrix.transpose(B)\n", "print(Z)\n", "Vs=numpy.matrix([[2],[0],[0],[0],[0],[0]]);\n", "print(\"\\nVs=\");\n", "print(Vs);\n", "print(\"\\nB.Zb =\");\n", "x=numpy.dot(B,Zb);\n", "print(x);\n", "\n", "print(\"\\nB.Vs=\");\n", "z=numpy.dot(B,Vs);\n", "print(z);\n", "print(\"\\nLoad currents:\");\n", "M=numpy.matrix([[5, -2 ,-2],[-2 ,5 ,-2],[-2, -2, 5]]);\n", "H=numpy.linalg.inv(M);\n", "N=([[2],[0],[0]]);\n", "X=numpy.dot(H,N);\n", "print(X);\n", "print(\"\\nIl1=0.857 A \\nIl2=0.571 A \\nIl3=0.571 A\");\n", "print(\"\\nBranch currents:\");\n", "P=(Z,X);\n", "print(P);##Currents in amperes\n", "\n", "\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\n", "tieset1={1,4,5} \n", "tieset2={2,4,6} \n", "tieset={3,5,6} \n", "B=\n", "[[ 1 0 0 1 1 0]\n", " [ 0 1 0 -1 0 -1]\n", " [ 0 0 1 0 -1 1]]\n", "\n", "The KVL equation in matrix form \n", "B.Zb.(B^T).Il = B.Vs-B.Zb.Is\n", "\n", "B.Zb.(B^T).Il = B.Vs \n", "Zb=\n", "[[1 0 0 0 0 0]\n", " [0 1 0 0 0 0]\n", " [0 0 1 0 0 0]\n", " [0 0 0 2 0 0]\n", " [0 0 0 0 2 0]\n", " [0 0 0 0 0 2]]\n", "\n", "(B^T)=\n", "[[ 1 0 0]\n", " [ 0 1 0]\n", " [ 0 0 1]\n", " [ 1 -1 0]\n", " [ 1 0 -1]\n", " [ 0 -1 1]]\n", "\n", "Vs=\n", "[[2]\n", " [0]\n", " [0]\n", " [0]\n", " [0]\n", " [0]]\n", "\n", "B.Zb =\n", "[[ 5 -3 1]]\n", "\n", "B.Vs=\n", "[[2]\n", " [0]\n", " [0]]\n", "\n", "Load currents:\n", "[[ 0.85714286]\n", " [ 0.57142857]\n", " [ 0.57142857]]\n", "\n", "Il1=0.857 A \n", "Il2=0.571 A \n", "Il3=0.571 A\n", "\n", "Branch currents:\n", "(matrix([[ 1, 0, 0],\n", " [ 0, 1, 0],\n", " [ 0, 0, 1],\n", " [ 1, -1, 0],\n", " [ 1, 0, -1],\n", " [ 0, -1, 1]]), matrix([[ 0.85714286],\n", " [ 0.57142857],\n", " [ 0.57142857]]))\n" ] } ], "prompt_number": 6 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Ex15-pg7.28" ] }, { "cell_type": "code", "collapsed": false, "input": [ "##Graph Theory : example 7.15 :(pg 7.38 & 7.39)\n", "##Tieset Matrix B\n", "import numpy\n", "import numpy\n", "from numpy import linalg\n", "print(\"\\ntieset1={1,4,6} \\ntieset2={2,5,6} \\ntieset={3,5,4} \\nB=\"); \n", "B=numpy.matrix([[1, 0 ,0 ,1 ,0 ,1],[0, 1, 0, 0, 1 ,-1],[0 ,0 ,1 ,-1 ,-1 ,0]]);\n", "print(B);\n", "print(\"\\nThe KVL equation in matrix form \\nB.Zb.(B^T).Il = B.Vs-B.Zb.Is\");\n", "print(\"\\nB.Zb.(B^T).Il = B.Vs \\nZb=\");##Is=0\n", "Zb = numpy.array([6,4,3,4,6,2])\n", "d = numpy.diag(Zb)\n", "print(d)\n", "XY=numpy.matrix.transpose(B)\n", "print(\"\\n(B^T)=\");\n", "print(XY);\n", "Vs=([[12],[-6],[-8],[0],[0],[0]]);\n", "print(\"\\nVs=\");\n", "print(Vs);\n", "print(\"\\nB.Zb=\");\n", "x=numpy.dot(B,Zb);\n", "print(x);\n", "print(\"\\nB.Zb.(B^T)=\");\n", "#y=numpy.dot(XY,x);\n", "#print(y);\n", "print(\"\\nB.Vs=\");\n", "z=numpy.dot(B,Vs);\n", "print(z);\n", "print(\"\\nLoad currents:\");\n", "M=numpy.matrix([[12 ,-2 ,-4],[-2, 12, -6],[-4, -6, 12]]);\n", "H=numpy.linalg.inv(M);\n", "N=([[12],[-6],[-8]]);\n", "X=numpy.dot(H,N);\n", "print(X);\n", "print(\"\\nIl1=0.55 A \\nIl2=-0.866 A \\nIl3=-0.916 A\");\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\n", "tieset1={1,4,6} \n", "tieset2={2,5,6} \n", "tieset={3,5,4} \n", "B=\n", "[[ 1 0 0 1 0 1]\n", " [ 0 1 0 0 1 -1]\n", " [ 0 0 1 -1 -1 0]]\n", "\n", "The KVL equation in matrix form \n", "B.Zb.(B^T).Il = B.Vs-B.Zb.Is\n", "\n", "B.Zb.(B^T).Il = B.Vs \n", "Zb=\n", "[[6 0 0 0 0 0]\n", " [0 4 0 0 0 0]\n", " [0 0 3 0 0 0]\n", " [0 0 0 4 0 0]\n", " [0 0 0 0 6 0]\n", " [0 0 0 0 0 2]]\n", "\n", "(B^T)=\n", "[[ 1 0 0]\n", " [ 0 1 0]\n", " [ 0 0 1]\n", " [ 1 0 -1]\n", " [ 0 1 -1]\n", " [ 1 -1 0]]\n", "\n", "Vs=\n", "[[12], [-6], [-8], [0], [0], [0]]\n", "\n", "B.Zb=\n", "[[12 8 -7]]\n", "\n", "B.Zb.(B^T)=\n", "\n", "B.Vs=\n", "[[12]\n", " [-6]\n", " [-8]]\n", "\n", "Load currents:\n", "[[ 0.55 ]\n", " [-0.86666667]\n", " [-0.91666667]]\n", "\n", "Il1=0.55 A \n", "Il2=-0.866 A \n", "Il3=-0.916 A\n" ] } ], "prompt_number": 7 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Ex19-pg7.34" ] }, { "cell_type": "code", "collapsed": false, "input": [ "##Graph Theory : example 7.19 \n", "import math\n", "import numpy\n", "from numpy import linalg\n", "Q=numpy.matrix([[1, -1, 0, 0],[0 ,-1 ,1 ,1]]);\n", "print(\"\\nQ=\");\n", "print(Q);\n", "print(\"\\nThe KCL equation in matrix form is given by\");\n", "print(\"\\nQ.Yb.(Q^T).Vl=Q.Is-Q.Yb.Vs\");\n", "print(\"\\nQ.Yb.(Q^T).Vl=Q.Is\");##Vs=0\n", "Yb=numpy.array([5,5,5,10]);\n", "d=numpy.diag(Yb)\n", "Is=numpy.matrix([[-10],[0],[0],[0]]);\n", "print(\"\\nYb=\");\n", "print(d);\n", "print(\"\\n(Q^T)=\");\n", "ZZ=numpy.matrix.transpose(Q)\n", "print(ZZ);\n", "print(\"\\nIs=\");\n", "print(Is);##current entering into nodes is taken as negative\n", "x=numpy.dot(Q,Yb);\n", "print(\"\\nQ.Yb=\");\n", "print(x);\n", "#y=numpy.dot(x[0],ZZ);\n", "print(\"\\nQ.Yb.(Q^T)=\");\n", "#print(y);\n", "z=numpy.dot(Q,Is);\n", "print(\"\\nQ.Is=\");\n", "print(z);\n", "print(\"\\nLoad voltages:\");\n", "M=numpy.matrix([[10, 5],[5, 20]]);\n", "P=numpy.linalg.inv(M);\n", "N=numpy.matrix([[-10],[0]]);\n", "X=numpy.dot(P,N);\n", "print(X);\n", "print(\"\\nvl1=-1.14 V \\nvl2=0.28 V\");\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\n", "Q=\n", "[[ 1 -1 0 0]\n", " [ 0 -1 1 1]]\n", "\n", "The KCL equation in matrix form is given by\n", "\n", "Q.Yb.(Q^T).Vl=Q.Is-Q.Yb.Vs\n", "\n", "Q.Yb.(Q^T).Vl=Q.Is\n", "\n", "Yb=\n", "[[ 5 0 0 0]\n", " [ 0 5 0 0]\n", " [ 0 0 5 0]\n", " [ 0 0 0 10]]\n", "\n", "(Q^T)=\n", "[[ 1 0]\n", " [-1 -1]\n", " [ 0 1]\n", " [ 0 1]]\n", "\n", "Is=\n", "[[-10]\n", " [ 0]\n", " [ 0]\n", " [ 0]]\n", "\n", "Q.Yb=\n", "[[ 0 10]]\n", "\n", "Q.Yb.(Q^T)=\n", "\n", "Q.Is=\n", "[[-10]\n", " [ 0]]\n", "\n", "Load voltages:\n", "[[-1.14285714]\n", " [ 0.28571429]]\n", "\n", "vl1=-1.14 V \n", "vl2=0.28 V\n" ] } ], "prompt_number": 12 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Ex20-pg7.35" ] }, { "cell_type": "code", "collapsed": false, "input": [ "##Graph Theory : example 7.20 :(pg 7.35 & 7.36)\n", "import numpy\n", "from numpy import linalg\n", "print(\"\\nf-cutset1={1,4,5,6} \\nf-cutset2={2,4,5} \\nf-cutset3={3,4,6}\");\n", "Q=numpy.matrix([[1, 0 ,0 ,-1, -1, 1],[0 ,1 ,0 ,-1, -1 ,0],[0 ,0, 1, -1 ,0 ,1]]);\n", "print(\"\\nQ=\");\n", "print(Q);\n", "print(\"\\nThe KCL equation in matrix form is given by\");\n", "print(\"\\nQ.Yb.(Q^T).Vl=Q.Is-Q.Yb.Vs\");\n", "print(\"\\nQ.Yb.(Q^T).Vl=Q.Is\");##Is=0\n", "Yb=numpy.array([0.2,0.2,0.2,0.1,0.5,0.1]);\n", "yz=numpy.diag(Yb)\n", "Vs=numpy.matrix([[910],[0],[0],[0],[0],[0]]);\n", "Is=numpy.matrix([[0],[0],[0],[0],[0],[0]]);\n", "print(\"\\nyz=\");\n", "print(yz);\n", "print(\"\\nVs=\");\n", "print(Vs);\n", "print(\"\\nIs=\");\n", "print(Is);\n", "x=numpy.dot(Q,yz);\n", "print(\"\\nQ.Yb=\");\n", "print(x);\n", "z=numpy.dot(x,Vs);\n", "print(\"\\nQ.Yb.Vs=\");\n", "print(z);\n", "print(\"\\nQ.Is=\");\n", "u=numpy.dot(Q,Is);\n", "print(u);\n", "v=(u-z);\n", "print(\"\\nQ.Is-Q.Yb.Vs=\");\n", "print(v);\n", "print(\"\\nLoad voltages:\");\n", "M=([[0.9, 0.6, 0.2],[0.6, 0.8, 0.1],[0.2 ,0.1 ,0.3]]);\n", "P=numpy.linalg.inv(M);\n", "N=([[-182],[0],[0]]);\n", "X=numpy.dot(P,N);\n", "print(X);\n", "print(\"\\nvl1=-460 V \\nvl2=320 V \\nvl3=200 V\");\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\n", "f-cutset1={1,4,5,6} \n", "f-cutset2={2,4,5} \n", "f-cutset3={3,4,6}\n", "\n", "Q=\n", "[[ 1 0 0 -1 -1 1]\n", " [ 0 1 0 -1 -1 0]\n", " [ 0 0 1 -1 0 1]]\n", "\n", "The KCL equation in matrix form is given by\n", "\n", "Q.Yb.(Q^T).Vl=Q.Is-Q.Yb.Vs\n", "\n", "Q.Yb.(Q^T).Vl=Q.Is\n", "\n", "yz=\n", "[[ 0.2 0. 0. 0. 0. 0. ]\n", " [ 0. 0.2 0. 0. 0. 0. ]\n", " [ 0. 0. 0.2 0. 0. 0. ]\n", " [ 0. 0. 0. 0.1 0. 0. ]\n", " [ 0. 0. 0. 0. 0.5 0. ]\n", " [ 0. 0. 0. 0. 0. 0.1]]\n", "\n", "Vs=\n", "[[910]\n", " [ 0]\n", " [ 0]\n", " [ 0]\n", " [ 0]\n", " [ 0]]\n", "\n", "Is=\n", "[[0]\n", " [0]\n", " [0]\n", " [0]\n", " [0]\n", " [0]]\n", "\n", "Q.Yb=\n", "[[ 0.2 0. 0. -0.1 -0.5 0.1]\n", " [ 0. 0.2 0. -0.1 -0.5 0. ]\n", " [ 0. 0. 0.2 -0.1 0. 0.1]]\n", "\n", "Q.Yb.Vs=\n", "[[ 182.]\n", " [ 0.]\n", " [ 0.]]\n", "\n", "Q.Is=\n", "[[0]\n", " [0]\n", " [0]]\n", "\n", "Q.Is-Q.Yb.Vs=\n", "[[-182.]\n", " [ 0.]\n", " [ 0.]]\n", "\n", "Load voltages:\n", "[[-460.]\n", " [ 320.]\n", " [ 200.]]\n", "\n", "vl1=-460 V \n", "vl2=320 V \n", "vl3=200 V\n" ] } ], "prompt_number": 9 }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Ex21-pg7.36" ] }, { "cell_type": "code", "collapsed": false, "input": [ "##Graph Theory : example 7.21 :(pg 7.38 & 7.39)\n", "import numpy\n", "from numpy import linalg\n", "print(\"\\ntwigs={1,2} \\nf-cutset1={1,4} \\nf-cutset2={2,3}\");\n", "Q=numpy.matrix([[1, 0, 0 ,-1],[0 ,1 ,-1, 0]]);\n", "print(\"\\nQ=\");\n", "print(Q);\n", "print(\"\\nThe KCL equation in matrix form is given by\");\n", "print(\"\\nQ.Yb.(Q^T).Vl=Q.Is-Q.Yb.Vs\");\n", "ZZ=numpy.matrix.transpose(Q)\n", "\n", "yxx=numpy.array([0.25,0.5,0.25,0.5]);\n", "Yb=numpy.diag(yxx)\n", "Vs=numpy.matrix([[1],[1],[0],[0]]);\n", "Is=numpy.matrix([[0],[0],[0.5],[-0.5]]);\n", "print(\"\\nYb=\");\n", "print(Yb);\n", "print(\"\\n(Q^T)=\");\n", "print(ZZ);\n", "print(\"\\nVs=\");\n", "print(Vs);\n", "print(\"\\nIs=\");\n", "print(Is);\n", "x=numpy.dot(Q,Yb);\n", "print(\"\\nQ.Yb=\");\n", "print(x);\n", "y=numpy.dot(x,ZZ);\n", "print(\"\\nQ.Yb.(Q^T)=\");\n", "print(y);\n", "print(\"\\nQ.Is=\");\n", "u=numpy.dot(Q,Is);\n", "print(Q*Is);\n", "z=numpy.dot(x,Vs);\n", "print(\"\\nQ.Yb.Vs=\");\n", "print(z);\n", "v=(u-z);\n", "print(\"\\nQ.Is-Q.Yb.Vs=\");\n", "print(v);\n", "print(\"\\nLoad voltages:\");\n", "M=([[0.75, 0],[0 ,0.75]]);\n", "P=numpy.linalg.inv(M);\n", "N=([[0.25],[-1]]);\n", "X=numpy.dot(P,N);\n", "print(X);\n", "print(\"\\nvl1=0.33 V \\nvl2=-1.33 V\");\n", "vl2=-1.33;\n", "v=1.+vl2;\n", "print\"%s %.2f %s\"%(\"\\nV=\",v,\"\");\n", "\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "\n", "twigs={1,2} \n", "f-cutset1={1,4} \n", "f-cutset2={2,3}\n", "\n", "Q=\n", "[[ 1 0 0 -1]\n", " [ 0 1 -1 0]]\n", "\n", "The KCL equation in matrix form is given by\n", "\n", "Q.Yb.(Q^T).Vl=Q.Is-Q.Yb.Vs\n", "\n", "Yb=\n", "[[ 0.25 0. 0. 0. ]\n", " [ 0. 0.5 0. 0. ]\n", " [ 0. 0. 0.25 0. ]\n", " [ 0. 0. 0. 0.5 ]]\n", "\n", "(Q^T)=\n", "[[ 1 0]\n", " [ 0 1]\n", " [ 0 -1]\n", " [-1 0]]\n", "\n", "Vs=\n", "[[1]\n", " [1]\n", " [0]\n", " [0]]\n", "\n", "Is=\n", "[[ 0. ]\n", " [ 0. ]\n", " [ 0.5]\n", " [-0.5]]\n", "\n", "Q.Yb=\n", "[[ 0.25 0. 0. -0.5 ]\n", " [ 0. 0.5 -0.25 0. ]]\n", "\n", "Q.Yb.(Q^T)=\n", "[[ 0.75 0. ]\n", " [ 0. 0.75]]\n", "\n", "Q.Is=\n", "[[ 0.5]\n", " [-0.5]]\n", "\n", "Q.Yb.Vs=\n", "[[ 0.25]\n", " [ 0.5 ]]\n", "\n", "Q.Is-Q.Yb.Vs=\n", "[[ 0.25]\n", " [-1. ]]\n", "\n", "Load voltages:\n", "[[ 0.33333333]\n", " [-1.33333333]]\n", "\n", "vl1=0.33 V \n", "vl2=-1.33 V\n", "\n", "V= -0.33 \n" ] } ], "prompt_number": 11 } ], "metadata": {} } ] }