{
 "metadata": {
  "name": "",
  "signature": "sha256:aec700ae8e541452237ee9c0f10eb2b8642d7039520473250339382162750967"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "9: Varying and alternating currents"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 9.1, Page number 242"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "L=0.1;   #inductance(H)\n",
      "R=10;   #resistance(ohm)\n",
      "t1=0;   #time(sec)\n",
      "t2=0.002;   #time(sec)\n",
      "t3=0.04;   #time(sec)\n",
      "E=5;   #voltage(V)\n",
      "\n",
      "#Calculation\n",
      "tow=L/R;   #time(sec)\n",
      "a=E/R;\n",
      "i1=a*(1-math.exp(-t1/tow));    #current for t=0 sec(A)\n",
      "i2=a*(1-math.exp(-t2/tow));    #current for t=0.002 sec(A)\n",
      "i3=a*(1-math.exp(-t3/tow));    #current for t=0.04 sec(A)\n",
      "i4=a*(1-math.exp(-tow/tow));    #current for t=tow sec(A)\n",
      "\n",
      "#Result\n",
      "print \"current for t=0 sec is\",i1,\"A\"\n",
      "print \"current for t=0.002 sec is\",round(i2,2),\"A\"\n",
      "print \"current for t=0.04 sec is\",round(i3,2),\"A\"\n",
      "print \"current for t=tow sec is\",round(i4,3),\"A\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "current for t=0 sec is 0.0 A\n",
        "current for t=0.002 sec is 0.09 A\n",
        "current for t=0.04 sec is 0.49 A\n",
        "current for t=tow sec is 0.316 A\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 9.2, Page number 243"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "L=0.5;   #inductance(H)\n",
      "R=5;   #resistance(ohm)\n",
      "E=2;   #voltage(V)\n",
      "t=0.2;   #time(sec)\n",
      "\n",
      "#Calculation\n",
      "tow=L/R;   #time(sec)\n",
      "a=E/R;\n",
      "i=a*(1-math.exp(-t/tow));    #current(A)\n",
      "dibydt=(E-(R*i))/L;       #rate of growth of current(A/s)\n",
      "E=(1/2)*L*(i**2);     #energy stored by inductor(J)\n",
      "\n",
      "#Result\n",
      "print \"rate of growth of current is\",round(dibydt,2),\"A/s\"\n",
      "print \"energy stored by inductor is\",round(E,2),\"J\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "rate of growth of current is 0.54 A/s\n",
        "energy stored by inductor is 0.03 J\n"
       ]
      }
     ],
     "prompt_number": 8
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 9.3, Page number 244"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "L=10;   #inductance(H)\n",
      "R=10;   #resistance(ohm)\n",
      "E=10;   #voltage(V)\n",
      "t1=0.3;   #time(sec)\n",
      "t2=0.5;   #time(sec)\n",
      "t3=1;   #time(sec)\n",
      "\n",
      "#Calculation\n",
      "tow=L/R;   #time(sec)\n",
      "i0=E/R;\n",
      "i1=i0*math.exp(-t1/tow);    #current for t=0.3 sec(A)\n",
      "i2=i0*math.exp(-t2/tow);    #current for t=0.5 sec(A)\n",
      "i3=i0*math.exp(-t3/tow);    #current for t=1 sec(A)\n",
      "\n",
      "#Result\n",
      "print \"current for t=0.3 sec is\",round(i1,2),\"A\"\n",
      "print \"current for t=0.5 sec is\",round(i2,2),\"A\"\n",
      "print \"current for t=1 sec is\",round(i3,2),\"A\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "current for t=0.3 sec is 0.74 A\n",
        "current for t=0.5 sec is 0.61 A\n",
        "current for t=1 sec is 0.37 A\n"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 9.4, Page number 250"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "E=5;   #voltage(V)\n",
      "C=2*10**-6;   #capacitor(F)\n",
      "R=1*10**6;    #resistance(ohm)\n",
      "t=1;   #time(sec)\n",
      "v=40/100;     #decay value(%)\n",
      "\n",
      "#Calculation\n",
      "q=E*C*(1-math.exp(-t/(R*C)));     #charge on plates(C)\n",
      "Vc=q/C;    #voltage drop across capacitor(V)\n",
      "i0=E/R;\n",
      "i=i0*math.exp(-t/(R*C));    #current in circuit(A)\n",
      "V=i*R;    #voltage drop across resistor(V)\n",
      "E=(1/2)*C*(Vc**2);     #energy stored by capacitor(J)\n",
      "tow=R*C;     #time constant(sec)\n",
      "t=2*math.log(1/v);     #time taken(sec)\n",
      "\n",
      "#Result\n",
      "print \"voltage drop across capacitor is\",round(Vc,2),\"V\"\n",
      "print \"current in circuit is\",int(i*10**6),\"micro A\"\n",
      "print \"voltage drop across resistor is\",int(V),\"V\"\n",
      "print \"energy stored by capacitor is\",round(E*10**6,1),\"*10**-6 J\"\n",
      "print \"time constant is\",tow,\"sec\"\n",
      "print \"time taken is\",round(t,4),\"sec\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "voltage drop across capacitor is 1.97 V\n",
        "current in circuit is 3 micro A\n",
        "voltage drop across resistor is 3 V\n",
        "energy stored by capacitor is 3.9 *10**-6 J\n",
        "time constant is 2.0 sec\n",
        "time taken is 1.8326 sec\n"
       ]
      }
     ],
     "prompt_number": 22
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 9.5, Page number 265"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "L=1*10**-3;    #inductance(H)\n",
      "C=0.1*10**-6;   #capacitor(F)\n",
      "R=1;    #resistance(ohm)\n",
      "\n",
      "#Calculation\n",
      "a=1/(L*C);\n",
      "b=(R**2)/(4*(L**2));   \n",
      "omega=math.sqrt(a-b);    #angular frequency(per sec)\n",
      "Q=omega*L/R;    #Q-factor\n",
      "\n",
      "#Result\n",
      "print \"angular frequency is\",round(omega),\"per sec\"\n",
      "print \"answer varies due to rounding off errors\"\n",
      "print \"Q-factor is\",round(Q)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "angular frequency is 99999.0 per sec\n",
        "answer varies due to rounding off errors\n",
        "Q-factor is 100.0\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 9.6, Page number 280"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "#v=7sin(314+pi/6)\n",
      "v=7;\n",
      "R=100;    #resistance(ohm)\n",
      "\n",
      "#Calculation\n",
      "Im=v/R;   #maximum current(A)\n",
      "Irms=Im/math.sqrt(2);   #rms value of current(A)\n",
      "Vrms=v/math.sqrt(2);\n",
      "P=Vrms*Irms;     #average power(W)\n",
      "\n",
      "#Result\n",
      "print \"maximum current is\",Im,\"A\"\n",
      "print \"rms value of current is\",round(Irms,2),\"A\"\n",
      "print \"average power is\",round(P,3),\"W\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "maximum current is 0.07 A\n",
        "rms value of current is 0.05 A\n",
        "average power is 0.245 W\n"
       ]
      }
     ],
     "prompt_number": 4
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 9.7, Page number 283"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "#V=7sin(314t+pi/6)\n",
      "v=7;\n",
      "omega=314;    \n",
      "L=0.05;   #inductance(H)\n",
      "\n",
      "#Calculation\n",
      "XL=omega*L;\n",
      "betaL=1/XL;    #susceptance(per ohm)\n",
      "i=v*betaL;     #current through inductor\n",
      "Im=i;\n",
      "Irms=Im/math.sqrt(2);    #rms current(A)\n",
      "P=0;     #power loss\n",
      "\n",
      "#Result\n",
      "print \"susceptance is\",round(betaL,4),\"per ohm\"\n",
      "print \"current through inductor is\",round(i,2),\"sin(314t-math.pi/3)\"\n",
      "print \"rms current is\",round(Irms,2),\"A\"\n",
      "print \"power loss is\",P"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "susceptance is 0.0637 per ohm\n",
        "current through inductor is 0.45 sin(314t-math.pi/3)\n",
        "rms current is 0.32 A\n",
        "power loss is 0\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 9.8, Page number 286"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "#V=7sin(314t+pi/6)\n",
      "v=7;\n",
      "omega=314;    \n",
      "C=0.05*10**-6;   #capacitance(F)\n",
      "\n",
      "#Calculation\n",
      "XC=1/(omega*C);    #value of XC \n",
      "i=v/XC;     #current through capacitor\n",
      "Im=i;\n",
      "Irms=Im/math.sqrt(2);    #rms current(A)\n",
      "P=0;     #power loss\n",
      "\n",
      "#Result\n",
      "print \"value of XC is\",round(XC/10**3,1),\"K ohm\"\n",
      "print \"current through capacitor is\",i*10**3,\"*10**-3 sin(314t+2*math.pi/3)\"\n",
      "print \"rms current is\",int(Irms*10**6),\"micro A\"\n",
      "print \"power loss is\",P"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "value of XC is 63.7 K ohm\n",
        "current through capacitor is 0.1099 *10**-3 sin(314t+2*math.pi/3)\n",
        "rms current is 77 micro A\n",
        "power loss is 0\n"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 9.9, Page number 294"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "V1=110;      #voltage(V)\n",
      "P=40;    #power(W)\n",
      "V2=230;      #voltage(V)\n",
      "\n",
      "#Calculation\n",
      "RB=V1**2/P;    #resistance of bulb(ohm)\n",
      "i=V1/RB;    #electric current through bulb(A)\n",
      "Z=V2/i;    #series resistance(ohm)\n",
      "R=Z-RB;    #pure resistance(ohm)\n",
      "XL=math.sqrt((Z**2)-(RB**2));    \n",
      "L=XL/314;      #inductance(H)\n",
      "\n",
      "#Result\n",
      "print \"pure resistance is\",R,\"ohm\"\n",
      "print \"inductance is\",round(L,3),\"H\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "pure resistance is 330.0 ohm\n",
        "inductance is 1.769 H\n"
       ]
      }
     ],
     "prompt_number": 19
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 9.10, Page number 311"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "C=10**-6;    #capacitance(F)\n",
      "L=10*10**-3;    #inductance(H)\n",
      "R=1*10**3;    #resistance(ohm)\n",
      "\n",
      "#Calculation\n",
      "fr=1/(2*math.pi*math.sqrt(L*C));       #resonant frequency(Hz)\n",
      "Z=L/(C*R);       #impedence(ohm)\n",
      "\n",
      "#Result\n",
      "print \"resonant frequency is\",round(fr/10**3,3),\"KHz\"\n",
      "print \"impedence is\",Z,\"ohm\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "resonant frequency is 1.592 KHz\n",
        "impedence is 10.0 ohm\n"
       ]
      }
     ],
     "prompt_number": 23
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 9.11, Page number 312"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "C=5*10**-6;    #capacitance(F)\n",
      "R=10;    #resistance(ohm)\n",
      "new=50;    #frequency(Hz)\n",
      "\n",
      "#Calculation\n",
      "omega=2*math.pi*new;\n",
      "L=1/(C*(omega**2));       #self inductance(H)\n",
      "\n",
      "#Result\n",
      "print \"self inductance is\",round(L,3),\"H\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "self inductance is 2.026 H\n"
       ]
      }
     ],
     "prompt_number": 25
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 9.12, Page number 312"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "C=0.1*10**-6;    #capacitance(F)\n",
      "L=1*10**-3;    #inductance(H)\n",
      "R=10;    #resistance(ohm)\n",
      "\n",
      "#Calculation\n",
      "omega0=1/math.sqrt(L*C);       #resonant frequency(rad/sec)\n",
      "d=R/L;    #difference between two half power points\n",
      "cosphi=R/R;    #power factor at resonance\n",
      "\n",
      "#Result\n",
      "print \"resonant frequency is\",omega0/10**5,\"*10**5 rad/sec\"\n",
      "print \"power factor at resonance is\",cosphi"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "resonant frequency is 1.0 *10**5 rad/sec\n",
        "power factor at resonance is 1.0\n"
       ]
      }
     ],
     "prompt_number": 28
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 9.13, Page number 313"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "C=0.1*10**-6;    #capacitance(F)\n",
      "L=10*10**-3;    #inductance(H)\n",
      "R=10;    #resistance(ohm)\n",
      "\n",
      "#Calculation\n",
      "Z=L/(C*R);       #impedence at resonance(ohm)\n",
      "\n",
      "#Result\n",
      "print \"impedence at resonance is\",Z/10**4,\"*10**4 ohm\""
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "impedence at resonance is 1.0 *10**4 ohm\n"
       ]
      }
     ],
     "prompt_number": 30
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example number 9.14, Page number 313"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "#importing modules\n",
      "import math\n",
      "from __future__ import division\n",
      "\n",
      "#Variable declaration\n",
      "C=5*10**-6;    #capacitance(F)\n",
      "L=10*10**-3;    #inductance(H)\n",
      "R=10*10**3;    #resistance(ohm)\n",
      "\n",
      "#Calculation\n",
      "omegar=1/math.sqrt(L*C);       #resonant frequency(Hz)\n",
      "omegar=round(omegar/10**3,1);\n",
      "delta_omega=1/(R*C);      #bandwidth(Hz)\n",
      "Q=omegar*10**3/delta_omega;     #Q-factor\n",
      "\n",
      "#Result\n",
      "print \"resonant frequency is\",omegar,\"*10**3 Hz\"\n",
      "print \"bandwidth is\",delta_omega,\"Hz\"\n",
      "print \"Q-factor is\",Q"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "resonant frequency is 4.5 *10**3 Hz\n",
        "bandwidth is 20.0 Hz\n",
        "Q-factor is 225.0\n"
       ]
      }
     ],
     "prompt_number": 36
    }
   ],
   "metadata": {}
  }
 ]
}