{
 "metadata": {
  "name": "",
  "signature": "sha256:b2b5fb16825d4183b23bc2d431db6308dc6c5888398753fd91beb4d61ab4253a"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter2-Network Theorem 1"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex1-pg2.4"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem-1\n",
      "##pg no.-2.4\n",
      "##example2.1\n",
      "print(\"\\nConverting the two delta networks formed by resistors 4.5 Ohm,  3Ohm, and 7.5Ohm into equivalent star networks\");\n",
      "a=4.5;\n",
      "b=3.;\n",
      "c=7.5;\n",
      "R1= (a*c)/(a+b+c);\n",
      "R2= (c*b)/(c+b+a);\n",
      "R3= (a*b)/(a+b+c);\n",
      "print'%s %.2f %s %.2f %s %.2f %s '%(\"\\nR1=R6 = \",R1,\" Ohm\" and \"\\nR2=R5 =\",R2,\" Ohm\"  and \"\\nR3=R4 =\" ,R3,\" Ohm\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "Converting the two delta networks formed by resistors 4.5 Ohm,  3Ohm, and 7.5Ohm into equivalent star networks\n",
        "\n",
        "R1=R6 =  2.25 \n",
        "R2=R5 = 1.50 \n",
        "R3=R4 = 0.90  Ohm \n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex2-pg2.5"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem-1\n",
      "##pg no.-2.2\n",
      "##example2.5\n",
      "##converting delta network to star network\n",
      "a=10.;\n",
      "b=10.;\n",
      "c=10.;\n",
      "R=(a*b)/(a+b+c);\n",
      "print(\"\\nConverting the delta formed by three resistors of 10 Ohm into an equivalent star network\");\n",
      "print'%s %.2f %s'%(\"\\nR1=R2=R3= \",R,\" Ohm\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "Converting the delta formed by three resistors of 10 Ohm into an equivalent star network\n",
        "\n",
        "R1=R2=R3=  3.33  Ohm\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex3-pg2.7"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem-1\n",
      "##pg no.-2.7\n",
      "##example2.3\n",
      "a=4.;\n",
      "b=3.;\n",
      "c=6.;\n",
      "##star to delta conversion\n",
      "R1=c+a+((a*c)/b);\n",
      "R2=c+b+((c*b)/a);\n",
      "R3=a+b+((a*b)/c);\n",
      "x=1.35;\n",
      "y=0.9;\n",
      "RAB=(c*(x+y))/(c+x+y);\n",
      "print'%s %.2f %s'%(\"\\nR1 = \",R1,\" Ohm\");\n",
      "print'%s %.2f %s'%(\"\\nR2 = \",R2,\" Ohm\");\n",
      "print'%s %.2f %s'%(\"\\nR3 = \",R3,\" Ohm\");\n",
      "print'%s %.2f %s'%(\"\\nThe network can be simplified as, \\nRAB = \",RAB,\" Ohm\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "R1 =  18.00  Ohm\n",
        "\n",
        "R2 =  13.50  Ohm\n",
        "\n",
        "R3 =  9.00  Ohm\n",
        "\n",
        "The network can be simplified as, \n",
        "RAB =  1.64  Ohm\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex5-pg2.9"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem-1\n",
      "##pg no.-2.9\n",
      "##example2.5\n",
      "##converting delta network to star network\n",
      "a=25.;\n",
      "b=20.;\n",
      "c=35.;\n",
      "R1=(b*c)/(a+b+c);\n",
      "R2=(a*b)/(a+b+c);\n",
      "R3=(a*c)/(a+b+c);\n",
      "print(\"\\nConverting the delta formed by resistors 20 Ohm ,25 Ohm, 35 Ohm  into an equivalent star network\");\n",
      "print'%s %.2f %s'%(\"\\nR1= \",R1,\" Ohm\");\n",
      "print'%s %.2f %s'%(\"\\nR2= \",R2,\" Ohm\");\n",
      "print'%s %.2f %s'%(\"\\nR3= \",R3,\" Ohm\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "Converting the delta formed by resistors 20 Ohm ,25 Ohm, 35 Ohm  into an equivalent star network\n",
        "\n",
        "R1=  8.75  Ohm\n",
        "\n",
        "R2=  6.25  Ohm\n",
        "\n",
        "R3=  10.94  Ohm\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex8-pg2.15"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem-1\n",
      "##pg no.-2.15\n",
      "##example2.8\n",
      "a=5;\n",
      "b=4;\n",
      "c=3;\n",
      "##Star to delta conversion\n",
      "R1=a+b+((a*b)/c);\n",
      "R2=c+b+((c*b)/a);\n",
      "R3=a+c+((a*c)/b);\n",
      "a1=6;\n",
      "b1=4;\n",
      "c1=8;\n",
      "##Satr to delta conversion\n",
      "R4=a1+b1+((a1*b1)/c1);\n",
      "R5=c1+b1+((c1*b1)/a1);\n",
      "R6=a1+c1+((a1*c1)/b1);\n",
      "x=6.17;\n",
      "y=9.78;\n",
      "RAB=(x*y)/(x+y);\n",
      "print(\"\\nConverting star network formed by 3 Ohm,4 Ohm ,5 Ohm into equivalent delta network \");\n",
      "print'%s %.2f %s %.2f %s %.2f %s'%(\"\\nR1= \",R1,\" Ohm\" and \" \\nR2= \",R2,\" Ohm\" and \" \\nR3 = \",R3,\" Ohm\");\n",
      "print(\"\\nSimilarly, converting star network formed by 6 Ohm,4 Ohm ,8 Ohm into equivalent delta network\");\n",
      "print'%s %.2f %s %.2f %s %.2f %s '%(\"\\nR4= \",R4,\" Ohm\" and \" \\nR5= \",R5,\" Ohm \" and \"\\nR6 =\",R6,\" Ohm\");\n",
      "print'%s %.2f %s'%(\"\\n Simplifying the parallel networks, we get \\nRAB = \",RAB,\" Ohms\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "Converting star network formed by 3 Ohm,4 Ohm ,5 Ohm into equivalent delta network \n",
        "\n",
        "R1=  15.00  \n",
        "R2=  9.00  \n",
        "R3 =  11.00  Ohm\n",
        "\n",
        "Similarly, converting star network formed by 6 Ohm,4 Ohm ,8 Ohm into equivalent delta network\n",
        "\n",
        "R4=  13.00  \n",
        "R5=  17.00 \n",
        "R6 = 26.00  Ohm \n",
        "\n",
        " Simplifying the parallel networks, we get \n",
        "RAB =  3.78  Ohms\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex9-pg2.18"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.18\n",
      "##example2.9\n",
      "import math\n",
      "import numpy\n",
      "print(\"Applying KVL to mesh 1\");\n",
      "print(\"10*I1-3*I2-6*I3=0\")##equation 1\n",
      "print(\"Applying KVL to mesh 2\");\n",
      "print(\"-3*I1+10*I2=-5\");##equation 2\n",
      "print(\"Applying KVL to mesh 3\");\n",
      "print(\"-6*I1+10*I3=25\");##equation 3\n",
      "print(\"Solving the three equations\");\n",
      "A=numpy.matrix([[10, -3, -6],[-3 ,10 ,0],[-6, 0, 10]])   ##solving the equations in matrix form\n",
      "B=numpy.matrix([[10], [-5], [25]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B)\n",
      "\n",
      "print[X];\n",
      "print(\"I1=4.27 A\");\n",
      "print(\"I2=0.78 A\");\n",
      "print(\"I3=5.06 A\");\n",
      "print(\"I5ohm=4.27 A\");"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Applying KVL to mesh 1\n",
        "10*I1-3*I2-6*I3=0\n",
        "Applying KVL to mesh 2\n",
        "-3*I1+10*I2=-5\n",
        "Applying KVL to mesh 3\n",
        "-6*I1+10*I3=25\n",
        "Solving the three equations\n",
        "[matrix([[ 4.27272727],\n",
        "        [ 0.78181818],\n",
        "        [ 5.06363636]])]\n",
        "I1=4.27 A\n",
        "I2=0.78 A\n",
        "I3=5.06 A\n",
        "I5ohm=4.27 A\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex10-pg2.19"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.19\n",
      "##example 2.10\n",
      "import math\n",
      "import numpy\n",
      "from numpy import linalg\n",
      "print(\"Applying KVL to mesh 1\");\n",
      "print(\"7*I1-I2=10\")##equation 1\n",
      "print(\"Applying KVL to mesh 2\");\n",
      "print(\"-I1+6*I2-3*I3=0\");##equation 2\n",
      "print(\"Applying KVL to mesh 3\");\n",
      "print(\"-3*I2+13*I3=-20\");##equation 3\n",
      "print(\"Solving the three equations\");\n",
      "A=numpy.matrix([[7 ,-1, 0],[-1, 6, -3],[0 ,-3, 13]]);##solving the equations in matrix form\n",
      "B=numpy.matrix([[10], [0], [-20]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "print(\"I1=1.34 A\");\n",
      "print(\"I1=-0.62 A\");\n",
      "print(\"I3=-1.68 A\");\n",
      "print(\"I2ohm=1.34 A\");"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Applying KVL to mesh 1\n",
        "7*I1-I2=10\n",
        "Applying KVL to mesh 2\n",
        "-I1+6*I2-3*I3=0\n",
        "Applying KVL to mesh 3\n",
        "-3*I2+13*I3=-20\n",
        "Solving the three equations\n",
        "[matrix([[ 1.34042553],\n",
        "        [-0.61702128],\n",
        "        [-1.68085106]])]\n",
        "I1=1.34 A\n",
        "I1=-0.62 A\n",
        "I3=-1.68 A\n",
        "I2ohm=1.34 A\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex11-pg2.20"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.20\n",
      "##example 2.11\n",
      "import math\n",
      "import numpy\n",
      "print(\"Applying KVL to mesh 1\");\n",
      "print(\"3*I1-I2-2*I3=8\");##equation 1\n",
      "print(\"Applying KVL to mesh 2\");\n",
      "print(\"-I1+8*I2-3*I3=10\");##equation 2\n",
      "print(\"Applying KVL to mesh 3\");\n",
      "print(\"-2*I1-3*I2+10*I3=12\");##equation 3\n",
      "print(\"Solving the three equations\");\n",
      "A=numpy.matrix([[3 ,-1 ,-2],[-1, 8 ,-3],[-2 ,-3 ,10]]);##solving the equations in matrix form\n",
      "B=numpy.matrix([[8], [10] ,[12]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "print(\"I1=6.01 A\");\n",
      "print(\"I1=3.27 A\");\n",
      "print(\"I3=3.38 A\");\n",
      "print(\"I5ohm=3.38 A\");"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Applying KVL to mesh 1\n",
        "3*I1-I2-2*I3=8\n",
        "Applying KVL to mesh 2\n",
        "-I1+8*I2-3*I3=10\n",
        "Applying KVL to mesh 3\n",
        "-2*I1-3*I2+10*I3=12\n",
        "Solving the three equations\n",
        "[matrix([[ 6.01257862],\n",
        "        [ 3.27044025],\n",
        "        [ 3.3836478 ]])]\n",
        "I1=6.01 A\n",
        "I1=3.27 A\n",
        "I3=3.38 A\n",
        "I5ohm=3.38 A\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex12-pg2.21"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.21\n",
      "##example 2.12\n",
      "import numpy\n",
      "print(\"Applying KVL to mesh 1\");\n",
      "print(\"8*I1-I2-4*I3=4\");##equation 1\n",
      "print(\"Applying KVL to mesh 2\");\n",
      "print(\"-I1+8*I2-5*I3=0\");##equation 2\n",
      "print(\"Applying KVL to mesh 3\");\n",
      "print(\"-4*I1-5*I2+15*I3=0\");##equation 3\n",
      "print(\"Solving the three equations\");\n",
      "A=numpy.matrix([[8 ,-1 ,-4],[-1 ,8 ,-5],[-4 ,-5 ,15]]);##solving the equations in matrix form\n",
      "B=numpy.matrix([[4] ,[0], [0]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "print(\"I1=0.66\");\n",
      "print(\"I1=0.24 A\");\n",
      "print(\"I3=0.26 A\");\n",
      "print(\"current supplied by the battery = 0.66 A\");"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Applying KVL to mesh 1\n",
        "8*I1-I2-4*I3=4\n",
        "Applying KVL to mesh 2\n",
        "-I1+8*I2-5*I3=0\n",
        "Applying KVL to mesh 3\n",
        "-4*I1-5*I2+15*I3=0\n",
        "Solving the three equations\n",
        "[matrix([[ 0.65857886],\n",
        "        [ 0.24263432],\n",
        "        [ 0.25649913]])]\n",
        "I1=0.66\n",
        "I1=0.24 A\n",
        "I3=0.26 A\n",
        "current supplied by the battery = 0.66 A\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex13-pg2.22"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.22\n",
      "##example 2.13\n",
      "import math\n",
      "import numpy\n",
      "print(\"Applying KVL to mesh 1\");\n",
      "print(\"V+13*I1-2*I2-5*I3=20\");##mesh equation 1\n",
      "print(\"Applying KVL to mesh 2\");\n",
      "print(\"2*I1-6*I2+I3=0\");##mesh equation 2\n",
      "print(\"Applying KVL to mesh 3\");\n",
      "print(\"V+5*I1+I2-10*I3=0\");##mesh equation 3\n",
      "print(\"putting I1=0 in equation 1, 2 and 3 we get\"); \n",
      "print(\"V-2*I2-5*I3=20\");##equation 1\n",
      "print(\"-6*I2+I3=0\");##equation 2\n",
      "print(\"V+I2-10*I3=0\");##equation 3\n",
      "print(\"Solving the three equations\");\n",
      "A=numpy.matrix([[1 ,-2 ,-5],[0 ,-6 ,1],[1 ,1 ,-10]]);##solving the equations in matrix form\n",
      "B=numpy.matrix([[20], [0] ,[0]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "print(\"V=43.7 V\")"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Applying KVL to mesh 1\n",
        "V+13*I1-2*I2-5*I3=20\n",
        "Applying KVL to mesh 2\n",
        "2*I1-6*I2+I3=0\n",
        "Applying KVL to mesh 3\n",
        "V+5*I1+I2-10*I3=0\n",
        "putting I1=0 in equation 1, 2 and 3 we get\n",
        "V-2*I2-5*I3=20\n",
        "-6*I2+I3=0\n",
        "V+I2-10*I3=0\n",
        "Solving the three equations\n",
        "[matrix([[ 43.7037037 ],\n",
        "        [  0.74074074],\n",
        "        [  4.44444444]])]\n",
        "V=43.7 V\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex14-pg2.22"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.13\n",
      "##example2.14\n",
      "import math\n",
      "import numpy\n",
      "print(\"Mesh 1 contains a current source of 6A.Hence, we cannot write KVL equation for Mesh 1.direction of current source and mesh current I1 are same,\");\n",
      "print(\"I1=6A\");##equation 1\n",
      "print(\"Applying KVL to mesh 2\");\n",
      "print(\"18*I2-6*I3=108\");##equation 2\n",
      "print(\"Applying KVL to mesh 3\");\n",
      "print(\"6*I2-11*I3=9\");##equation 3\n",
      "print(\"Solving the three equations\");\n",
      "A=numpy.matrix([[18, -6],[6 ,-11]])##solving the equations in matrix form\n",
      "B=numpy.matrix([[108] ,[9]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "print(\"I3 = 3A\");\n",
      "print(\"I2ohm = 3A\");"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Mesh 1 contains a current source of 6A.Hence, we cannot write KVL equation for Mesh 1.direction of current source and mesh current I1 are same,\n",
        "I1=6A\n",
        "Applying KVL to mesh 2\n",
        "18*I2-6*I3=108\n",
        "Applying KVL to mesh 3\n",
        "6*I2-11*I3=9\n",
        "Solving the three equations\n",
        "[matrix([[ 7.],\n",
        "        [ 3.]])]\n",
        "I3 = 3A\n",
        "I2ohm = 3A\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex15-pg2.23"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.23\n",
      "##example2.15\n",
      "print(\"from the fig,\");\n",
      "print(\"IA=I1\");##equation 1\n",
      "print(\"IB=I2\");##equation 2\n",
      "print(\"Applying Kvl to mesh 1:\");\n",
      "print(\"5-5*I1-10*IB-10*(I1-I2)-5*IA=0\");\n",
      "print(\"5-5*I1-10*I2-10*I1+10*I2-5*I1=0\");\n",
      "print(\"-20*I1=-5\");\n",
      "I1=5./20.;\n",
      "print'%s %.2f %s'%(\"I1= \",I1,\" A\");##equation 3\n",
      "print(\"Applying Kvl to mesh 2:\");\n",
      "print(\"15*I1-15*I2=10\");##equation 4\n",
      "print(\"Put I1=0.25 A in equation 4\");\n",
      "print(\"-6.25=15*I2\");\n",
      "I2=-6.25/15.;\n",
      "print'%s %.2f %s '%(\"I2= \",I2,\" A\");"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "from the fig,\n",
        "IA=I1\n",
        "IB=I2\n",
        "Applying Kvl to mesh 1:\n",
        "5-5*I1-10*IB-10*(I1-I2)-5*IA=0\n",
        "5-5*I1-10*I2-10*I1+10*I2-5*I1=0\n",
        "-20*I1=-5\n",
        "I1=  0.25  A\n",
        "Applying Kvl to mesh 2:\n",
        "15*I1-15*I2=10\n",
        "Put I1=0.25 A in equation 4\n",
        "-6.25=15*I2\n",
        "I2=  -0.42  A \n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex17-pg2.24"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.25\n",
      "##example2.17\n",
      "import math\n",
      "import numpy\n",
      "print(\"from the fig,\");\n",
      "print(\"V1=-5*I1\");##equation 1\n",
      "print(\"V2=2*I2\");##equation 2\n",
      "print(\"Applying Kvl to mesh 1:\");\n",
      "print(\"20*I1+3*I2=-5\");##equation 3\n",
      "print(\"Applying Kvl to mesh 2:\");\n",
      "print(\"11*I1-3*I2=10\");##equation 4\n",
      "print(\"Solving equations 3 and 4\");##solving equations in matrix form\n",
      "A=numpy.matrix([[20, 3],[11, -3]]);\n",
      "B=numpy.matrix([[-5], [10]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "print(\"I1=0.161 A\");\n",
      "print(\"I2=-2.742 A\");"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "from the fig,\n",
        "V1=-5*I1\n",
        "V2=2*I2\n",
        "Applying Kvl to mesh 1:\n",
        "20*I1+3*I2=-5\n",
        "Applying Kvl to mesh 2:\n",
        "11*I1-3*I2=10\n",
        "Solving equations 3 and 4\n",
        "[matrix([[ 0.16129032],\n",
        "        [-2.74193548]])]\n",
        "I1=0.161 A\n",
        "I2=-2.742 A\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex18-pg2.25"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem-1\n",
      "##pg no.-2.25\n",
      "##example2.18\n",
      "import numpy\n",
      "print(\"from the fig,\");\n",
      "print(\"Iy=I1\");##equation 1\n",
      "print(\"Ix=I1-I2\");##equation 2\n",
      "print(\"Applying Kvl to mesh 1:\");\n",
      "print(\"-10*I1+3*I2=5\");##equation 3\n",
      "print(\"Applying Kvl to mesh 2:\");\n",
      "print(\"-I1-3*I2=10\");##equation 4\n",
      "print(\"Solving equations 3 and 4\");##solving equations in matrix form\n",
      "A=numpy.matrix([[-10 ,3],[-1, -3]]);\n",
      "B=numpy.matrix([[5] ,[10]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "print(\"I1=-1.364 A\");\n",
      "print(\"I2=-2878 A\");\n",
      "x=-1.364;\n",
      "y=-2.878;\n",
      "Ix=x-y;\n",
      "print'%s %.2f %s %.2f %s '%(\"\\nIy = \",x,\" A\" and \" \\nIx = \",Ix,\" A\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "from the fig,\n",
        "Iy=I1\n",
        "Ix=I1-I2\n",
        "Applying Kvl to mesh 1:\n",
        "-10*I1+3*I2=5\n",
        "Applying Kvl to mesh 2:\n",
        "-I1-3*I2=10\n",
        "Solving equations 3 and 4\n",
        "[matrix([[-1.36363636],\n",
        "        [-2.87878788]])]\n",
        "I1=-1.364 A\n",
        "I2=-2878 A\n",
        "\n",
        "Iy =  -1.36  \n",
        "Ix =  1.51  A \n"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex19-pg2.26"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.26\n",
      "##example2.19\n",
      "import math\n",
      "import numpy\n",
      "print(\"Applying KVL to mesh 1:\");\n",
      "print(\"11*I1-10*I2=2\");##equation 1\n",
      "print(\"Writing current equation to supermesh:\")\n",
      "print(\"I3-I2=4\");##equation 2\n",
      "print(\"Applying KVL to outer path of supermesh:\");\n",
      "print(\"2*I1-3*I2-3*I3=0\");##equation 3\n",
      "print(\"solving these equations we get :\");##solving equations in matrix form\n",
      "A=numpy.matrix([[11, -10, 0],[0 ,-1 ,1],[2 ,-3, -3]]);\n",
      "B=numpy.matrix([[2] ,[4] ,[0]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "I1=-2.35\n",
      "I2=-2.78\n",
      "I3=1.22\n",
      "I4=I1-I2;\n",
      "print'%s %.2f %s'%(\"\\ncurrent through the 10 ohm resistor = I1-I2 = \",I4,\" A\");"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Applying KVL to mesh 1:\n",
        "11*I1-10*I2=2\n",
        "Writing current equation to supermesh:\n",
        "I3-I2=4\n",
        "Applying KVL to outer path of supermesh:\n",
        "2*I1-3*I2-3*I3=0\n",
        "solving these equations we get :\n",
        "[matrix([[-2.34782609],\n",
        "        [-2.7826087 ],\n",
        "        [ 1.2173913 ]])]\n",
        "\n",
        "current through the 10 ohm resistor = I1-I2 =  0.43  A\n"
       ]
      }
     ],
     "prompt_number": 17
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex20-pg2.26"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.26\n",
      "##example2.20\n",
      "import math\n",
      "import numpy\n",
      "print(\"writing equation for supermesh,\");\n",
      "print(\"I1-I3=7\");##equation 1\n",
      "print(\"Applying Kvl to the outer path of the supermesh:\");\n",
      "print(\"-I1+4*I2-4*I3 = -7\");##equation 2\n",
      "print(\"Applying Kvl to mesh 2:\");\n",
      "print(\"I1-6*I2+3*I3 = 0\");##equation 3\n",
      "print(\"Solving equations 1 ,2 and 3\");##solving equations in matrix form\n",
      "A=numpy.matrix([[1 ,0 ,-1],[-1 ,4 ,-4],[1 ,-6 ,3]]);\n",
      "B=numpy.matrix([[7], [-7], [0]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "print(\"I1=9 A\");\n",
      "print(\"I2=-2.5 A\");\n",
      "print(\"I3=-2 A\");\n",
      "x=2.5;\n",
      "y=2;\n",
      "z=x-y;\n",
      "print'%s %.2f %s'%(\"\\nCurrent through the 3-Ohm resistor = I2-I3 =\",z,\" A\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "writing equation for supermesh,\n",
        "I1-I3=7\n",
        "Applying Kvl to the outer path of the supermesh:\n",
        "-I1+4*I2-4*I3 = -7\n",
        "Applying Kvl to mesh 2:\n",
        "I1-6*I2+3*I3 = 0\n",
        "Solving equations 1 ,2 and 3\n",
        "[matrix([[ 9. ],\n",
        "        [ 2.5],\n",
        "        [ 2. ]])]\n",
        "I1=9 A\n",
        "I2=-2.5 A\n",
        "I3=-2 A\n",
        "\n",
        "Current through the 3-Ohm resistor = I2-I3 = 0.50  A\n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex21-pg2.27"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.27\n",
      "##example2.21\n",
      "import math\n",
      "import numpy\n",
      "print(\"Applying KVL to mesh 1:\");\n",
      "print(\"15*I1-10*I2-5*I3=50\");##equation 1\n",
      "print(\"Writing current equation to supermesh:\")\n",
      "print(\"I2-I3=2 A\");##equation 2\n",
      "print(\"Applying KVL to outer path of supermesh:\");\n",
      "print(\"-15*I1+12*I2+6*I3=0\");##equation 3\n",
      "print(\"solving these equations we get :\");##solving equations in matrix form\n",
      "A=numpy.matrix([[15, -10, -5],[0 ,1 ,-1],[-15, 12, 6]]);\n",
      "B=numpy.matrix([[50] ,[2] ,[0]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "I1=20.\n",
      "I2=17.33\n",
      "I3=15.33\n",
      "I4=I1-I3;\n",
      "print'%s %.2f %s'%(\"\\ncurrent through the 5 ohm resistor = I1-I3 = \",I4,\" A\");"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Applying KVL to mesh 1:\n",
        "15*I1-10*I2-5*I3=50\n",
        "Writing current equation to supermesh:\n",
        "I2-I3=2 A\n",
        "Applying KVL to outer path of supermesh:\n",
        "-15*I1+12*I2+6*I3=0\n",
        "solving these equations we get :\n",
        "[matrix([[ 20.        ],\n",
        "        [ 17.33333333],\n",
        "        [ 15.33333333]])]\n",
        "\n",
        "current through the 5 ohm resistor = I1-I3 =  4.67  A\n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex22-pg2.28"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.28\n",
      "##example2.22\n",
      "import math\n",
      "import numpy\n",
      "print(\"from the fig,\");\n",
      "print(\"I4=40\");##equation 1\n",
      "print(\"\\nmeshes 2 and 3 form a supermesh. current equation for supermesh,\")\n",
      "print(\"-I1+2*I2-I3 = 0\");##equation 2\n",
      "print(\"Applying Kvl to supermesh:\");\n",
      "print(\"-1/5(I2-I1)-1/20*I2-1/15*I3-1/2(I3-I4)=0\");##equation 3\n",
      "print(\"applying KVL to mesh 1\");\n",
      "print(\"-1/10*I1-1/5(I1-I2)-1/6(I1-I4)=6\");##equation 4\n",
      "print(\"Solving equations 1 ,2 ,3 and 4\");##solving equations in matrix form\n",
      "A=numpy.matrix([[0 ,0 ,0 ,1],[-1, 2 ,-1 ,0],[0.2, -0.25, -17/30, 0.5],[-7/15, 0.2, 0 ,1/6]]);\n",
      "B=numpy.matrix([[40], [0] ,[0], [6]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "print(\"I1=10 A\");\n",
      "print(\"I2=-20 A\");\n",
      "print(\"I3=30 A\");\n",
      "print(\"I4=40 A\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "from the fig,\n",
        "I4=40\n",
        "\n",
        "meshes 2 and 3 form a supermesh. current equation for supermesh,\n",
        "-I1+2*I2-I3 = 0\n",
        "Applying Kvl to supermesh:\n",
        "-1/5(I2-I1)-1/20*I2-1/15*I3-1/2(I3-I4)=0\n",
        "applying KVL to mesh 1\n",
        "-1/10*I1-1/5(I1-I2)-1/6(I1-I4)=6\n",
        "Solving equations 1 ,2 ,3 and 4\n",
        "[matrix([[ -4.72636816],\n",
        "        [  6.3681592 ],\n",
        "        [ 17.46268657],\n",
        "        [ 40.        ]])]\n",
        "I1=10 A\n",
        "I2=-20 A\n",
        "I3=30 A\n",
        "I4=40 A\n"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex24-pg2.29"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.29\n",
      "import numpy\n",
      "##example2.24\n",
      "print(\"Applying KCL to node 1:\");\n",
      "print(\"2*V1-V2 = 2\");##equation 1\n",
      "print(\"Applying KCL to node 2:\");\n",
      "print(\"3*V2-V1 = 4\");##equation 2\n",
      "print(\"Solving equations 1 and 2\");##solving equations in matrix form\n",
      "A=([[2 ,-1],[-1 ,3]]);\n",
      "B=([[2] ,[4]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "print(\"V1= 2 V\");\n",
      "print(\"V2=-2 V\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Applying KCL to node 1:\n",
        "2*V1-V2 = 2\n",
        "Applying KCL to node 2:\n",
        "3*V2-V1 = 4\n",
        "Solving equations 1 and 2\n",
        "[array([[ 2.],\n",
        "       [ 2.]])]\n",
        "V1= 2 V\n",
        "V2=-2 V\n"
       ]
      }
     ],
     "prompt_number": 21
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex25-pg2.30"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.30\n",
      "##example2.25\n",
      "import numpy\n",
      "print(\"Applying KCL to node 1:\");\n",
      "print(\"8*VA-2*VB = 50\");##equation 1\n",
      "print(\"Applying KCL to node 2:\");\n",
      "print(\"-3*VA+9*VB = 85\");##equation 2\n",
      "print(\"Solving equations 1 and 2\");##solving equations in matrix form\n",
      "A=([[8 ,-2],[-3 ,9]]);\n",
      "B=([[50], [85]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "print(\"VA= 9.39 V\");\n",
      "print(\"VB= 12.58 V\");\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Applying KCL to node 1:\n",
        "8*VA-2*VB = 50\n",
        "Applying KCL to node 2:\n",
        "-3*VA+9*VB = 85\n",
        "Solving equations 1 and 2\n",
        "[array([[  9.39393939],\n",
        "       [ 12.57575758]])]\n",
        "VA= 9.39 V\n",
        "VB= 12.58 V\n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex26-pg2.30"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.30\n",
      "import numpy\n",
      "##example2.26\n",
      "print(\"Applying KCL to node 1:\");\n",
      "print(\"5*V1-2*V2 = -24\");##equation 1\n",
      "print(\"Applying KCL to node 2:\");\n",
      "print(\"10*V1-31*V2+6*V3 = 300\");##equation 2\n",
      "print(\"Applying KCL to node 3:\");\n",
      "print(\"-4*V2 +9*V3 = 160\");##equation 3\n",
      "print(\"Solving equations 1,2 and 3\");##solving equations in matrix form\n",
      "A=([[5, -2 ,0],[10, -31, 6],[0, -4, 9]]);\n",
      "B=([[-24] ,[300] ,[160]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "print(\"V1= -8.77 V\");\n",
      "print(\"V2= -9.92 V\");\n",
      "print(\"V3= 13.37 V\");\n",
      "x=13.37;\n",
      "y=-9.92;\n",
      "z=(x-y)/5.;\n",
      "print'%s %.2f %s'%(\"\\ncurrent through the 5 ohm resistor = V3-V2/5 = \",z,\" A\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Applying KCL to node 1:\n",
        "5*V1-2*V2 = -24\n",
        "Applying KCL to node 2:\n",
        "10*V1-31*V2+6*V3 = 300\n",
        "Applying KCL to node 3:\n",
        "-4*V2 +9*V3 = 160\n",
        "Solving equations 1,2 and 3\n",
        "[array([[ -8.76712329],\n",
        "       [ -9.91780822],\n",
        "       [ 13.36986301]])]\n",
        "V1= -8.77 V\n",
        "V2= -9.92 V\n",
        "V3= 13.37 V\n",
        "\n",
        "current through the 5 ohm resistor = V3-V2/5 =  4.66  A\n"
       ]
      }
     ],
     "prompt_number": 24
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex27-pg2.31"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.31\n",
      "##example2.27\n",
      "import numpy\n",
      "print(\"Applying KCL to node 1:\");\n",
      "print(\"50*V1-20*V2 = 2400\");##equation 1\n",
      "print(\"Applying KCL to node 2:\");\n",
      "print(\"-10*V1+19*V2 = 240\");##equation 2\n",
      "print(\"Solving equations 1 and 2\");##solving equations in matrix form\n",
      "A=([[50, -20],[-10, 19]]);\n",
      "B=([[2400] ,[240]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "print(\"V1= 67.2 V\");\n",
      "print(\"V2=-48 V\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Applying KCL to node 1:\n",
        "50*V1-20*V2 = 2400\n",
        "Applying KCL to node 2:\n",
        "-10*V1+19*V2 = 240\n",
        "Solving equations 1 and 2\n",
        "[array([[ 67.2],\n",
        "       [ 48. ]])]\n",
        "V1= 67.2 V\n",
        "V2=-48 V\n"
       ]
      }
     ],
     "prompt_number": 25
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex28-pg2.32"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.32\n",
      "##example2.28\n",
      "import numpy\n",
      "print(\"Applying KCL to node 1:\");\n",
      "print(\"4*VA-2*VB = 5\");##equation 1\n",
      "print(\"Applying KCL to node 2:\");\n",
      "print(\"-2*VA+3*VB = 4\");##equation 2\n",
      "print(\"Solving equations 1 and 2\");##solving equations in matrix form\n",
      "A=([[4, -2],[-2 ,3]]);\n",
      "B=([[5], [4]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "\n",
      "print(X);\n",
      "print(\"VA= 2.88 V\");\n",
      "print(\"VB= 3.25 V\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Applying KCL to node 1:\n",
        "4*VA-2*VB = 5\n",
        "Applying KCL to node 2:\n",
        "-2*VA+3*VB = 4\n",
        "Solving equations 1 and 2\n",
        "[[ 2.875]\n",
        " [ 3.25 ]]"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "VA= 2.88 V\n",
        "VB= 3.25 V\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex29-pg2.33"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import numpy\n",
      "##Network Theorem 1\n",
      "##page no-2.33\n",
      "##example2.29\n",
      "print(\"Applying KCL to node 1:\");\n",
      "print(\"4*V1-2*V2-V3 = -24\");##equation 1\n",
      "print(\"Applying KCL to node 2:\");\n",
      "print(\"-50*V1+71*V2-20*V3 = 0\");##equation 2\n",
      "print(\"Applying KCL to node 3:\");\n",
      "print(\"-5V1-4*V2 +10*V3 = 180\");##equation 3\n",
      "print(\"Solving equations 1,2 and 3\");##solving equations in matrix form\n",
      "A=numpy.matrix([[4, -2, -1],[-50 ,71 ,-20],[-5, -4 ,10]]);\n",
      "B=numpy.matrix([[-24], [0], [180]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "print(\"V1= 6.35 V\");\n",
      "print(\"V2= 11.76 V\");\n",
      "print(\"V3= 25.88 V\");\n",
      "x=25.88;\n",
      "y=11.76;\n",
      "z=(x-y);\n",
      "print'%s %.2f %s'%(\"\\ncurrent through the 5 ohm resistor = V3-V2/5 = \",z,\" A\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Applying KCL to node 1:\n",
        "4*V1-2*V2-V3 = -24\n",
        "Applying KCL to node 2:\n",
        "-50*V1+71*V2-20*V3 = 0\n",
        "Applying KCL to node 3:\n",
        "-5V1-4*V2 +10*V3 = 180\n",
        "Solving equations 1,2 and 3\n",
        "[matrix([[  6.35294118],\n",
        "        [ 11.76470588],\n",
        "        [ 25.88235294]])]\n",
        "V1= 6.35 V\n",
        "V2= 11.76 V\n",
        "V3= 25.88 V\n",
        "\n",
        "current through the 5 ohm resistor = V3-V2/5 =  14.12  A\n"
       ]
      }
     ],
     "prompt_number": 27
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex30-pg2.34"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.34\n",
      "##example2.30\n",
      "import numpy\n",
      "print(\"Applying KCL to node 1:\");\n",
      "print(\"8*V1-V2 = 50\");##equation 1\n",
      "print(\"Applying KCL to node 2:\");\n",
      "print(\"-2*V1+11*V2 = -500\");##equation 2\n",
      "print(\"Solving equations 1 and 2\");##solving equations in matrix form\n",
      "A=([[8, -1],[-2, 17]]);\n",
      "B=([[50] ,[-500]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "print(\"V1= 2.61 V\");\n",
      "print(\"V2=-29.1 V\");\n",
      "x=2.61;\n",
      "y=-29.1;\n",
      "I1=-x/2.;\n",
      "I2=(x-y)/10.;##current through 10 Ohm resistor\n",
      "I3=(y+50)/2.;##50 volts is the supply to the circuit\n",
      "print'%s %.2f %s %.2f %s %.2f %s '%(\"\\nI1= \",I1,\" A\" and  \"\\nI2= \",I2,\"A\" and \" \\nI3= \",I3,\" A\");\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Applying KCL to node 1:\n",
        "8*V1-V2 = 50\n",
        "Applying KCL to node 2:\n",
        "-2*V1+11*V2 = -500\n",
        "Solving equations 1 and 2\n",
        "[array([[  2.6119403 ],\n",
        "       [-29.10447761]])]\n",
        "V1= 2.61 V\n",
        "V2=-29.1 V\n",
        "\n",
        "I1=  -1.30 \n",
        "I2=  3.17  \n",
        "I3=  10.45  A \n"
       ]
      }
     ],
     "prompt_number": 28
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex31-pg2.34"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.34\n",
      "##example2.31\n",
      "import numpy\n",
      "print(\"Applying KCL to node a:\");\n",
      "print(\"0.5*Va-0.2*Vb = 34.2\");#equation 1\n",
      "print(\"Applying KCL to node b:\");\n",
      "print(\"0.1*Va-0.4*Vb = -32.4\");##equation 2\n",
      "print(\"Solving equations 1 and 2\");##solving equations in matrix form\n",
      "A=numpy.matrix([[0.5,0.2],[0.1, -0.4]]);\n",
      "B=numpy.matrix([[34.2], [-32.4]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "print(\"Va= 112 V\");\n",
      "print(\"Vb= 109 V\");\n",
      "x=112.;\n",
      "y=109.;\n",
      "I1=(120.-x)/0.2;\n",
      "I2=(x-y)/0.3;\n",
      "I3=(110-y)/0.1;\n",
      "print'%s %.2f %s %.2f %s %.2f %s '%(\"\\nI1=\",I1,\" A \" and \"\\nI2= \",I2,\" A\" and \" \\nI3= \",I3,\" A\");\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Applying KCL to node a:\n",
        "0.5*Va-0.2*Vb = 34.2\n",
        "Applying KCL to node b:\n",
        "0.1*Va-0.4*Vb = -32.4\n",
        "Solving equations 1 and 2\n",
        "[matrix([[ 32.72727273],\n",
        "        [ 89.18181818]])]\n",
        "Va= 112 V\n",
        "Vb= 109 V\n",
        "\n",
        "I1= 40.00 \n",
        "I2=  10.00  \n",
        "I3=  10.00  A \n"
       ]
      }
     ],
     "prompt_number": 29
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex32-pg2.35"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.35\n",
      "##example2.35\n",
      "import numpy\n",
      "print(\"Applying KCL to node 1:\");\n",
      "print(\"V1 = 50\");##equation 1\n",
      "print(\"Applying KCL to node 2:\");\n",
      "print(\"-2*V1+17*V2 = 50\");#equation 2\n",
      "print(\"Solving equations 1 and 2\");##solving equations in matrix form\n",
      "A=([[1, 0],[-2, 17]]);\n",
      "B=([[50] ,[50]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "print(\"V1= 50 V\");\n",
      "print(\"V2= 8.82 V\");\n",
      "x=8.82;\n",
      "y=(x/10.);\n",
      "print'%s %.2f %s'%(\"\\ncurrent in the 10-Ohm resistor =V2/10 =\",y,\" A\");\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Applying KCL to node 1:\n",
        "V1 = 50\n",
        "Applying KCL to node 2:\n",
        "-2*V1+17*V2 = 50\n",
        "Solving equations 1 and 2\n",
        "[array([[ 50.        ],\n",
        "       [  8.82352941]])]\n",
        "V1= 50 V\n",
        "V2= 8.82 V\n",
        "\n",
        "current in the 10-Ohm resistor =V2/10 = 0.88  A\n"
       ]
      }
     ],
     "prompt_number": 35
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex33-pg2.36"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.36\n",
      "##example2.33\n",
      "import numpy\n",
      "print(\"Applying KCL to node a:\");\n",
      "print(\"6*Va-5*Vb = -20\");##equation 1\n",
      "print(\"Applying KCL to node b:\");\n",
      "print(\"-10*Va+17*Vb-5*Vc = 0\");##equation 2\n",
      "print(\"At node c\");\n",
      "print(\"Vc = 20\");\n",
      "print(\"Solving equations 1,2 and 3\");##solving equations in matrix form\n",
      "A=numpy.matrix([[6 ,-5 ,0],[-10 ,17 ,-5],[0, 0, 1]]);\n",
      "B=numpy.matrix([[-20], [0] ,[20]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "print(\"Va= 3.08 V\");\n",
      "print(\"Vb= 7.69 V\");\n",
      "x=3.08;\n",
      "y=7.69;\n",
      "z=20.;\n",
      "Va = x-y;\n",
      "Vb = y-z;\n",
      "print'%s %.2f %s %.2f %s '%(\"\\nV1 = Va-Vb =  \",Va,\"V\" and \"\\nV2 = Vb-Vc = \",Vb,\" V\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Applying KCL to node a:\n",
        "6*Va-5*Vb = -20\n",
        "Applying KCL to node b:\n",
        "-10*Va+17*Vb-5*Vc = 0\n",
        "At node c\n",
        "Vc = 20\n",
        "Solving equations 1,2 and 3\n",
        "[matrix([[  3.07692308],\n",
        "        [  7.69230769],\n",
        "        [ 20.        ]])]\n",
        "Va= 3.08 V\n",
        "Vb= 7.69 V\n",
        "\n",
        "V1 = Va-Vb =   -4.61 \n",
        "V2 = Vb-Vc =  -12.31  V \n"
       ]
      }
     ],
     "prompt_number": 33
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex34-pg2.37"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.37\n",
      "##example2.334\n",
      "import math\n",
      "import numpy\n",
      "print(\"At node A:\");\n",
      "print(\"VA = 60\");##equation 1\n",
      "print(\"Applying KCL to node B:\");\n",
      "print(\"-VA+3*VB-VC = 12\");##equation 2\n",
      "print(\"Applying KCL to node C:\");\n",
      "print(\"-2*VA-5*VB+10*VC\");##equation 3\n",
      "print(\"Solving equations 1,2 and 3\");##solving equations in matrix \n",
      "A=numpy.matrix([[1 ,0 ,0],[-1 ,3 ,-1],[-2 ,-5 ,10]]);\n",
      "B=numpy.matrix([[60], [12], [24]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B)\n",
      "print[X];\n",
      "print(\"VC= 31.68 V\");\n",
      "print(\"Voltage across the 100 Ohm resistor = 31.68 V\");\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "At node A:\n",
        "VA = 60\n",
        "Applying KCL to node B:\n",
        "-VA+3*VB-VC = 12\n",
        "Applying KCL to node C:\n",
        "-2*VA-5*VB+10*VC\n",
        "Solving equations 1,2 and 3\n",
        "[matrix([[ 60.  ],\n",
        "        [ 34.56],\n",
        "        [ 31.68]])]\n",
        "VC= 31.68 V\n",
        "Voltage across the 100 Ohm resistor = 31.68 V\n"
       ]
      }
     ],
     "prompt_number": 32
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex35-pg2.38"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.38\n",
      "##example2.35\n",
      "import math\n",
      "import numpy\n",
      "print(\"Applying KCL to node 1:\");\n",
      "print(\"2.5*V1-0.5*V2 = 5\");##equation 1\n",
      "print(\"Applying KCL to node 2:\");\n",
      "print(\"V1-V2 = 0\");##equation 2\n",
      "print(\"Solving equations 1 and 2\");##solving equations in matrix form\n",
      "A=numpy.matrix([[2.5, -0.5],[1 ,-1]]);\n",
      "B=numpy.matrix([[5] ,[0]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B);\n",
      "print[X];\n",
      "print(\"V1= 2.5 V\");\n",
      "print(\"V2=-2.5 V\");\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Applying KCL to node 1:\n",
        "2.5*V1-0.5*V2 = 5\n",
        "Applying KCL to node 2:\n",
        "V1-V2 = 0\n",
        "Solving equations 1 and 2\n",
        "[matrix([[ 2.5],\n",
        "        [ 2.5]])]\n",
        "V1= 2.5 V\n",
        "V2=-2.5 V\n"
       ]
      }
     ],
     "prompt_number": 31
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex37-pg2.39"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.39\n",
      "##example2.37\\\n",
      "import math\n",
      "import numpy\n",
      "print(\"Applying KCL to node 1:\");\n",
      "print(\"2*V1+17*V2 = 0\")##equation 1\n",
      "print(\"Applying KCL to node 2:\");\n",
      "print(\"V1+6V2 = 0\");##equation 2\n",
      "print(\"Solving equations 1 and 2\")##solving equations in matrix form\n",
      "A=numpy.matrix([[2 ,17],[1, 6]]);\n",
      "B=numpy.matrix([[0], [0]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B)\n",
      "print(X);\n",
      "print(\"V1= 0 V\");\n",
      "print(\"V2= 0 V\");\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Applying KCL to node 1:\n",
        "2*V1+17*V2 = 0\n",
        "Applying KCL to node 2:\n",
        "V1+6V2 = 0\n",
        "Solving equations 1 and 2\n",
        "[[ 0.]\n",
        " [ 0.]]\n",
        "V1= 0 V\n",
        "V2= 0 V\n"
       ]
      }
     ],
     "prompt_number": 30
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex38-pg2.40"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.40\n",
      "##example2.38\n",
      "import numpy\n",
      "import math\n",
      "print(\"Applying KCL to node a:\");\n",
      "print(\"2*Va-0.5*Vb-0.5*Vc = 5\");##equation 1\n",
      "print(\"Applying KCL to node b:\");\n",
      "print(\"-3/2*Va+5/6*Vb+2/3*Vc = -1\");##equation 2\n",
      "print(\"Applying KCL to node c:\");\n",
      "print(\"1/2*Va+1/3*Vb-31/30*Vc = -1\");##equation 3\n",
      "print(\"Solving equations 1,2 and 3\");##solving equations in matrix form\n",
      "A=numpy.matrix([[2, -0.5, -0.5],[-3/2, 5/6, 2/3],[0.5 ,1/3 ,-31/30 ]]);\n",
      "B=numpy.matrix([[5], [-1], [0]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B)\n",
      "print[X];\n",
      "\n",
      "print(\"Va= 4.303 V\");\n",
      "print(\"Vb= 3.87 V\");\n",
      "print(\"Vc= 3.33 V\");\n",
      "\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Applying KCL to node a:\n",
        "2*Va-0.5*Vb-0.5*Vc = 5\n",
        "Applying KCL to node b:\n",
        "-3/2*Va+5/6*Vb+2/3*Vc = -1\n",
        "Applying KCL to node c:\n",
        "1/2*Va+1/3*Vb-31/30*Vc = -1\n",
        "Solving equations 1,2 and 3\n",
        "[matrix([[ 0.5  ],\n",
        "        [-8.125],\n",
        "        [ 0.125]])]"
       ]
      },
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "\n",
        "Va= 4.303 V\n",
        "Vb= 3.87 V\n",
        "Vc= 3.33 V\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex39-pg2.41"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.41\n",
      "##example2.39\n",
      "import math\n",
      "import numpy\n",
      "print(\"from the figure\");\n",
      "print(\"V4= 40 V\");##equation 1\n",
      "print(\"nodes 2 and 3 form suoernode:\");\n",
      "print(\"V1-2*V2+V3 = 0\");##equation 2\n",
      "print(\"Applying KCL to node 1:\");\n",
      "print(\"7/15*V1-1/5*V2 = 2/3\");##equation 3\n",
      "print(\"Applying KCL to supernode :\");\n",
      "print(\"-23/30*V1 +83/60*V3 = 20\");##equation 4\n",
      "print(\"Solving equations 1,2,3 and 4\");##solving equations in matrix form\n",
      "A=numpy.matrix([[0, 0 ,0 ,1],[1 ,-2 ,1 ,0],[7/15 ,-1/5, 0, 0],[-23/30, 83/60, 0 ,0]]);\n",
      "B=numpy.matrix([[40] ,[0], [2/3], [20]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B)\n",
      "print[X];\n",
      "print(\"V1= 10 V\");\n",
      "print(\"V2= 20 V\");\n",
      "print(\"V3= 30 V\");\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "from the figure\n",
        "V4= 40 V\n",
        "nodes 2 and 3 form suoernode:\n",
        "V1-2*V2+V3 = 0\n",
        "Applying KCL to node 1:\n",
        "7/15*V1-1/5*V2 = 2/3\n",
        "Applying KCL to supernode :\n",
        "-23/30*V1 +83/60*V3 = 20\n",
        "Solving equations 1,2,3 and 4\n",
        "[matrix([[-20.],\n",
        "        [  0.],\n",
        "        [ 20.],\n",
        "        [ 40.]])]\n",
        "V1= 10 V\n",
        "V2= 20 V\n",
        "V3= 30 V\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Ex40-pg2.42"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "##Network Theorem 1\n",
      "##page no-2.42\n",
      "##example2.40\n",
      "import math\n",
      "import numpy\n",
      "print(\"selecting central node as reference node\");\n",
      "print(\"V1= -12 V\");##equation 1\n",
      "print(\"Applying KCL at node 1:\");\n",
      "print(\"-2*V1+2.5*V2-0.5V3 = 14\");##equation 2\n",
      "print(\"nodes 3 and 4 form a supernode\");\n",
      "print(\"0.2*V1+V3-1.2*V4 = 0\");##equation 3\n",
      "print(\"Applying KCL to supernode :\");\n",
      "print(\"0.1*V1-V2+0.5*V3+1.4*V4 = 0\");##equation 4\n",
      "print(\"Solving equations 1,2,3 and 4\");##solving equations in matrix form\n",
      "A=numpy.matrix([[1, 0, 0 ,0],[-2 ,2.5 ,-0.5 ,0],[0.2 ,0 ,1, -1.2],[0.1 ,-1 ,0.5, 1.4]]);\n",
      "B=numpy.matrix([[-12], [14] ,[0],[0]])\n",
      "X=numpy.dot(numpy.linalg.inv(A),B)\n",
      "print[X];\n",
      "print(\"V1= -12 V\");\n",
      "print(\"V2= -4 V\");\n",
      "print(\"V3= 0\");\n",
      "print(\"V4= -2 V\");\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "selecting central node as reference node\n",
        "V1= -12 V\n",
        "Applying KCL at node 1:\n",
        "-2*V1+2.5*V2-0.5V3 = 14\n",
        "nodes 3 and 4 form a supernode\n",
        "0.2*V1+V3-1.2*V4 = 0\n",
        "Applying KCL to supernode :\n",
        "0.1*V1-V2+0.5*V3+1.4*V4 = 0\n",
        "Solving equations 1,2,3 and 4\n",
        "[matrix([[ -1.20000000e+01],\n",
        "        [ -4.00000000e+00],\n",
        "        [  4.44089210e-16],\n",
        "        [ -2.00000000e+00]])]\n",
        "V1= -12 V\n",
        "V2= -4 V\n",
        "V3= 0\n",
        "V4= -2 V\n"
       ]
      }
     ],
     "prompt_number": 2
    }
   ],
   "metadata": {}
  }
 ]
}