{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 3: NETWORK ANALYSIS"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.1,Page number: 53"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the value of capacitance parameter.\"\"\"\n",
      "\n",
      "#Variable Declaration:\n",
      "per_free_space=8.854e-12   #Permittivity of free space(in Farad per metre)\n",
      "A=0.113                    #Total area(in square metre)  \n",
      "rel_per=10.0               #Relative permittivity of mica layer\n",
      "d=0.1e-03                  #Thickness of mica layer(in metre)\n",
      "\n",
      "\n",
      "#Calculations:\n",
      "C1=(per_free_space*rel_per*A)/d\n",
      "W=0.05\n",
      "V=100.0\n",
      "C2=(2*W)/(V*V)\n",
      "i=5e-03\n",
      "dv=100\n",
      "dt=0.1\n",
      "C3=i/(dv/dt)\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"(i)The value of capacitance is %.2f micro Farad.\" %(C1*1000000)\n",
      "print \"(ii)The value of capacitance is %.2f micro Farad.\" %(C2*1000000)\n",
      "print \"(iii)The value of capacitance is %.2f micro Farad.\" %(C3*1000000)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(i)The value of capacitance is 0.10 micro Farad.\n",
        "(ii)The value of capacitance is 10.00 micro Farad.\n",
        "(iii)The value of capacitance is 5.00 micro Farad.\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.2,Page number: 54"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the inductance of the coil for different cases.\"\"\"\n",
      "\n",
      "#Variable Declaration:\n",
      "W=0.2                  #Energy stored in magnetic field(in Joules)    \n",
      "i=0.2                  #Current producing magnetic field(in Amperes) \n",
      "\n",
      "\n",
      "#Calculations:\n",
      "L1=(2*W)/(i*i)\n",
      "v=10\n",
      "di=0.1\n",
      "dt=0.2\n",
      "L2=v/(di/dt)\n",
      "p=2.5\n",
      "di=0.5\n",
      "dt=1\n",
      "i=0.1\n",
      "L3=p/(i*(di/dt))\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"(i)The inductance of the coil is %.2f H.\" %(L1)\n",
      "print \"(ii)The inductance of the coil is %.2f H.\" %(L2)\n",
      "print \"(iii)The inductance of the coil is %.2f H.\" %(L3)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(i)The inductance of the coil is 10.00 H.\n",
        "(ii)The inductance of the coil is 20.00 H.\n",
        "(iii)The inductance of the coil is 50.00 H.\n"
       ]
      }
     ],
     "prompt_number": 2
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.3,Page number: 55"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the inductance of 2 coils.\"\"\"\n",
      "\n",
      "#Variable Declaration:\n",
      "Leq=0.7                #Equivalent self-inductance(in Henry)\n",
      "\n",
      "\n",
      "#Calculations:\n",
      "\"\"\" Leq=0.7 H; \n",
      "    \n",
      "    Leq=((L1*L2)/(L1+L2))+0.5 ;\n",
      "\n",
      "    L1=(2*L2); \"\"\"\n",
      "L2=(Leq-0.5)*(3.0/2)\n",
      "L1=2*L2\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"L1=%.2f H. \\nL2=%.2f H.\" %(L1,L2)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "L1=0.60 H. \n",
        "L2=0.30 H.\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.4,Page number: 55"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the equivalent capacitance of the network and the voltage drop across each capacitor. \"\"\"\n",
      "\n",
      "#Variable Declaration:\n",
      "V=220.0                #Voltage of the DC source(in Volts)\n",
      "C1=0.05e-06            #Capacitance of the capacitor 1(in Farad)\n",
      "C2=0.10e-06            #Capacitance of the capacitor 2(in Farad)\n",
      "C3=0.20e-06            #Capacitance of the capacitor 3(in Farad)\n",
      "C4=0.05e-06            #Capacitance of the capacitor 4(in Farad) \n",
      "\n",
      "\n",
      "#Calculations:\n",
      "Cs=1/((1/C1)+(1/C2)+(1/C3)+(1/C4))\n",
      "Q=Cs*V\n",
      "V1=Q/C1\n",
      "V2=Q/C2\n",
      "V3=Q/C3\n",
      "V4=Q/C4\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"The equivalent capacitance of the network is %.4f micro Farad.\" %(Cs*1000000)\n",
      "print \"The voltage across capacitor C1= %.2f V.\" %(V1)\n",
      "print \"The voltage across capacitor C2= %.2f V.\" %(V2)\n",
      "print \"The voltage across capacitor C3= %.2f V.\" %(V3)\n",
      "print \"The voltage across capacitor C4= %.2f V.\" %(V4)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The equivalent capacitance of the network is 0.0182 micro Farad.\n",
        "The voltage across capacitor C1= 80.00 V.\n",
        "The voltage across capacitor C2= 40.00 V.\n",
        "The voltage across capacitor C3= 20.00 V.\n",
        "The voltage across capacitor C4= 80.00 V.\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.5,Page number: 55\n"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the voltage across each capacitor.\"\"\"\n",
      "\n",
      "#Variable Declaration:\n",
      "Q1=400e-06            #Charge on the capacitor 1(in Coulombs)\n",
      "Q2=200e-06            #Charge on the capacitor 2(in Coulombs) \n",
      "C1=2e-06              #Capacitance of the capacitor 1(in Farad)\n",
      "C2=10e-06             #Capacitance of the capacitor 2(in Farad) \n",
      "\n",
      "\n",
      "#Calculations:\n",
      "Q=Q1+Q2\n",
      "C=C1+C2\n",
      "V=Q/C\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"After the switch is closed, the voltage that exists across each capacitor is %.2f V.\" %(V)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "After the switch is closed, the voltage that exists across each capacitor is 50.00 V.\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.6,Page number: 56"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\" A series combination of 2 capacitances C1=2 micro-F and C2=8 micro-F is connected across a dc-supply of 300-V.Determine(a)the charge,\n",
      "    (b)the voltage,and(c)the energy stored in each capacitor. \"\"\"\n",
      "\n",
      "#Variable Declaration:\n",
      "C1=2e-06               #Capacitance of the capacitor 1(in Farad) \n",
      "C2=8e-06               #Capacitance of the capacitor 2(in Farad)\n",
      "V=300.0                #Voltage of Dc supply(in Volts)\n",
      "\n",
      "\n",
      "#Calculations:\n",
      "C=(C1*C2)/(C1+C2)\n",
      "Q=C*V\n",
      "V1=Q/C1\n",
      "V2=Q/C2\n",
      "W1=(1.0/2)*C1*(V1*V1)    \n",
      "W2=(1.0/2)*C2*(V2*V2)\n",
      "\n",
      "#Result:\n",
      "print \"(a)When connected in series,the charge on each capacitor is the same.The charge on each capacitor is %.2f micro Coulomb.\" %(Q*1000000)\n",
      "print \"(b)The voltage across the capacitor C1= %.2f V.\\n   The voltage across the capacitor C2= %.2f V.\" %(V1,V2)\n",
      "print \"(c)The energy stored in the capacitor C1= %.2f milli Joule.\" %(W1*1000)\n",
      "print \"   The energy stored in the capacitor C2= %.2f milli Joule.\" %(W2*1000)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)When connected in series,the charge on each capacitor is the same.The charge on each capacitor is 480.00 micro Coulomb.\n",
        "(b)The voltage across the capacitor C1= 240.00 V.\n",
        "   The voltage across the capacitor C2= 60.00 V.\n",
        "(c)The energy stored in the capacitor C1= 57.60 milli Joule.\n",
        "   The energy stored in the capacitor C2= 14.40 milli Joule.\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.7,Page number: 56"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the value of capacitance.\"\"\"\n",
      "\n",
      "#Variable Declaration:\n",
      "C_eq=1e-06            #Equivalent capacitance of the network(in Farad)\n",
      "C1=1e-06              #Capacitance of the capacitor 1(in Farad)\n",
      "C2=8e-06              #Capacitance of the capacitor 2(in Farad)\n",
      "C3=2e-06              #Capacitance of the capacitor 3(in Farad)\n",
      "C4=2e-06              #Capacitance of the capacitor 4(in Farad)\n",
      "C5=6e-06              #Capacitance of the capacitor 5(in Farad)\n",
      "C6=12e-06             #Capacitance of the capacitor 6(in Farad)\n",
      "C7=4e-06              #Capacitance of the capacitor 7(in Farad) \n",
      "\n",
      "\n",
      "#Calculations:\n",
      "C8=C3+C4\n",
      "C9=1/((1/C5)+(1/C6))\n",
      "C10=1/((1/C2)+(1/C8))\n",
      "C11=C7+C9\n",
      "C12=1/((1/C1)+(1/C11))\n",
      "C13=C12+C10\n",
      "C=1/((1/C_eq)-(1/C13))\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"The value of capacitance C is %.2f micro Farad.\" %(C*1e06)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The value of capacitance C is 1.39 micro Farad.\n"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.8,Page number: 59"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the % change in V_L and I_L.\"\"\"\n",
      "\n",
      "#Variable Declaration:\n",
      "E=3.0                  #EMF of the battery(in Volts) \n",
      "Ri=1.0                 #Internal resistance of the battery(in Ohms)\n",
      "R_L_min=100.0          #Minimum value of variable load resistance(in Ohms)\n",
      "R_L_max=1000.0         #Maximum value of variable load resistance(in Ohms) \n",
      "\n",
      "\n",
      "#Calculations and Result: \n",
      "I_L1=E/(R_L_min+Ri)\n",
      "I_L2=E/(R_L_max+Ri)\n",
      "V_L1=E-(I_L1*Ri)\n",
      "V_L2=E-(I_L2*Ri)\n",
      "\n",
      "if I_L1>I_L2 :\n",
      "               change_I_L= ((I_L1-I_L2)/I_L1)*100\n",
      "               ans=\"(a)The percentage decrease in I_L is %.2f percent\" %(round(change_I_L,2))\n",
      "               print(ans)\n",
      "elif I_L2>IL1 : \n",
      "               change_I_L= ((I_L2-I_L1)/I_L1)*100\n",
      "               ans=\"(a)The percentage increase in I_L is %.2f percent\" %(round(change_I_L,2))\n",
      "               print(ans)\n",
      "else: print(\"(a)The percentage change in I_L is 0 percent.\")\n",
      "\n",
      "if V_L2>V_L1 :\n",
      "              change_V_L= ((V_L2-V_L1)/V_L1)*100\n",
      "              ans=\"   The percentage increase in V_L is %.2f percent\" %(round(change_V_L,2))\n",
      "              print(ans)\n",
      "elif V_L1>V_L2 :\n",
      "                change_V_L= ((V_L1-V_L2)/V_L1)*100\n",
      "                ans=\"   The percentage decrease in V_L is %.2f percent\" %(round(change_V_L,2))\n",
      "                print(ans)\n",
      "else : print(\"   The percentage change in V_L is 0\",\"%\")\n",
      "\n",
      "R_L_min=1e-03\n",
      "R_L_max=10e-03\n",
      "I_L1=E/(R_L_min+Ri)\n",
      "I_L2=E/(R_L_max+Ri)\n",
      "V_L1=round((E-(I_L1*Ri)),3)\n",
      "V_L2=round((E-(I_L2*Ri)),2)\n",
      "\n",
      "if I_L1>I_L2 :\n",
      "               change_I_L= ((I_L1-I_L2)/I_L1)*100\n",
      "               ans=\"(b)The percentage decrease in I_L is %.2f percent\" %(round(change_I_L,2))\n",
      "               print(ans) \n",
      "\n",
      "elif I_L2>I_L1 :\n",
      "                change_I_L= ((I_L2-I_L1)/I_L1)*100\n",
      "                ans=\"(b)The percentage increase in I_L is %.2f percent\" %(round(change_I_L,2))\n",
      "                print(ans)\n",
      "\n",
      "else : print(\"(b) The percentage change in I_L is 0 percent\")\n",
      "\n",
      "if V_L2>V_L1 :\n",
      "               change_V_L= ((V_L2-V_L1)/V_L1)*100\n",
      "               ans=\"   The percentage increase in V_L is %.3f percent\" %(change_V_L)\n",
      "               print(ans)\n",
      "\n",
      "elif V_L1>V_L2 :\n",
      "                change_V_L= ((V_L1-V_L2)/V_L1)*100\n",
      "                ans=\"   The percentage decrease in V_L is %.2f percent\" %(change_V_L)\n",
      "                print(ans)\n",
      "\n",
      "else: print(\"    The percentage change in V_L is 0 percent\")\n",
      "\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)The percentage decrease in I_L is 89.91 percent\n",
        "   The percentage increase in V_L is 0.90 percent\n",
        "(b)The percentage decrease in I_L is 0.89 percent\n",
        "   The percentage increase in V_L is 900.000 percent\n"
       ]
      }
     ],
     "prompt_number": 30
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.9,Page number: 61"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the power delivered by the ideal part of the sources.\"\"\"\n",
      "\n",
      "#Variable Declaration:\n",
      "R_S=2.0                #Resistance of the current source(in Ohms)\n",
      "I_S=3.0                #Current from the current source(in Amperes) \n",
      "R_L=4.0                #Resistance of the load(in Ohms)\n",
      "\n",
      "\n",
      "#Calculations:\n",
      "V_S=R_S*I_S\n",
      "I_L1=I_S*(R_S/(R_S+R_L))\n",
      "V_L1=I_L1*R_L\n",
      "R1=1/((1/R_S)+(1/R_L))\n",
      "P_S1=I_S*I_S*R1\n",
      "I_L2=V_S/(R_S+R_L)\n",
      "V_L2=V_S*(R_L/(R_S+R_L))\n",
      "R2=R_S+R_L\n",
      "P_S2=(V_S*V_S)/R2\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"Case 1:\"\n",
      "print \"I_L=%.2f A. \\nV_L=%.2f V. \\nP_S=%.2f W.\" %(I_L1,V_L1,P_S1)\n",
      "print \"\\nCase 2:\"\n",
      "print \"I_L=%.2f A. \\nV_L=%.2f V. \\nP_S=%.2f W.\" %(I_L2,V_L2,P_S2) \n",
      "print \"\\nWe find that the two energy sources are equivalent as regards the terminal relationships. But, the total power delivered by the ideal part of the two sources is different.\" "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Case 1:\n",
        "I_L=1.00 A. \n",
        "V_L=4.00 V. \n",
        "P_S=12.00 W.\n",
        "\n",
        "Case 2:\n",
        "I_L=1.00 A. \n",
        "V_L=4.00 V. \n",
        "P_S=6.00 W.\n",
        "\n",
        "We find that the two energy sources are equivalent as regards the terminal relationships. But, the total power delivered by the ideal part of the two sources is different.\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.10,Page number: 62"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the currents through the two resistors in the circut.\"\"\"\n",
      "\n",
      "#Calculations:\n",
      "I_2_ohm1=16.0*(6.0/(6+2))\n",
      "I_6_ohm1=16-I_2_ohm1\n",
      "V_eq=16*2\n",
      "I_2_ohm2=V_eq/(2+6)\n",
      "I_6_ohm2=I_2_ohm2\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"The current through the 2 ohm resistor is %.2f A.\" %(I_2_ohm1) \n",
      "print \"The current through the 6 ohm resistor is %.2f A. \\n\" %(I_6_ohm1) \n",
      "print \"After transformation,\\nThe current through the 2 ohm resistor is %.2f A.\" %(I_2_ohm2) \n",
      "print \"The current through the 6 ohm resistor is %.2f A.\" %(I_6_ohm2)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The current through the 2 ohm resistor is 12.00 A.\n",
        "The current through the 6 ohm resistor is 4.00 A. \n",
        "\n",
        "After transformation,\n",
        "The current through the 2 ohm resistor is 4.00 A.\n",
        "The current through the 6 ohm resistor is 4.00 A.\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.11,Page number: 64"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the reduced network using source transformation.\"\"\"\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"First all the voltage sources are transformed to equivalent current sources.\"\"\"\n",
      "I1=8.0/2.0\n",
      "I2=6.0/1.0\n",
      "I3=6.0/2.0\n",
      "I4=3.0/1.0\n",
      "I5=I1+I2\n",
      "I6=I3+I4\n",
      "R1=1.0/((1.0/2.0)+(1.0/1.0))\n",
      "R2=1.0/((1.0/2.0)+(1.0/1.0))\n",
      "V5=I5*R1\n",
      "V6=I6*R2\n",
      "V_tot=V5+V6\n",
      "R_tot=R1+R2\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"The network is equivalent to a voltage source of %.3f V with an internal resistance of %.2f Ohms.\" %(V_tot,R_tot)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The network is equivalent to a voltage source of 10.667 V with an internal resistance of 1.33 Ohms.\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.12,Page number: 65"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the voltage across 3 Ohms resistor.\"\"\"\n",
      "\n",
      "#Variable Declaration:\n",
      "I1=4.0                #Current delivered by source 1(in Amperes)\n",
      "R1=1.0                #Resitance of resistor parallel to current source 1(in Ohms) \n",
      "V2=6.0                #Voltage of the voltage source 2(in Volts)\n",
      "I2=5.0                #Current delivered by source 2(in Amperes)\n",
      "R2=2.0                #Resistance of resistor 2(in Ohms) \n",
      "R3=3.0                #Resistance of resistor 3(in Ohms)\n",
      "\n",
      "\n",
      "#Calculations:\n",
      "V1=I1*R1\n",
      "V3=V1+V2\n",
      "I3=V3/R1\n",
      "I4=I3-I2\n",
      "V4=I4*R1\n",
      "V_res=V4*(R3/(R1+R2+R3))\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"The voltage across 3 Ohms resistor is %.2f Volts.\" %(V_res)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The voltage across 3 Ohms resistor is 2.50 Volts.\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.13,Page number: 67"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the current in the circuit.\"\"\"\n",
      "\n",
      "#Variable Declaration:\n",
      "V=24.0                #Supply voltage(in Volts)\n",
      "R1=4.0                #Resistance of resistor 1(in Ohms) \n",
      "R2=2.0                #Resistance of resistor 2(in Ohms)\n",
      "\n",
      "\n",
      "#Calculations:\n",
      "\"\"\" V1=4*I;\n",
      "    Applying Kirchoff's Voltage Law to the closed loop, 24-(4*I)-(2*I)-(4.5*4*I)=0 ; \"\"\"\n",
      "I=24/((R1+R2)-(4.5*R1))\n",
      "P=-4.5*R1*I*I\n",
      "R=V/I\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"(a)The value of the current I is %.2f A.\" %(abs(I))\n",
      "print \"(b)The power absorbed by the dependent source is %.2f W.\" %(P)\n",
      "print \"(c)The resistance 'seen' by the independent voltage source is %.2f Ohms.\" %(R) \n",
      "print \"\\nNOTE: The negative sign of the resistance is a result of the action of the dependent source.\"     "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)The value of the current I is 2.00 A.\n",
        "(b)The power absorbed by the dependent source is -72.00 W.\n",
        "(c)The resistance 'seen' by the independent voltage source is -12.00 Ohms.\n",
        "\n",
        "NOTE: The negative sign of the resistance is a result of the action of the dependent source.\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.14,Page number: 68"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the voltage in the circuit.\"\"\"\n",
      "\n",
      "#Variable Declaration:\n",
      "V=100.0               #Supply voltage(in Volts)\n",
      "\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"Appling KVL in the closed loop, +100-(40*I)-(60*I)=0.\"\"\"\n",
      "I=V/(40.0+60.0)\n",
      "V1=I*60.0\n",
      "\"\"\"Appling KVL in the open loop, -10+V1+(0*10)+30-Vab=0.\"\"\"\n",
      "Vab=30+V1-10\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"The voltage Vab in the circuit is %.2f V.\" %(Vab)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The voltage Vab in the circuit is 80.00 V.\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.15,Page number: 69"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the unknown voltages Vx and Vcd.\"\"\"\n",
      "\n",
      "#Variable Declaration:\n",
      "V=10.0                #Supply voltage(in Volts)\n",
      "Vca=4.0               #Voltage between points c and a(in Volts) \n",
      "V1=6.0                #Voltage across resistor R1(in Volts) \n",
      "V2=-4.0               #Voltage across resistor R2(in Volts) \n",
      "\n",
      "\n",
      "#Calculations:\n",
      "Vx=Vca-V2\n",
      "Vcd=Vca-V1\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"The voltage Vx in the circuit is %.2f V.\" %(Vx)\n",
      "print \"The voltage Vcd in the circuit is %.2f V.\" %(Vcd)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The voltage Vx in the circuit is 8.00 V.\n",
        "The voltage Vcd in the circuit is -2.00 V.\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.16,Page number: 71"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the currents in the network.\"\"\"\n",
      "\n",
      "from sympy import *;\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"KVL equations for loops 1,2 and 3 are written and the equations are solved using SymPy.\"\"\" \n",
      "print \"Note: All currents are expressed in Amperes.\"\n",
      "Ix, Iy, I1 = symbols('Ix Iy I1');\n",
      "solve([(5*Ix)+(0*Iy)+(10*I1)-100,(7*Ix)+(2*Iy)+(-2*I1)+50,(3*Ix)+(-5*Iy)+(-3*I1)+50], [Ix,Iy,I1])\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Note: All currents are expressed in Amperes.\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 20,
       "text": [
        "{I1: 585/49, Ix: -190/49, Iy: 25/49}"
       ]
      }
     ],
     "prompt_number": 20
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.17,Page number: 71"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the currents using Kirchoff's laws.\"\"\"\n",
      "\n",
      "from sympy import *;\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"KCL equations at nodes B and C,we get\n",
      "    \n",
      "   I1+I2=20;\n",
      "   \n",
      "   I3-I2=30;\"\"\"\n",
      "\"\"\"KVL equation for the outer loop ABCDEFGHA, I1-(3*I2)-(2*I3)=-100; \"\"\"\n",
      "print \"All the currents are expressed in Amperes.\"\"\"\n",
      "print \"Resistances R1 and R2 are in Ohms.\"\"\"\n",
      "I1, I2,I3,R1,R2 = symbols('I1 I2 I3 R1 R2')\n",
      "solve([I1+I2+(0*I3)-20,(0*I1)-I2+I3-30,I1+(-3*I2)+(-2*I3)+100,(110-(0.1*I1))-(20*R1),(120-(0.2*I3))-(30*R2)],[I1,I2,I3,R1,R2])\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "All the currents are expressed in Amperes.\n",
        "Resistances R1 and R2 are in Ohms.\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 42,
       "text": [
        "{I1: 10.0000000000000,\n",
        " I2: 10.0000000000000,\n",
        " I3: 40.0000000000000,\n",
        " R1: 5.45000000000000,\n",
        " R2: 3.73333333333333}"
       ]
      }
     ],
     "prompt_number": 42
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.18,Page number: 74"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the current through resistor in the circuit.\"\"\"\n",
      "\n",
      "#Variable Declaration:\n",
      "I=2.0                 #Loop current(in Amperes)\n",
      "\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"KVL Equation: 10-(5*(I1-2))-(8*I1)=0.\"\"\"\n",
      "I1=(10.0+10.0)/(8.0+5.0)\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"The current through the 8 Ohms resistor is %.3f A.\" %(I1)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The current through the 8 Ohms resistor is 1.538 A.\n"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.19,Page number: 75"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the unknown voltage.\"\"\"\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"Writing the KVL equation around the loop of I, -(2*I)+(3*I)+6-(1*(I+5-4))=0.\"\"\"\n",
      "I=(6.0-1.0)/(2+3+1)\n",
      "v=3*I\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"The unknown voltage in the circuit is %.2f V.\" %(v)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The unknown voltage in the circuit is 2.50 V.\n"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.20,Page number: 79"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the current drawn by the source.\"\"\"\n",
      "\n",
      "from sympy import *;\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"Apply KVL for the loops 1, 2 and 3 and solving for currents.\"\"\"\n",
      "print \"All the currents are expressed in Amperes.\"\"\"\n",
      "print \"The current delivered  by the source is I1.\"\n",
      "I1, I2,I3,Is = symbols('I1 I2 I3 Is')\n",
      "solve([(19*I1)+(-12*I2)+(0*I3)-60,(-12*I1)+(18*I2)+(-6*I3),(0*I1)+(-6*I2)+(18*I3),Is-I1], [I1,I2,I3,Is]) "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "All the currents are expressed in Amperes.\n",
        "The current delivered  by the source is I1.\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 4,
       "text": [
        "{I1: 6, I2: 9/2, I3: 3/2, Is: 6}"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.21,Page number: 80"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the mesh currents using mesh analysis.\"\"\"\n",
      "\n",
      "from sympy import *;\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"Apply KVL for the loops 1, 2 and 3 and solving for currents.\"\"\"\n",
      "print \"All the currents are expressed in Amperes.\"\"\"\n",
      "I1, I2, I3 = symbols('I1 I2 I3')\n",
      "solve([(7*I1)+(-4*I2)+(0*I3)-13,(-4*I1)+(15*I2)+(-6*I3)-12,(0*I1)+(-6*I2)+(13*I3)-1], [I1,I2,I3]) "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "All the currents are expressed in Amperes.\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 34,
       "text": [
        "{I1: 3, I2: 2, I3: 1}"
       ]
      }
     ],
     "prompt_number": 34
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.22,Page number: 81"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the voltage across resistor using node-voltage analysis.\"\"\"\n",
      "\n",
      "from sympy import *;\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"Apply KCL at nodes a and b and finding the nodal voltages.\"\"\"\n",
      "print \"All the voltages are expressed in Volts.\"\"\"\n",
      "Va,Vb,Vab = symbols('Va Vb Vab')\n",
      "solve([(Va/2)+((Va-Vb)/3)-5,((Vb-Va)/3)+(Vb/4)+6,Va-Vb-Vab], [Va,Vb,Vab])\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "All the voltages are expressed in Volts.\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 43,
       "text": [
        "{Va: 22/9, Vab: 34/3, Vb: -80/9}"
       ]
      }
     ],
     "prompt_number": 43
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.23,Page number: 82"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the current through resistor.\"\"\"\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"Applying KCL at node 1,\n",
      "\n",
      "   ((V1-0)/12.0)+((V1-60.0)/7.0)+((V1-0)/4.0)=0; \"\"\"\n",
      "V1=(60.0/7.0)/((1.0/12.0)+(1.0/7.0)+(1.0/4.0))\n",
      "I1=V1/12.0\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"The current I1 through the 12 Ohms resistor is %.2f A.\" %(I1)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The current I1 through the 12 Ohms resistor is 1.50 A.\n"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.24,Page number: 82"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the current through a resistor.\"\"\"\n",
      "\n",
      "from sympy import *;\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"Apply KCL for supernode (a,b) and for node c and finding the nodal voltages.\"\"\"\n",
      "print \"All the voltages are expressed in Volts.\"\"\"\n",
      "print \"The current I is in Amperes.\"\n",
      "Va,Vb,Vc,I = symbols('Va Vb Vc I')\n",
      "solve([Va-Vb-6,(Va/3)+((Vb-Vc)/4)-2,((Vc-Vb)/4)+(Vc/5)+7,((Vb-Vc)/4)-I], [Va,Vb,Vc,I])\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "All the voltages are expressed in Volts.\n",
        "The current I is in Amperes.\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 47,
       "text": [
        "{I: 35/12, Va: -11/4, Vb: -35/4, Vc: -245/12}"
       ]
      }
     ],
     "prompt_number": 47
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.25,Page number: 83"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the voltage across resistor by nodal-voltage method.\"\"\"\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"Applying KCL at node a,\n",
      "  \n",
      "   ((Va-6.0)/1.0)+((Va-0.0)/5.0)=-4.0+5.0 ; \"\"\"\n",
      "\n",
      "Va=(6.0-1.0)/1.2\n",
      "v=Va*(3.0/(2.0+3.0))\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"The voltage across 3 Ohms resistor is %.2f V.\" %(v)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The voltage across 3 Ohms resistor is 2.50 V.\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.26,Page number: 84"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the current through resistor.\"\"\"\n",
      "\n",
      "from sympy import *;\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"Applying KCL at nodes 1 and 2 and solving for nodal voltages.\"\"\"\n",
      "print \"All the voltages are expressed in Volts.\"\"\"\n",
      "print \"The current I is in Amperes.\"\n",
      "V1,V2,I = symbols('V1 V2 I')\n",
      "solve([(0.7*V1)+(-0.2*V2)-3,(-0.2*V1)+(1.2*V2)-2,((V1-V2)/5.0)-I],[V1,V2,I])\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "All the voltages are expressed in Volts.\n",
        "The current I is in Amperes.\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 16,
       "text": [
        "{I: 0.500000000000000, V1: 5.00000000000000, V2: 2.50000000000000}"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.27,Page number: 85 "
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the current through a resistor.\"\"\"\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"Applying KCL at node 1,\n",
      "\n",
      "   ((V-10.0)/2.0)+((V-0.0)/(1.0+3.0))+((V-8.0)/6.0)=0 ; \"\"\"\n",
      "\n",
      "V=((10.0/2.0)+(8.0/6.0))/((1.0/2.0)+(1.0/4.0)+(1.0/6.0))\n",
      "I=V/(1.0+3.0)\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"The current I is %.2f A.\" %(I)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The current I is 1.73 A.\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.28,Page number: 85"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the values of capacitances.\"\"\"\n",
      "\n",
      "from sympy import *;\n",
      "\n",
      "#Variable Declaration:\n",
      "Vs=200.0              #Voltage of the dc supply(in Volts)\n",
      "V1=120.0              #Potential difference across C1(in Volts)\n",
      "V_new=140.0           #Potential difference across C1 when a capacitor is added(in Volts)\n",
      "\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"Case 1: The charge on each capacitor is the same.\n",
      "\n",
      "           (C1*V1)=(C2*V2);\n",
      "           (120*C1)=(80*C2);\"\"\"\n",
      "\"\"\"Case 2: The capacitance of 3 micro Farad in parallel with C2 gives an equivalent capacitance of (C2+3) micro Farad.\n",
      "            \n",
      "           (140*C1)=(60*(C2+3)) ;\"\"\"\n",
      "print \"Note:The capacitances are expressed in Farads.\"          \n",
      "C1,C2 = symbols('C1 C2')\n",
      "solve([(120*C1)-(80*C2),(140*C1)-(60*(C2+(3e-06)))],[C1,C2])\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Note:The capacitances are expressed in Farads.\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 31,
       "text": [
        "{C1: 3.60000000000000e-6, C2: 5.40000000000000e-6}"
       ]
      }
     ],
     "prompt_number": 31
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.29,Page number: 86"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the current in each branch.\"\"\"\n",
      "\n",
      "#Calculations:\n",
      "I1=20.0/10.0\n",
      "I4=10.0/5.0\n",
      "I5=10.0/2.0\n",
      "I2=(20.0-(10.0+9.0))/1.0\n",
      "I3=(20.0-50.0-10.0)/20.0\n",
      "Ia=I1+I2+I3\n",
      "Ib=I4+I5-I2-I3\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"The currents are:\" \n",
      "print \" I1=%.2f A \\n I2=%.2f A \\n I3=%.2f A \\n I4=%.2f A \\n I5=%.2f A \\n Ia=%.2f A \\n Ib=%.2f A\" %(I1,I2,I3,I4,I5,Ia,Ib)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The currents are:\n",
        " I1=2.00 A \n",
        " I2=1.00 A \n",
        " I3=-2.00 A \n",
        " I4=2.00 A \n",
        " I5=5.00 A \n",
        " Ia=1.00 A \n",
        " Ib=8.00 A\n"
       ]
      }
     ],
     "prompt_number": 50
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.30,Page number: 86"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the currents through resistors.\"\"\"\n",
      "\n",
      "from sympy import *;\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"Apply KVL for the loops 1 and 2 and solving for currents.\"\"\"\n",
      "print \"All the currents are expressed in Amperes.\"\"\"\n",
      "print \"Current through R1= Current through R2=I1\"\n",
      "print \"Current through R3=I3\"\n",
      "print \"Current through R4=I2\"\n",
      "I1, I2, I3 = symbols('I1 I2 I3')\n",
      "solve([(4.5*I1)+(-3*I2)-2,(-3*I1)+(4*I2)-5,I1-I2-I3], [I1,I2,I3]) "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "All the currents are expressed in Amperes.\n",
        "Current through R1= Current through R2=I1\n",
        "Current through R3=I3\n",
        "Current through R4=I2\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 54,
       "text": [
        "{I1: 2.55555555555556, I2: 3.16666666666667, I3: -0.611111111111111}"
       ]
      }
     ],
     "prompt_number": 54
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.31,Page number: 87"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the current through each resistor.\"\"\"\n",
      "\n",
      "#Variable Declaration:\n",
      "E1=4.0                #EMF of cell 1(in Volts)\n",
      "E2=8.0                #EMF of cell 2(in Volts)\n",
      "R1=0.5                #Internal resistance of cell 1(in Ohms)\n",
      "R2=1.0                #Internal resistance of cell 2(in Ohms)\n",
      "\n",
      "\n",
      "#Calculations:\n",
      "R3=1.0/((1.0/3.0)+(1.0/6.0))\n",
      "Rt=R1+R2+R3+4.5\n",
      "E=E2-E1\n",
      "I=E/Rt\n",
      "I_3=I*(6.0/(3.0+6.0))\n",
      "I_6=I*(3.0/(3.0+6.0))\n",
      "V1=E1+(I*R1)\n",
      "V2=E2-(I*R2)\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"(a)The current the 3 Ohms resistor is %.2f A.\" %(I_3)\n",
      "print \"   The current the 6 Ohms resistor is %.2f A.\" %(I_6)\n",
      "print \"   The current the 4.5 Ohms resistor is %.2f A.\" %(I)\n",
      "print \"(b)The potential difference across cell 1 is %.2f V and across cell 2 is %.2f V.\" %(V1,V2)\n",
      "print \"   Note that the pd of cell E1 is greater than its EMF.This is so because the cell is working as a load.\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)The current the 3 Ohms resistor is 0.33 A.\n",
        "   The current the 6 Ohms resistor is 0.17 A.\n",
        "   The current the 4.5 Ohms resistor is 0.50 A.\n",
        "(b)The potential difference across cell 1 is 4.25 V and across cell 2 is 7.50 V.\n",
        "   Note that the pd of cell E1 is greater than its EMF.This is so because the cell is working as a load.\n"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.32,Page number: 88"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the potential of point A.\"\"\"\n",
      "\n",
      "#Variable Declaration:\n",
      "E1=8.0                #EMF of first source(in Volts)\n",
      "E2=6.0                #EMF of second source(in Volts)\n",
      "E3=4.0                #EMF of third source(in Volts)\n",
      "R1=5.0                #Resistance of resistor 1(in Ohms) \n",
      "R2=9.0                #Resistance of resistor 2(in Ohms)\n",
      "\n",
      "\n",
      "#Calculations:\n",
      "V_A=E3+E2-E1\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"The potential of point A is %.2f V.\" %(V_A)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The potential of point A is 2.00 V.\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.33,Page number: 88"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the energy stored in a capacitor.\"\"\"\n",
      "\n",
      "#Variable Declaration:\n",
      "C=4e-06               #Capacitance of the capacitor(in Farad)\n",
      "\n",
      "\n",
      "#Calculations:\n",
      "\"\"\" Applying KCL to the node at the top of the capacitor, current through 5 Ohms resistance is 1+2=3 A. \n",
      "    Applying KCL to the node at the bottom of the capacitor, current through 2 Ohms resistance is 2-1=1 A.\"\"\"\n",
      "V=(3*5)+(3*1)+(1*2)\n",
      "W=0.5*C*V*V\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"The energy stored in the capacitor is %e J.\" %(W)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The energy stored in the capacitor is 8.000000e-04 J.\n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.34,Page number: 88"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the potential differnce between two points.\"\"\"\n",
      "\n",
      "#Variable Declaration:\n",
      "E1=3.0                #EMF of cell 1(in Volts)\n",
      "E2=2.0                #EMF of cell 2in Volts)\n",
      "E3=1.0                #EMF of cell 3in Volts)\n",
      "r1=1.0                #Internal resistance of cell 1(in Ohms)\n",
      "r2=1.0                #Internal resistance of cell 2(in Ohms)\n",
      "r3=1.0                #Internal resistance of cell 3(in Ohms) \n",
      "R=1.0                 #Resistance of resistor R(in Ohms)\n",
      "\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"Assigning loop currents as I1 and I2 and writing KVL equations for the two loops,\n",
      "\n",
      "   E1-(I1*r1)-((I1-I2)*r2)-E2=0; which is (-2*I1)+I2+1=0; \n",
      "   \n",
      "   E2-(I2*r3)-((I2-I1)*r2)-E3=0; which is (-2*I2)+I1+1=0; \"\"\"\n",
      "\n",
      "eq1=-1\n",
      "eq2=-1\n",
      "I1=((2*eq1)+eq2)/(-3.0)\n",
      "I2=((2*eq2)+eq1)/(-3.0)\n",
      "Vab=E2+((I1-I2)*r2)+(0*R)\n",
      "\n",
      "V_CB=E2\n",
      "V_B=0.0\n",
      "V_C=V_CB+V_B\n",
      "I3=(V_C-E1)/r1\n",
      "I4=(V_C-E3)/r3\n",
      "I6=V_C/R\n",
      "I5=I3+I4+I6\n",
      "\n",
      "\n",
      "#Result:\n",
      "print \"(a)The potential difference between points A and B is %.2f V.\" %(Vab) \n",
      "print \"   The current through r1 is %.2f A,the current through r2=%.2f A.\" %(I1,(I1-I2)) \n",
      "print \"   The current through r3=%.2f A and the current through R is 0(no closed loop).\" %(I2)\n",
      "print \"(b)The current through E1 is %.2f A.\" %(I3) \n",
      "print \"   The current through E2 is %.2f A.\" %(I5)\n",
      "print \"   The current through E3 is %.2f A.\" %(I4)\n",
      "print \"   The current through R is %.2f A.\" %(I6)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(a)The potential difference between points A and B is 2.00 V.\n",
        "   The current through r1 is 1.00 A,the current through r2=0.00 A.\n",
        "   The current through r3=1.00 A and the current through R is 0(no closed loop).\n",
        "(b)The current through E1 is -1.00 A.\n",
        "   The current through E2 is 2.00 A.\n",
        "   The current through E3 is 1.00 A.\n",
        "   The current through R is 2.00 A.\n"
       ]
      }
     ],
     "prompt_number": 29
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.35,Page number: 89"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the potential diiference between two points.\"\"\"\n",
      "\n",
      "#Calculations:\n",
      "pd_9=0.0\n",
      "pd_13=0.0\n",
      "pd_10=6.0*10.0\n",
      "pd_5=5.0*8.0\n",
      "pd_18=15.0\n",
      "Vab=pd_5-pd_10-pd_18\n",
      "\n",
      "#Result:\n",
      "print \"The voltage drop Vab is %.2f V.\" %(Vab)\n",
      "print \"The resistors 4 Ohms,11 Ohms,9 Ohms,18 Ohms and 13 Ohms have no effect on the voltage drop Vab.\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The voltage drop Vab is -35.00 V.\n",
        "The resistors 4 Ohms,11 Ohms,9 Ohms,18 Ohms and 13 Ohms have no effect on the voltage drop Vab.\n"
       ]
      }
     ],
     "prompt_number": 18
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.36,Page number: 90 "
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the voltage of dependent voltage source.\"\"\"\n",
      "\n",
      "from sympy import *;\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"Apply KVL for the loops 1 and 2.\"\"\"\n",
      "print \"The current I1 is expressed in Amperes and the voltage V1 is expressed in Volts.\"\"\"\n",
      "V1,I1 = symbols('V1 I1')\n",
      "solve([V1+(2*I1),24-(16*I1)-(4*V1)], [V1,I1]) "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The current I1 is expressed in Amperes and the voltage V1 is expressed in Volts.\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 33,
       "text": [
        "{I1: 3, V1: -6}"
       ]
      }
     ],
     "prompt_number": 33
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.37,Page number: 90"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the voltage V.\"\"\"\n",
      "\n",
      "from sympy import *;\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"Apply KCL at the upper node and KVL equation for the left loop.\"\"\"\n",
      "print \"The currents I1 and I2 are expressed in Amperes and the voltage V is expressed in Volts.\"\"\"\n",
      "I1,I2,V = symbols('I1 I2 V')\n",
      "solve([I1-I2+(10*I2),36-(20e03*I1),V+(10*I2*(5e03))], [I1,I2,V]) "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The currents I1 and I2 are expressed in Amperes and the voltage V is expressed in Volts.\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 37,
       "text": [
        "{I1: 0.00180000000000000, I2: -0.000200000000000000, V: 10.0000000000000}"
       ]
      }
     ],
     "prompt_number": 37
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.38,Page number: 90"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the loop currents.\"\"\"\n",
      "\n",
      "from sympy import *;\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"Apply KVL for the loops 1 and 2.\"\"\"\n",
      "print \"The loop currents i1 and i2 are expressed in Amperes.\"\n",
      "i1,i2 = symbols('i1 i2')\n",
      "solve([(3*i2)-((i2-i1)*1)-(i2*2)-3,4-(i1*1)-((i1-i2)*1)-(3*i2)], [i1,i2]) "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The loop currents i1 and i2 are expressed in Amperes.\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 16,
       "text": [
        "{i1: 3, i2: -1}"
       ]
      }
     ],
     "prompt_number": 16
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.39,Page number: 91"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the nodal voltages.\"\"\"\n",
      "\n",
      "from sympy import *;\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"Applying KCL at top node and solving for nodal voltages.\"\"\"\n",
      "print \"All the voltages are expressed in Volts.\"\"\"\n",
      "print \"The current I is in Amperes.\"\n",
      "V1,V2,I = symbols('V1 V2 I')\n",
      "solve([9-I-(V1/10)+(3*I),9-(4*V1/5)-(V1/10),V2-V1-108],[V1,V2,I])\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "All the voltages are expressed in Volts.\n",
        "The current I is in Amperes.\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 40,
       "text": [
        "{I: -4, V1: 10, V2: 118}"
       ]
      }
     ],
     "prompt_number": 40
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.40,Page number: 91"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the current I by nodal analysis.\"\"\"\n",
      "\n",
      "from sympy import *;\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"Apply KCL at the nodes 1 and 2.\"\"\"\n",
      "print \"The nodal voltages V1 and V2 are expressed in Volts.\"\n",
      "print \"The current I is expressed in Amperes.\"\n",
      "V1,V2,I = symbols('V1 V2 I')\n",
      "solve([(2*V1)-(V2)-12,(-2*V1)+(4*V2)-6,I-((V1-V2)/3)], [V1,V2,I]) "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The nodal voltages V1 and V2 are expressed in Volts.\n",
        "The current I is expressed in Amperes.\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 15,
       "text": [
        "{I: 1, V1: 9, V2: 6}"
       ]
      }
     ],
     "prompt_number": 15
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.41,Page number: 91"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the current I in the circuit.\"\"\"\n",
      "\n",
      "from sympy import *;\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"Apply KCL at the nodes 1 and 2.\"\"\"\n",
      "print \"The nodal voltages V1 and V2 are expressed in Volts.\"\n",
      "print \"The current I is expressed in Amperes.\"\n",
      "V1,V2,I = symbols('V1 V2 I')\n",
      "solve([(1*V1)-(0.5*V2)-6,(-0.5*V1)+(0.625*V2)-3,I-((V1-V2)/2)], [V1,V2,I]) "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The nodal voltages V1 and V2 are expressed in Volts.\n",
        "The current I is expressed in Amperes.\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 14,
       "text": [
        "{I: -1.00000000000000, V1: 14.0000000000000, V2: 16.0000000000000}"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.42,Page number: 92"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the current through resistor.\"\"\"\n",
      "\n",
      "from sympy import *;\n",
      "\n",
      "#Calculations:\n",
      "\"\"\"Apply KCL at the nodes 1,2. and 3\"\"\"\n",
      "print \"The nodal voltages V1,V2 and V3 are expressed in Volts.\"\n",
      "print \"The current I flowing through the 2 Ohms resistor is expressed in Amperes.\" \n",
      "V1,V2,V3,I = symbols('V1 V2 V3 I')\n",
      "solve([(7*V1)-(3*V2)-(4*V3)+11,(-3*V1)+(6*V2)-(2*V3)-3,(-4*V1)-(2*V2)+(11*V3)-25,I-(2*(V2-V3))], [V1,V2,V3,I]) "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The nodal voltages V1,V2 and V3 are expressed in Volts.\n",
        "The current I flowing through the 2 Ohms resistor is expressed in Amperes.\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 12,
       "text": [
        "{I: -2, V1: 1, V2: 2, V3: 3}"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 3.43,Page number: 92"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#Question:\n",
      "\"\"\"Finding the nodal voltages in the circuit.\"\"\"\n",
      "\n",
      "from sympy import *;\n",
      "\n",
      "#Calculations:\n",
      "Ieq=13.0*5.0 #Equivalent current source\n",
      "\"\"\"Apply KCL at the nodes 1 and 2.\"\"\"\n",
      "print \"The nodal voltages V1 and V2 are expressed in Volts.\"\n",
      "V1,V2 = symbols('V1 V2')\n",
      "solve([(9*V1)-(5*V2)-10,(-5*V1)+(11*V2)-52], [V1,V2]) "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "The nodal voltages V1 and V2 are expressed in Volts.\n"
       ]
      },
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 11,
       "text": [
        "{V1: 5, V2: 7}"
       ]
      }
     ],
     "prompt_number": 11
    }
   ],
   "metadata": {}
  }
 ]
}