{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Chapter 2 : Electric Circuits" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 1 : pg 6" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "current in resistance Ra=1.0 ohm is ,(A)= 0.105\n" ] } ], "source": [ "# Example 2.1 :current\n", "#calculate the current \n", "# given :\n", "import numpy\n", "#15*I1-5*I2=10 loop 1 equation\n", "#20*I2-5*I1-5*I3=0 loop 2 equation\n", "#10*I3-5*I2=0 loop 3 equation\n", "vs=10.;#voltage in volts\n", "R1=10.;#resistance in ohm\n", "R2=5.;#resistance in ohm\n", "R3=10.;#resistance in ohm\n", "R4=5.;#resistance in ohm\n", "R5=4.;#resistance in ohm\n", "Ra=1.;#resistance in ohm\n", "#calculations\n", "A=([[R1+R2, R2-R1, 0],[R2-R1, R2+R3+R4, -R4],[R4-(R5+Ra), -R4, R4+R5+Ra]]);#making equations\n", "nb=7.;#number of branches\n", "nn=5.;#number of nodes\n", "nl=nb-(nn-1);#number of loops\n", "nvs=1.;#number of voltage sources\n", "nivs=nn-1-nvs;#number of independent voltage variables\n", "B=([[vs],[0],[0]]);#making equations\n", "X=numpy.dot(numpy.linalg.inv(A),B);#solving equations\n", "I3=X[2,0];#calculating currrent\n", "#results\n", "print \"current in resistance Ra=1.0 ohm is ,(A)=\",round(I3,3)\n", "#directions of the current are 2 to 3 and 3 to 4 respectively\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 2 : pg 6" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "current through Rx is(by node voltage method), (A)= 3.956\n", "current through Rx is (by loop current method),(A) = 3.956\n" ] } ], "source": [ "# Example 2.2 :current\n", "#calculate the current in both cases\n", "import numpy\n", "# given :\n", "vs1=72.;#voltage in volts\n", "vs2=40.;#voltage in volts\n", "R1=36.;#resistance in ohm\n", "R2=10.;#resistance in ohm\n", "ig=2.;#current in amperes\n", "Rx=8.;#resistance in ohm\n", "#calculations\n", "#(va-72)/36+(va-40)/10 -2 +va/8=0 node equation at 1\n", "va=((R2*Rx*vs1)+(R1*Rx*vs2)+(R1*R2*Rx*ig))/((R2*Rx)+(R1*Rx)+(R1*R2));#voltage in volts\n", "ix1=va/Rx;#current in amperes\n", "#(R1+R2)*I1-R2*I2+vs2=vs1 loop equation 1\n", "#R2*I2-R2*I1+Ix*Rx=vs2 loop equation 2\n", "#Ix=I2+2\n", "A=([[R1+R2, -R2],[-R2, R2+Rx]]);#making equations\n", "B=([[vs1-vs2],[vs2-2*Rx]]);#making equations\n", "X=numpy.dot(numpy.linalg.inv(A),B);#solving equations\n", "ix2=X[1,0]+ig;#current in amperes\n", "print \"current through Rx is(by node voltage method), (A)=\",round(ix1,3)\n", "print \"current through Rx is (by loop current method),(A) =\",round(ix2,3)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 3 : pg 7" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "current through Rl is (from b to a),(A)= 0.359\n" ] } ], "source": [ "# Example 2.3 :current\n", "#calculate the current\n", "import numpy\n", "# given :\n", "vs1=10;#voltage in volts\n", "i5=2;#current in amperes\n", "i2=i5;#current\n", "r1=1;#resistance in ohms\n", "r2=5;#resistance in ohms\n", "r3=5;#resistance in ohms\n", "rl=10;#resistance in ohms\n", "r4=5;#resistance ohms\n", "#calculations\n", "#(r1+r2+r3)*i1-r2*i2-r3*i3=vs1 loop equaion 1\n", "#-r2*i1-(r1+r2)*i2+(rl+r2+r3)*i3=0 loop equation 2\n", "A=([[4*(r1+r2+r3), -r2*4],[-r2, (rl+r2+r3)]]);#making equations\n", "B=([[4*(vs1+r2*i2)],[i2*(r2+r3)]]);#making equations\n", "X=numpy.dot(numpy.linalg.inv(A),B);#solving equations\n", "il=i2-X[1,0];#calculating current\n", "#results\n", "print \"current through Rl is (from b to a),(A)=\",round(il,3)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 4 : pg 8" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Applying Thevenins Theorem \n", "current through Rx is, (A) 3.956\n", "Applying Nortons Theorem \n", "current through Rx is, (A) = 3.956\n" ] } ], "source": [ "# Example 2.4 :current\n", "#calculate the current\n", "# given :\n", "vs1=72.;#voltage in volts\n", "vs2=40.;#voltage in volts\n", "R1=36.;#resistance in ohms\n", "R2=10.;#resistance in ohms\n", "ig=2.;#current in amperes\n", "Rx=8.;#resistance in ohms\n", "#calculations and results\n", "print \"Applying Thevenins Theorem \"\n", "#(vs1-voc)/R1+(v40-voc)/R2 +2 =0 node equation at 1\n", "voc=(R2*vs1+R1*vs2+R1*R2*ig)/(R1+R2);#voltage in volts\n", "req=(R1*R2)/(R1+R2);#resistance in ohms\n", "ix1=(voc)/(req+Rx);#resistance in ohms\n", "print \"current through Rx is, (A)\",round(ix1,3)\n", "print \"Applying Nortons Theorem \"\n", "Is=(vs1/R1)+(vs2/R2)+ig;#current in amperes\n", "ix2=(req*(Is/(Rx+req)));#current in amperes\n", "print \"current through Rx is, (A) =\",round(ix2,3)\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 5 : pg 8" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(a) Applying Thevenins Theorem \n", "Thevenin equivalent open circuit voltage is, (V)= 5.0\n", "Thevenin equivalent resistance is,(Ohm)= 50.0\n", "(b) Applying Nortons Theorem \n", "Norton short circuit current is,(A)= 0.1\n", "Norton equivalent resistance is,(Ohm)= 50.0\n" ] } ], "source": [ "# Example 2.5 :Thevenin's and Norton's Equivalent\n", "#calculate the current in all cases\n", "# given :\n", "vs1=10.;#voltage in volts\n", "R1=50.;#resistance in ohms\n", "R2=50.;#resistance in ohms\n", "R3=25.;#resistance in ohms\n", "#calculations and results\n", "print \"(a) Applying Thevenins Theorem \"\n", "voc=(R1/(R1+R2))*vs1;#voltage in volts\n", "req=((R1*R2)/(R1+R2))+R3;#resistance in ohms\n", "print \"Thevenin equivalent open circuit voltage is, (V)=\",voc\n", "print \"Thevenin equivalent resistance is,(Ohm)=\",req\n", "print \"(b) Applying Nortons Theorem \"\n", "Isc=((vs1)/(R1+(R1*R3)/(R1+R3)))*(R1/(R1+R3));#\n", "req=((R1*R2)/(R1+R2))+R3;#resistance in ohms\n", "print \"Norton short circuit current is,(A)=\",Isc\n", "print \"Norton equivalent resistance is,(Ohm)=\",req\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 6 : pg 10" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "current through Rx is (from A to B),(mA)= 0.299\n" ] } ], "source": [ "# Example 2.6 :current\n", "#calculate the current \n", "# given :\n", "vs1=10.;#voltage volts\n", "r1=100.;#resistance in ohms\n", "r2=600.;#resistance in ohms\n", "r3=150.;#resistance in ohms\n", "r4=850.;#resistance in ohms\n", "rx=50.;#resistance in ohms\n", "#calculations\n", "voc=vs1*((r3/(r1+r3))-(r4/(r2+r4)));#open circuit voltage in volts\n", "req=((r1*r3)/(r1+r3))+((r2*r4)/(r2+r4));#equivalent resistance in ohms\n", "ix=voc/(req+rx)*10**3;#current in amperes\n", "#results\n", "print \"current through Rx is (from A to B),(mA)=\",round(ix,3)\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 7 : pg 11" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "current is,(A) -1.429\n", "equivalent resistance is,(ohm)= 1.273\n" ] } ], "source": [ "# Example 2.7 :\n", "#calculate the Norton's Equivalent\n", "# given :\n", "vs1=40.;#volts\n", "vs2=20.;#volts\n", "r1=2.;#resistance in ohms\n", "r2=6.;#resistance in ohms\n", "r3=2.;#resistance in ohms\n", "r4=2.;#resistance in ohms\n", "#calculations\n", "iab=((r1*vs1)/(r2+(r1/2))*((r1+(r3/2))/(r1+r3)));#current in amperes\n", "iab1=-vs2/r1;#current amperes\n", "it=iab+iab1;#current amperes\n", "req1=r1+((r1*r2)/(r1+r2));#equivalent resistance in ohms\n", "req=(req1*r3)/(req1+r3);#equivalent resistance in ohms\n", "#results\n", "print \"current is,(A)\",round(it,3)\n", "print \"equivalent resistance is,(ohm)=\",round(req,3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 8 : pg 12" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "current is (when t=500 micro seconds),(A)= 0.221\n", "time at which current will be zero is,(micro-seconds)= 1222.0\n" ] } ], "source": [ "# Example 2.8:equation of current and time\n", "#calculate the current \n", "from math import exp,ceil\n", "# given :\n", "v=100.;#voltage in volts\n", "r=100.;#resistance in ohms\n", "l=0.2;#inductance in henrty\n", "#calculations and results\n", "T=1/(l/r);#calculating time in seconds\n", "t=500.;#time in micro seconds\n", "i1=1-exp(-T*t*10**-6);#current in amperes\n", "print \"current is (when t=500 micro seconds),(A)=\",round(i1,3)\n", "v2=50.;#voltage in volts\n", "x=v2/r;#variable\n", "x1=x*((v2/r)+i1);#variable \n", "t1=t+(10**6*(x1/500.));#time in seconds\n", "print \"time at which current will be zero is,(micro-seconds)=\",ceil(t1)\n", "#time is caluclated wrong in the textbook as they had not added the values\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 9 : pg 15" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "time is ,(seconds)= 0.025\n" ] } ], "source": [ "# Example 2.9 :time\n", "#calculate the time required\n", "from math import log\n", "# given :\n", "v=10.;#voltage in volts\n", "r1=500.;#resistance in ohms\n", "ix=0.;#current in amperes\n", "r=700;#resistance in ohms\n", "c=100;#capacitance in micro farads\n", "#calculations\n", "x=1/(r*c*10**-6);#variable\n", "i=30;#current in mA\n", "y=(i*10**-3)-(v/r1);#variable\n", "t=-((log(y*(r/v))));#time in seconds\n", "t1=t/x;#time in seconds\n", "#results\n", "print \"time is ,(seconds)=\",round(t1,3)\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 10 : pg 18" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "it= 2.697 *e^ -250.0 t*sin 370.81 t A\n" ] } ], "source": [ "# Example 2.10 :current equation\n", "#calculate the current equation\n", "# given :\n", "from numpy import roots\n", "v=100.;#volts\n", "r=50.;#in ohms\n", "l=0.1;#henry\n", "c=50.;#mf\n", "#calculations\n", "p = ([1,500.0,2*10**5])\n", "#p=2*10**5+500*d+d**2;\n", "x=roots(p)\n", "c1=0;#at t=0 i=0\n", "c2=1000/x[0].imag;#\n", "#results\n", "print \"it= \",round(c2,3),\"*e^\",x[0].real,\"t*sin\",round(x[0].imag,3),\"t A\"\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 11 : pg 19" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "parts (a) saw tooth wave\n", "rms value of e is ,(V)= 0.886\n", "average value of e is ,(V)= 5\n", "parts (b) half wave rectified sine wave form\n", "rms value of e is ,(V)= 5.0\n", "average value of e is ,(V)= 3.183\n" ] } ], "source": [ "# Example 2.11 :\n", "#calculate the average & rms value\n", "# given :\n", "from numpy import linspace\n", "from math import sin,pi,sqrt\n", "from scipy import integrate\n", "vm=10;#voltage in volts\n", "e=vm/2;#voltage in volts\n", "t=linspace(0,2, num=3);#time range\n", "#x=intsplin(t,(5*t)**2);#variable\n", "x=1.571;\n", "#calculations and results\n", "rms=sqrt(x/2);#rms value of voltage in volts\n", "av=vm/2;#average value of voltage in volts\n", "print \"parts (a) saw tooth wave\"\n", "print \"rms value of e is ,(V)=\",round(rms,3)\n", "print \"average value of e is ,(V)=\",av\n", "t1=0;#initial time in seconds\n", "t2=pi;#final time in seconds\n", "t3=2*pi;#time interval\n", "def function(t):\n", " return sin(t) *sin(t);\n", "\n", "def function2(t):\n", " return sin(t)\n", " \n", "x=integrate.quad(function,t1,t2)[0];#variable\n", "rms=sqrt((1/(2*pi))*x*vm**2);#rms value of voltage in volts\n", "av=(10/(2*pi))*integrate.quad(function2,t1,t2)[0];#average value of voltage in volts\n", "print \"parts (b) half wave rectified sine wave form\"\n", "print \"rms value of e is ,(V)=\",rms\n", "print \"average value of e is ,(V)=\",round(av,3)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 12 : pg 20" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "part (a)\n", "Impedance is ,(Ohm)= (16.4700606969+2.90411607477j)\n", "part (b)\n", "Impedance is ,(Ohm)= (3.53553390593+3.53553390593j)\n" ] } ], "source": [ "# Example 2.12 :\n", "#calculate the Circuit constants\n", "# given :\n", "from math import sqrt, cos, sin,pi\n", "#v=194*cos(800*t+150)V Voltage equation\n", "#I=11.6*cos(800*t+140)A Current equation\n", "vm=194/sqrt(2);#voltage in volts\n", "va=150;#angle in degree\n", "im=11.6/sqrt(2);#current in amperes\n", "ia=140;#angle in degree\n", "#calculations and results\n", "zm=vm/im;#resistance in ohms\n", "za=va-ia;#resistance in ohms\n", "z1=zm*cos(za*pi/180.);#reactance in ohms\n", "z2=zm*sin(za*pi/180.);#reactance in ohms\n", "z=z1+1j*z2;#resistance in ohms\n", "print \"part (a)\"\n", "print \"Impedance is ,(Ohm)=\",z\n", "print \"part (b)\"\n", "#v=6*sin(1000*t+45)V Voltage equation\n", "#I=12*cos(1000t-90)A current equation\n", "vm1=60/sqrt(2);#voltage in volts\n", "va1=45;#angle in degree\n", "im1=12/sqrt(2);#current in amperes\n", "ia1=0;#angle in degree\n", "zm1=vm1/im1;#resistance in ohms\n", "za1=va1-ia1;#resistance in ohms\n", "z11=zm1*cos(za1*pi/180.);#reactance in ohms\n", "z21=zm1*sin(za1*pi/180.);#reactance in ohms\n", "z22=z11+1j*z21;#impedance in ohms\n", "print \"Impedance is ,(Ohm)=\",z22\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 13 : pg 22" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "reading V2 is,(V) 207.123\n", "reading V4 is 507.123 V or 92.877 V\n" ] } ], "source": [ "# Example 2.13 :reading\n", "#calculate the voltage reading\n", "# given :\n", "from math import sqrt\n", "v1=230.;#voltage in volts\n", "v2=100.;#voltage in volts\n", "#calculations\n", "v2=sqrt(v1**2-v2**2);#voltage in volts\n", "v3=300.;#voltage in volts\n", "#results\n", "print \"reading V2 is,(V)\",round(v2,3)\n", "print \"reading V4 is \",round(v3+v2,3),\" V or \",round(v3-v2,3),\" V\"\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 14 : pg 25" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Impedance is ,(Ohm)= (14.1877554161-14.1877554161j)\n", "capacitance is ,(micro-farads)= 28.1933250377\n" ] } ], "source": [ "# Example 2.14 :circuit elements\n", "#calculate the circuit elements\n", "# given :\n", "from math import sqrt,cos,sin,pi\n", "#v=311*sin(2500*t+170) V voltage equation\n", "#I=15.5*sin(2500*t-145)A current equation\n", "vm=311/sqrt(2);#voltage in volts\n", "va=170.;#angle in degree\n", "im=15.5/sqrt(2);#current in amperes\n", "ia=-145.;#angle in degree\n", "#calculations\n", "zm=vm/im;#resistance in ohms\n", "za=(va-ia)-360.;#resistance ohms\n", "z1=zm*cos(za*pi/180.);#resistance in ohms\n", "z2=zm*sin(za*pi/180.);#resistance in ohms\n", "z=z1+1j*z2;#resistance in ohms\n", "t=2500;#time in seconds\n", "c=(1/(z.real*t));#capacitance in farads\n", "#results\n", "print \"Impedance is ,(Ohm)=\",z\n", "print \"capacitance is ,(micro-farads)=\",c*10**6\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example 15 : pg 26" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "part (a) Star\n", "phase voltage,(V)= 231.0\n", "phase current,(A)= 5.0\n", "line voltage ,(V)= 400\n", "line current,(A)= 4.619\n", "power ,(W)= 2560.0\n", "part (b) Delta\n", "phase voltage,(V)= 400.0\n", "phase current,(A)= 8.0\n", "line voltage ,(V)= 400.0\n", "line current,(A)= 13.856\n", "power ,(W)= 7680.0\n" ] } ], "source": [ "# Example 2.15 :parameters\n", "#calculate the parameters of phase, line voltage and current, power\n", "from math import sqrt\n", "# given :\n", "z=40+1j*30;#resistance in ohms\n", "zph=sqrt(z.real**2+z.imag**2);#resistance in ohms\n", "pf=z.real/zph;#power factor\n", "v=400;#voltage in volts\n", "#calculations and results\n", "vp=v/(sqrt(3));#voltage in volts\n", "pc=vp/zph;#current in amperes\n", "lv=v;#voltage in volts\n", "lc=pc;#current om amperes\n", "p=sqrt(3)*v*lc*pf;#power in watts\n", "print \"part (a) Star\"\n", "print \"phase voltage,(V)=\",round(vp)\n", "print \"phase current,(A)=\",round(pc)\n", "print \"line voltage ,(V)=\",lv\n", "print \"line current,(A)=\",round(lc,3)\n", "print \"power ,(W)=\",p\n", "z1=40+1j*30;#ohms\n", "zph1=sqrt(z1.real**2+z1.imag**2);#ohms\n", "pf1=z1.real/zph1;#power factor\n", "v1=400.;#volts\n", "vp1=v1;#volts\n", "pc1=vp1/zph1;#amperes\n", "lv1=v1;#volts\n", "lc1=pc1*sqrt(3);#amperes\n", "p1=sqrt(3)*v1*lc1*pf1;#watts\n", "print \"part (b) Delta\"\n", "print \"phase voltage,(V)=\",round(vp1)\n", "print \"phase current,(A)=\",round(pc1)\n", "print \"line voltage ,(V)=\",lv1\n", "print \"line current,(A)=\",round(lc1,3)\n", "print \"power ,(W)=\",p1\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.11" } }, "nbformat": 4, "nbformat_minor": 0 }