# 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
# 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)
# 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)
# 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)
# 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
# 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)
# 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)
# 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
# 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
c=100;#capacitance in micro farads
#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)
# 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"
# 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)
x=integrate.quad(function,t1,t2)[0];#variable
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)
# 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
# Example 2.13 :reading
#calculate the voltage 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 V2 is,(V)",round(v2,3)
print "reading V4 is ",round(v3+v2,3)," V or ",round(v3-v2,3)," V"
# 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
c=(1/(z.real*t));#capacitance in farads
#results
print "Impedance is ,(Ohm)=",z
print "capacitance is ,(micro-farads)=",c*10**6
# 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