# Chapter 2 : Electric Circuits¶

## Example 1 : pg 6¶

In [2]:
# Example 2.1 :current
#calculate the current
# given :
import numpy
#15*I1-5*I2=10 loop 1 equation
#20*I2-5*I1-5*I3=0 loop 2 equation
#10*I3-5*I2=0 loop 3 equation
vs=10.;#voltage in volts
R1=10.;#resistance in ohm
R2=5.;#resistance in ohm
R3=10.;#resistance in ohm
R4=5.;#resistance in ohm
R5=4.;#resistance in ohm
Ra=1.;#resistance in ohm
#calculations
A=([[R1+R2, R2-R1, 0],[R2-R1, R2+R3+R4, -R4],[R4-(R5+Ra), -R4, R4+R5+Ra]]);#making equations
nb=7.;#number of branches
nn=5.;#number of nodes
nl=nb-(nn-1);#number of loops
nvs=1.;#number of voltage sources
nivs=nn-1-nvs;#number of independent voltage variables
B=([[vs],[0],[0]]);#making equations
X=numpy.dot(numpy.linalg.inv(A),B);#solving equations
I3=X[2,0];#calculating currrent
#results
print "current in resistance Ra=1.0 ohm is ,(A)=",round(I3,3)
#directions of the current are 2 to 3 and 3 to 4 respectively

current in resistance Ra=1.0 ohm is ,(A)= 0.105


## Example 2 : pg 6¶

In [3]:
# Example 2.2 :current
#calculate the current in both cases
import numpy
# given :
vs1=72.;#voltage in volts
vs2=40.;#voltage in volts
R1=36.;#resistance in ohm
R2=10.;#resistance in ohm
ig=2.;#current in amperes
Rx=8.;#resistance in ohm
#calculations
#(va-72)/36+(va-40)/10 -2 +va/8=0 node equation at 1
va=((R2*Rx*vs1)+(R1*Rx*vs2)+(R1*R2*Rx*ig))/((R2*Rx)+(R1*Rx)+(R1*R2));#voltage in volts
ix1=va/Rx;#current in amperes
#(R1+R2)*I1-R2*I2+vs2=vs1 loop equation 1
#R2*I2-R2*I1+Ix*Rx=vs2 loop equation 2
#Ix=I2+2
A=([[R1+R2, -R2],[-R2, R2+Rx]]);#making equations
B=([[vs1-vs2],[vs2-2*Rx]]);#making equations
X=numpy.dot(numpy.linalg.inv(A),B);#solving equations
ix2=X[1,0]+ig;#current in amperes
print "current through Rx is(by node voltage method), (A)=",round(ix1,3)
print "current through Rx is (by loop current method),(A) =",round(ix2,3)

current through Rx is(by node voltage method), (A)= 3.956
current through Rx is (by loop current method),(A) = 3.956


## Example 3 : pg 7¶

In [4]:
# Example 2.3 :current
#calculate the current
import numpy
# given :
vs1=10;#voltage in volts
i5=2;#current in amperes
i2=i5;#current
r1=1;#resistance in ohms
r2=5;#resistance in ohms
r3=5;#resistance in ohms
rl=10;#resistance in ohms
r4=5;#resistance ohms
#calculations
#(r1+r2+r3)*i1-r2*i2-r3*i3=vs1 loop equaion 1
#-r2*i1-(r1+r2)*i2+(rl+r2+r3)*i3=0 loop equation 2
A=([[4*(r1+r2+r3), -r2*4],[-r2, (rl+r2+r3)]]);#making equations
B=([[4*(vs1+r2*i2)],[i2*(r2+r3)]]);#making equations
X=numpy.dot(numpy.linalg.inv(A),B);#solving equations
il=i2-X[1,0];#calculating current
#results
print "current through Rl is (from b to a),(A)=",round(il,3)

current through Rl is (from b to a),(A)= 0.359


## Example 4 : pg 8¶

In [5]:
# Example 2.4 :current
#calculate the current
# given :
vs1=72.;#voltage in volts
vs2=40.;#voltage in volts
R1=36.;#resistance in ohms
R2=10.;#resistance in ohms
ig=2.;#current in amperes
Rx=8.;#resistance in ohms
#calculations and results
print "Applying Thevenins Theorem "
#(vs1-voc)/R1+(v40-voc)/R2 +2 =0 node equation at 1
voc=(R2*vs1+R1*vs2+R1*R2*ig)/(R1+R2);#voltage in volts
req=(R1*R2)/(R1+R2);#resistance in ohms
ix1=(voc)/(req+Rx);#resistance in ohms
print "current through Rx is, (A)",round(ix1,3)
print "Applying Nortons Theorem "
Is=(vs1/R1)+(vs2/R2)+ig;#current in amperes
ix2=(req*(Is/(Rx+req)));#current in amperes
print "current through Rx is, (A) =",round(ix2,3)

Applying Thevenins Theorem
current through Rx is, (A) 3.956
Applying Nortons Theorem
current through Rx is, (A) = 3.956


## Example 5 : pg 8¶

In [6]:
# Example 2.5 :Thevenin's and Norton's Equivalent
#calculate the current in all cases
# given :
vs1=10.;#voltage in volts
R1=50.;#resistance in ohms
R2=50.;#resistance in ohms
R3=25.;#resistance in ohms
#calculations and results
print "(a) Applying Thevenins Theorem "
voc=(R1/(R1+R2))*vs1;#voltage in volts
req=((R1*R2)/(R1+R2))+R3;#resistance in ohms
print "Thevenin equivalent open circuit voltage is, (V)=",voc
print "Thevenin equivalent resistance is,(Ohm)=",req
print "(b) Applying Nortons Theorem "
Isc=((vs1)/(R1+(R1*R3)/(R1+R3)))*(R1/(R1+R3));#
req=((R1*R2)/(R1+R2))+R3;#resistance in ohms
print "Norton short circuit current is,(A)=",Isc
print "Norton equivalent resistance is,(Ohm)=",req

(a) Applying Thevenins Theorem
Thevenin equivalent open circuit voltage is, (V)= 5.0
Thevenin equivalent resistance is,(Ohm)= 50.0
(b) Applying Nortons Theorem
Norton short circuit current is,(A)= 0.1
Norton equivalent resistance is,(Ohm)= 50.0


## Example 6 : pg 10¶

In [7]:
# Example 2.6 :current
#calculate the current
# given :
vs1=10.;#voltage volts
r1=100.;#resistance in ohms
r2=600.;#resistance in ohms
r3=150.;#resistance in ohms
r4=850.;#resistance in ohms
rx=50.;#resistance in ohms
#calculations
voc=vs1*((r3/(r1+r3))-(r4/(r2+r4)));#open circuit voltage in volts
req=((r1*r3)/(r1+r3))+((r2*r4)/(r2+r4));#equivalent resistance in ohms
ix=voc/(req+rx)*10**3;#current in amperes
#results
print "current through Rx is (from A to B),(mA)=",round(ix,3)

current through Rx is (from A to B),(mA)= 0.299


## Example 7 : pg 11¶

In [8]:
# Example 2.7 :
#calculate the Norton's Equivalent
# given :
vs1=40.;#volts
vs2=20.;#volts
r1=2.;#resistance in ohms
r2=6.;#resistance in ohms
r3=2.;#resistance in ohms
r4=2.;#resistance in ohms
#calculations
iab=((r1*vs1)/(r2+(r1/2))*((r1+(r3/2))/(r1+r3)));#current in amperes
iab1=-vs2/r1;#current amperes
it=iab+iab1;#current amperes
req1=r1+((r1*r2)/(r1+r2));#equivalent resistance in ohms
req=(req1*r3)/(req1+r3);#equivalent resistance in ohms
#results
print "current is,(A)",round(it,3)
print "equivalent resistance is,(ohm)=",round(req,3)

current is,(A) -1.429
equivalent resistance is,(ohm)= 1.273


## Example 8 : pg 12¶

In [10]:
# Example 2.8:equation of current and time
#calculate the current
from math import exp,ceil
# given :
v=100.;#voltage in volts
r=100.;#resistance in ohms
l=0.2;#inductance in henrty
#calculations and results
T=1/(l/r);#calculating time in seconds
t=500.;#time in micro seconds
i1=1-exp(-T*t*10**-6);#current in amperes
print "current is (when t=500 micro seconds),(A)=",round(i1,3)
v2=50.;#voltage in volts
x=v2/r;#variable
x1=x*((v2/r)+i1);#variable
t1=t+(10**6*(x1/500.));#time in seconds
print "time at which current will be zero is,(micro-seconds)=",ceil(t1)
#time is caluclated wrong in the textbook as they had not added the values

current is (when t=500 micro seconds),(A)= 0.221
time at which current will be zero is,(micro-seconds)= 1222.0


## Example 9 : pg 15¶

In [11]:
# Example 2.9 :time
#calculate the time required
from math import log
# given :
v=10.;#voltage in volts
r1=500.;#resistance in ohms
ix=0.;#current in amperes
r=700;#resistance in ohms
#calculations
x=1/(r*c*10**-6);#variable
i=30;#current in mA
y=(i*10**-3)-(v/r1);#variable
t=-((log(y*(r/v))));#time in seconds
t1=t/x;#time in seconds
#results
print "time is ,(seconds)=",round(t1,3)

time is ,(seconds)= 0.025


## Example 10 : pg 18¶

In [12]:
# Example 2.10 :current equation
#calculate the current equation
# given :
from numpy import roots
v=100.;#volts
r=50.;#in ohms
l=0.1;#henry
c=50.;#mf
#calculations
p = ([1,500.0,2*10**5])
#p=2*10**5+500*d+d**2;
x=roots(p)
c1=0;#at t=0 i=0
c2=1000/x[0].imag;#
#results
print "it= ",round(c2,3),"*e^",x[0].real,"t*sin",round(x[0].imag,3),"t A"

it=  2.697 *e^ -250.0 t*sin 370.81 t A


## Example 11 : pg 19¶

In [13]:
# Example 2.11 :
#calculate the average & rms value
# given :
from numpy import linspace
from math import sin,pi,sqrt
from scipy import integrate
vm=10;#voltage in volts
e=vm/2;#voltage in volts
t=linspace(0,2, num=3);#time range
#x=intsplin(t,(5*t)**2);#variable
x=1.571;
#calculations and results
rms=sqrt(x/2);#rms value of voltage in volts
av=vm/2;#average value of voltage in volts
print "parts (a) saw tooth wave"
print "rms value of e is ,(V)=",round(rms,3)
print "average value of e is ,(V)=",av
t1=0;#initial time in seconds
t2=pi;#final time in seconds
t3=2*pi;#time interval
def function(t):
return sin(t) *sin(t);

def function2(t):
return sin(t)

rms=sqrt((1/(2*pi))*x*vm**2);#rms value of voltage in volts
av=(10/(2*pi))*integrate.quad(function2,t1,t2)[0];#average value of voltage in volts
print "parts (b) half wave rectified sine wave form"
print "rms value of e is ,(V)=",rms
print "average value of e is ,(V)=",round(av,3)

parts (a) saw tooth wave
rms value of e is ,(V)= 0.886
average value of e is ,(V)= 5
parts (b) half wave rectified sine wave form
rms value of e is ,(V)= 5.0
average value of e is ,(V)= 3.183


## Example 12 : pg 20¶

In [14]:
# Example 2.12 :
#calculate the Circuit constants
# given :
from math import sqrt, cos, sin,pi
#v=194*cos(800*t+150)V Voltage equation
#I=11.6*cos(800*t+140)A Current equation
vm=194/sqrt(2);#voltage in volts
va=150;#angle in degree
im=11.6/sqrt(2);#current in amperes
ia=140;#angle in degree
#calculations and results
zm=vm/im;#resistance in ohms
za=va-ia;#resistance in ohms
z1=zm*cos(za*pi/180.);#reactance in ohms
z2=zm*sin(za*pi/180.);#reactance in ohms
z=z1+1j*z2;#resistance in ohms
print "part (a)"
print "Impedance is ,(Ohm)=",z
print "part (b)"
#v=6*sin(1000*t+45)V  Voltage equation
#I=12*cos(1000t-90)A current equation
vm1=60/sqrt(2);#voltage in volts
va1=45;#angle in degree
im1=12/sqrt(2);#current in amperes
ia1=0;#angle in degree
zm1=vm1/im1;#resistance in ohms
za1=va1-ia1;#resistance in ohms
z11=zm1*cos(za1*pi/180.);#reactance in ohms
z21=zm1*sin(za1*pi/180.);#reactance in ohms
z22=z11+1j*z21;#impedance in ohms
print "Impedance is ,(Ohm)=",z22

part (a)
Impedance is ,(Ohm)= (16.4700606969+2.90411607477j)
part (b)
Impedance is ,(Ohm)= (3.53553390593+3.53553390593j)


## Example 13 : pg 22¶

In [15]:
# Example 2.13 :reading
# given :
from math import sqrt
v1=230.;#voltage in volts
v2=100.;#voltage in volts
#calculations
v2=sqrt(v1**2-v2**2);#voltage in volts
v3=300.;#voltage in volts
#results
print "reading V4 is ",round(v3+v2,3)," V or ",round(v3-v2,3)," V"

reading V2 is,(V) 207.123
reading V4 is  507.123  V or  92.877  V


## Example 14 : pg 25¶

In [16]:
# Example 2.14 :circuit elements
#calculate the circuit elements
# given :
from math import sqrt,cos,sin,pi
#v=311*sin(2500*t+170) V voltage equation
#I=15.5*sin(2500*t-145)A current equation
vm=311/sqrt(2);#voltage in volts
va=170.;#angle in degree
im=15.5/sqrt(2);#current in amperes
ia=-145.;#angle in degree
#calculations
zm=vm/im;#resistance in ohms
za=(va-ia)-360.;#resistance ohms
z1=zm*cos(za*pi/180.);#resistance in ohms
z2=zm*sin(za*pi/180.);#resistance in ohms
z=z1+1j*z2;#resistance in ohms
t=2500;#time in seconds
#results
print "Impedance is ,(Ohm)=",z

Impedance is ,(Ohm)= (14.1877554161-14.1877554161j)


## Example 15 : pg 26¶

In [17]:
# Example 2.15 :parameters
#calculate the parameters of phase, line voltage and current, power
from math import sqrt
# given :
z=40+1j*30;#resistance in ohms
zph=sqrt(z.real**2+z.imag**2);#resistance in ohms
pf=z.real/zph;#power factor
v=400;#voltage in volts
#calculations and results
vp=v/(sqrt(3));#voltage in volts
pc=vp/zph;#current in amperes
lv=v;#voltage in volts
lc=pc;#current om amperes
p=sqrt(3)*v*lc*pf;#power in watts
print "part (a) Star"
print "phase voltage,(V)=",round(vp)
print "phase current,(A)=",round(pc)
print "line voltage ,(V)=",lv
print "line current,(A)=",round(lc,3)
print "power ,(W)=",p
z1=40+1j*30;#ohms
zph1=sqrt(z1.real**2+z1.imag**2);#ohms
pf1=z1.real/zph1;#power factor
v1=400.;#volts
vp1=v1;#volts
pc1=vp1/zph1;#amperes
lv1=v1;#volts
lc1=pc1*sqrt(3);#amperes
p1=sqrt(3)*v1*lc1*pf1;#watts
print "part (b) Delta"
print "phase voltage,(V)=",round(vp1)
print "phase current,(A)=",round(pc1)
print "line voltage ,(V)=",lv1
print "line current,(A)=",round(lc1,3)
print "power ,(W)=",p1

part (a) Star
phase voltage,(V)= 231.0
phase current,(A)= 5.0
line voltage ,(V)= 400
line current,(A)= 4.619
power ,(W)= 2560.0
part (b) Delta
phase voltage,(V)= 400.0
phase current,(A)= 8.0
line voltage ,(V)= 400.0
line current,(A)= 13.856
power ,(W)= 7680.0