import math
from numpy import ones
def r2p(x,y): #function to convert recmath.tangular to polar
polar = ones(2)
polar[0] = math.sqrt ((x **2) +(y**2))
polar[1] = math.atan (y/x)
polar[1] = (polar [1]*180)/math.pi
return polar
def p2r(r,theta): #function to convert polar to recmath.tangular
rect = ones(2)
theta = ( theta *math.pi) /180
rect [0] = r* math.cos(theta)
rect [1] = r* math.sin(theta)
return rect
#CALCULATIONS
I1 = r2p(7,-5);
print (I1);
I2 = r2p(-9,6);
I2[1] = I2[1]+(180); #this belongs to quadrant 2 and hence 180 degrees should be added
print (I2);
I3 = r2p(-8,-8);
I3[1] = I3[1]+(180); #this belongs to quadrant 3 and hence 180 degrees should be added
print (I3);
I4 = r2p(6,6);
print (I4);
#note:here direct functions for converson are not available and hence we defined user defined functions for polar to rect and rect to polar conversions
import math
from numpy import ones
def r2p(x,y): #function to convert recmath.tangular to polar
polar = ones(2)
polar[0] = math.sqrt ((x **2) +(y**2))
polar[1] = math.atan (y/x)
polar[1] = (polar [1]*180)/math.pi
return polar
def p2r(r,theta): #function to convert polar to recmath.tangular
rect = ones(2)
theta = ( theta *math.pi) /180
rect [0] = r* math.cos(theta)
rect [1] = r* math.sin(theta)
return rect
#CALCULATIONS
#for subdivision 1
I1 = p2r(10,60);
I2 = p2r(8,-45);
I3 = I1+I2;
print (I3);
I4 = r2p(I3[0],I3[1]);
print (I4)
#for subdivision 2
I5 = r2p(5,4);
I6 = r2p(-4,-6);
I7 = ones(2)
I7[0] = (I5[0])*(I6[0]);
I7[1] = (I5[1]+I6[1]);
I7[1] = I7[1]-180;
print (I7);
#for subdivision 3
I8 = r2p(-2,-5);
I9 = r2p(5,7);
I10 = ones(2)
I10[0] = I8[0]/I9[0];
I10[1] = I8[1]-I9[1];
I10[1] = I10[1]-180
print (I10);
#note:here direct functions for converson are not available and hence we defined user defined functions for polar to rect and rect to polar conversions
import math
#given i(t) = 5*math.sin(314*t+(2*math.pi/3))&& v(t) = 20*math.sin(314*t+(5*math.pi/6))
#CALCULATIONS
P1 = 2*(math.pi/3); #phase angle of current in radians
P1 = P1*(180/math.pi); #phase angle of current in degrees
P2 = 5*(math.pi/6); #phase angle of voltage in radians
P2 = P2*(180/math.pi); #phase angle of voltage in degrees
P3 = P2-P1; #current lags voltage by P3 degrees
P4 = P3*math.pi/180;
pf = math.cos(P4); #lagging pf
Vm = 20; #peak voltage
Im = 5; #peak current
Z = Vm/Im; #impedance in ohms
R = (Z)*math.cos(P4); #resistance in ohms
Xl = math.sqrt((Z)**2-(R)**2); #reacmath.tance
W = 314;
L = Xl/W; #inductance in henry
V = Vm/math.sqrt(2); #average value of voltage
I = Im/math.sqrt(2); #average value of current
av = (V*I)*math.cos(P4); #average power in watts
print "thus impedance, resistance, inductance, powerfactor and average power are %d ohms, %1.2f ohms, %g H,%1.3f and %2.1f W respectively"%(Z,R,L,pf,av);
import math
#Chapter-5, Example 5.4, Page 161
#INPUT DATA
I = 10.; #given current in A
P = 1000.; #power in Watts
V = 250.; #voltage in volts
f = 25.; #frequency in Hz
#CALCULATIONS
R = P/((I)**2); #resistance in ohms
Z = V/I; #impedance in ohms
Xl = math.sqrt((Z)**2-(R)**2); #reacmath.tance in ohms
L = Xl/(2*math.pi*f); #inductance in Henry
Pf = R/Z; #power factor,lagging,pf = math.cos(phi)
# Results
print "thus impedance, resistance, inductance, reactance and powerfactor are %d ohms, %d ohms, %1.3f H, \
%2.2f ohms and %1.1f respectively"%(Z,R,L,Xl,Pf);
import math
#Chapter-5, Example 5.5, Page 162
#INPUT DATA
V = 250.; #supply voltage in volts
f = 50.; #frequency in hz
Vr = 125.; #voltage across resistance in volts
Vc = 200.; #voltage across coil in volts
I = 5.; #current in A
#CALCULATIONS
R = Vr/I; #resistance in ohms
Z1 = Vc/I; #impedance of coil in ohms
#Z1 = math.sqrt((R1)**2+(Xl)**2)------eqn(1)
Z = V/I; #total impedance in ohms
#Z = math.sqrt((R+R1)**2+(Xl)**2)-----eqn(2)
#solving eqn(1)and eqn(2) we get R1 as follows
R1 = (((Z)**2-(Z1)**2)-(R)**2)/(2*R); #in ohms
Xl = math.sqrt((Z1)**2-(R1)**2); #reacmath.tance of coil in ohms
P = ((I)**2*R1); #power absorbed by the coil in Watts
Pt = ((I)**2)*(R+R1); #total power in Watts
# Results
print "thus impedance, resistance, reactance are %d ohms, %d ohms, %2.2f ohms respectively"%(Z1,R,Xl);
print "power absorbed and total power are %3.1f W and %3.1f W respectively"%(P,Pt)
import math
#Chapter-5, Example 5.6, Page 163
#INPUT DATA
V = 240; #supply voltage in volts
Vl = 171; #voltage across inductor in volts
I = 3; #current in A
phi = 37; #power factor laggging in degrees
#CALCULATIONS
Zl = Vl/I; #impedance of coil in ohms
#Zl = math.sqrt((R1)**2+(Xl)**2)------eqn(1)
Z = V/I; #total impedance in ohms
#Z = math.sqrt((R+R1)**2+(Xl)**2)-----eqn(2)
pf = math.cos(phi*math.pi/180); #powerfactor
Rt = pf*Z; #total resistance in ohms #Rt = (R+R1)
#substituting Rt value in eqn(2) we find Xl as follows
Xl = math.sqrt((Z)**2-(Rt)**2); #reacmath.tance of inductor in ohms
#ubstituting Xl value in eqn(1) we find R1 as follows
R1 = math.sqrt((Zl)**2-(Xl)**2); #resistance of inductor in ohms
R = Rt-R1; #resistance of resistor in ohms
print "Thus resistance of resistor is %2.2f ohms"%(R);
print "Thus resisimath.tance and reacmath.tance of inductor are %2.2f ohms and %2.2f ohms respectively"%(R1,Xl)
import math
#Chapter-5, Example 5.7, Page 164
#INPUT DATA
V = 100; #supply voltage in volts
#for COIL A
f = 50; #frequency in Hz
I1 = 8; #current in A
P1 = 120; #power in Watts
#for COIL B
I2 = 10; #current in A
P2 = 500; #power in Watts
#CALCULATIONS
#FOR COIL A
Z1 = V/I1; #impedance of coil A in ohms
R1 = P1/(I1)**2; #resistance of coil A in ohms
X1 = math.sqrt(((Z1)**2-(R1)**2)); #reacmath.tance of coil A in ohms
#FOR COIL B
Z2 = V/I2; #impedance of coil B in ohms
R2 = P2/(I2)**2; #resistance of coil B in ohms
X2 = math.sqrt(((Z2)**2-(R2)**2)); #reacmath.tance of coil B in ohms
#When both COILS A and B are in series
Rt = R1+R2; #total resistance in ohms
Xt = X1+X2; #total reacmath.tance in ohms
Zt = math.sqrt((Rt)**2+(Xt)**2); #total impedance in ohms
It = V/Zt; #current drawn in A
P = ((It)**2)*(Rt); #power taken in watts
print "Thus current drawn and power taken in watts are %2.2f A and %3.2f W respectively"%(It,P);
import math
#Chapter-5, Example 5.8, Page 167
#INPUT DATA
R = 100; #resistance in ohms
C = 50*10**-6; #capacitance in F
V = 200; #voltage in Volts
f = 50; #frequency in Hz
#Z = R-(1j)*(Xc)------>impedance
Xc = 1/(2*math.pi*f*C); #capacitive reacmath.tance in ohms
Z = math.sqrt((R)**2+(Xc)**2); #impedance in ohms
I = V/Z; #current in A
pf = R/Z; #power factor ------>math.cos(phi)---->leading
phi = math.acos(0.844); #phase angle in radians
phi = phi*180/math.pi; #phase angle in degrees
Vr = (I)*(R); #voltage across resistor
Vc = (I)*(Xc); #votage across capacitor
print "Thus impedance, current, powerfactor and phaseangle are %3.2f ohms, %1.2f A, %1.3f and %2.2f degrees respectively"%(Z,I,pf,phi);
print "voltage across resistor and capacitor are %d V and %3.2f V respectively"%(Vr,Vc)
import math
#Chapter-5, Example 5.9, Page 169
#INPUT DATA
phi = 40; #phase in degrees
V = 150; #voltage in Volts
I = 8; #current in A
#the applied voltage lags behind the current .That means the current leads the voltage
#hence pf is leading
#CALCULATIONS
pf = math.cos(phi*math.pi/180); #in degrees--->leading
#hence it is a capacitive circuit
pa = V*I*pf; #active power in W
pr = V*I*math.sin(phi*math.pi/180); #reactive power in VAR
print "Thus active and reactive power are %3.1f W and %3.1f VAR respectively"%(pa,pr);
import math
#Chapter-5, Example 5.10, Page 169
#INPUT DATA
#given v = 141.4*math.sin(314*t)
P = 700.; #power in Watts
pf = 0.707; #powerfactor------>leading------>math.cos(phi)
Vm = 141.4; #maximum value of supply voltage
#CALCULATIONS
Vr = Vm/(math.sqrt(2)); #rms value of supply voltage
I = P/(Vr*pf); #current in A
Z = Vr/I; #impedance in ohms
R = (Z)*(pf); #resistance in ohms
phi = math.acos(pf)*180/math.pi; #angle in degrees
Xc = (Z)*(math.sin(phi)); #reacmath.tance in ohms
C = 1/(3.14*7.13); #capacitance in F
print "Thus resistance and capacitance are %1.2f ohms and %g F respectively"%(R,C);
import math
#Chapter-5, Example 5.11, Page 169
#INPUT DATA
V = 200.; #supply voltage in volts
f = 50.; #freq in hz
P = 7000.; #power in Watts
Vr = 130.; #volatge across resistor in volts
P = 7000.; #power in Watts
#CALCULATIONS
R = ((Vr)**2)/P; #resistance in ohms
I = Vr/R; #current in A
Z = V/I; #total impedance in ohms
Xc = math.sqrt((Z)**2-(R)**2);
C = 1/(2*math.pi*f*Xc); #capacitance in F
pf = R/Z; #power factor------>leading
phi = math.acos(pf); #angle in radians
phi = phi*180/math.pi; #angle in degrees
Vm = V*math.sqrt(2); #maximum value of voltage
#voltage equation v = Vm*math.sin(2*math.pi*f*t)------>282.84*math.sin(314.16*t)
#current leads voltage by phi
#current equation ------>i = 76.155*math.sin(314.16*t+phi)
print "Thus current, resistance, p.f, capacitance, impedance are %2.2f A , %1.2f ohms, %2.1f , \
%g F and %1.2f ohms respectively"%(I,R,pf,C,Z);
import math
#INPUT DATA
C = 50.; #capacitance in uf
R = 100.; #resistance in ohms
V = 200.; #supply voltage in volts
f = 50.; #freq in hz
#CALCULATIONS
Xc = 1/(2*math.pi*f*C*10**-6); #capacitive reacmath.tance in ohms
Z = R-((1j)*Xc); #impedance in ohms
print (Z);
z1 = math.sqrt((R)**2+(Xc)**2);
theta = math.atan(Xc/R);
pf = math.cos(theta); #powerfactor
I = V/z1; #current in A
P = V*I*pf; #power in Watts
print "Thus current, power factor, power are % 1.2f A ,%1.3f ,%d W respectively"%(I,pf,P);
import math
#INPUT DATA
C = 0.05; #capacitance in uf
F = 500; #freq in hz
#CALCULATIONS
Xl = 1/(2*math.pi*F*C*10**-6); #capacitive reacmath.tance in ohms
#at resonance Xl = Xc
L = (Xl/(2*math.pi*F)); #inductance in H
print "Thus value of L is %1.2f H"%(L);
import math
#INPUT DATA
V = 200; #voltage in V
R = 50; #resistance in ohms
L = 0.5; #inductance in Henry
F = 50; #freq in hz
#CALCULATIONS
Xl = 2*math.pi*F*L; #inductive reacmath.tance
Z = (R)+((1j)*Xl) #impedance
print (Z);
z1 = math.sqrt((R)**2+(Xl)**2); #magnitude
theta = math.atan(Xl/R); #angle in radians
I = V/z1; #current in A
P = V*I*math.cos(theta); #power supplied in W
#here capacitive reacmath.tance equals inductive reacmath.tance
#hence Xc = Xl
C = 1/(2*math.pi*F*Xl); #capacitance in uf
r = (V/I)-(R); #additional resistance to be added in series
print "Thus current and power required are % 1.2f A and %2.2f W respectively"%(I,P);
print "Thus additional resistance that neede to be connected in series with R and C to have\
same current at unity power factor is %1.1f ohms"%(r);
import math
#INPUT DATA
R = 50.; #resistance in ohms
L = 9.; #inductance in Henry
I0 = 1.; #current in A
f = 75.; #ferquency in Hz
#at resonance Xl = Xc
#CALCULATIONS
Xl = 2*math.pi*f*L; #inductive reacmath.tance
Xc = Xl; #capacitive reacmath.tance
C = 1/(2*math.pi*f*Xc); #capacitance in uf
print "Thus capacitance is %g F"%(C);
import math
#INPUT DATA
R = 10.; #resistance in ohms
L = 0.1; #inductance in Henry
C = 150.; #capacitor in uf
V = 200.; #voltage in V
f = 50.; #frequency in hz
#CALCULATIONS
Xc = 1/(2*math.pi*f*C*10**-6); #Capacitive reacmath.tance in ohms
Xl = (2*math.pi*f*L); #inductive reacmath.tance in ohms
Z = R+((1j)*(Xl-Xc)); #impedance in ohms
z1 = math.sqrt((R)**2+(Xl-Xc)**2); #magnitude of Z
I = V/z1; #current in A
pf = R/z1; #power factor----->math.cos(phi)
#As Xl-Xc is inductive,pf is lagging
z2 = math.sqrt((R**2)+(Xl)**2); #impedance of coil in ohms
Vl = I*(z2); #voltage across coil in volts
Vc = I*(Xc); #voltage across capacitor in volts
print "Thus inductive reacmath.tance, capacitive reacmath.tance, impedance, current, powerfactor are %2.2f ohms, \
%2.2f ohms, %2.2f ohms, %d A, %1.1f respectively"%(Xl,Xc,z1,I,pf);
import math
#INPUT DATA
L = 10; #inductance in milliHenry
C = 5; #capacitor in uf
phi = 50; #phase in degrees-------->lagging
f = 500; #frequency in hz
V = 200; #supply voltage in volts
#CALCULATIONS
Xc = 1/(2*math.pi*f*C*10**-6); #Capacitive reacmath.tance in ohms
Xl = (2*math.pi*f*L*10**-3); #inductive reacmath.tance in ohms
R = (Xc-Xl)/(math.tan(phi*math.pi/180)); #resistance in ohms
Z = math.sqrt((R)**2+(Xc-Xl)**2); #impedance in ohms
I = V/Z; #current in A
Vr = (I)*(R); #voltage across resistance
Vl = (I)*(Xl); #voltage across inductance
Vc = (I)*(Xc); #voltage across capacitance
print "Thus voltages across resistance, inductance, capacitance are %3.2f volts, %3.2f volts, %3.2f volts respectively"%(Vr,Vl,Vc);
import math
from sympy import Symbol,solve
#Chapter-5, Example 5.18, Page 176
#INPUT DATA
L = 5; #inductance in Henry
f = 50; #frequency in hz
V = 230; #supply voltage in volts
R = 2; #resistance in ohms
V1 = 250; #voltage across coil in V
#CALCULATIONS
Xl = (2*math.pi*f*L); #inductive reacmath.tance in ohms
Z1 = math.sqrt((R)**2+(Xl)**2); #impedance of coil in ohms
I = V1/Z1; #current in A
Z = V/I; #total impedance in ohms
#Z = math.sqrt((R)**2+(Xl-Xc)**2) and solving for Xc
Xc = Symbol("Xc");
p = (Xc**2)-3141.58*(Xc)+378004
roots2 = solve(p);
r2 = roots2[1];
#Xc cannot be greater than Z
C = 1/(2*math.pi*f*r2); #capacitance in F
print "Thus value of C that must be present suct that voltage across coil is 250 volts is %g F respectively"%(C);
import math
#Chapter-5, Example 5.19, Page 178
#v = 350*math.cos(3000*t-20)
#i = 15*math.cos(3000*t-60)
#INPUT DATA
L = 0.5; #inductance in Henry
phi = -40; #phase difference between applied voltage and current
#Xl>Xc(P.f is lagging)
w = 3000; #freq in hz
Vm = 350; #peak voltage in volts
Im = 15; #peak current in amps
#CALCULATIONS
Z = Vm/Im; #total impedance in ohms
#Xl-Xc = 0.839*R = X
#Z = math.sqrt((R)**2+(X)**2)
#Z = 1.305*R
R = Z/1.305; #resistance in ohms
X = 0.839*R; #
#X = Xl-Xc
Xl = w*L; #reactive inductance in ohms
Xc = Xl-X; #capacitive reacmath.tance in ohms
C = 1/(w*Xc); #capacitance in uf
print "Thus resistance and capacitance are %2.2f ohms and %g F respectively"%(R,C);
import math
from numpy.linalg import inv
from scipy.optimize import fsolve
from sympy.solvers import solve
#INPUT DATA
R = 10; #resistance in ohms
L = 0.1; #inductance in henry
f = 50; #frequency in hz
#CALCULATIONS
Xl = (2*math.pi*f*L); #inductive reacmath.tance in ohms
Z = R+((1j)*(Xl)); #impedance in ohms
Y = inv([[Z]])#[0]; #admittance in mho
y = abs(Y); #admittance in mho
print "admittance is %1.5f mho"%(y);
import math
from numpy.linalg import inv
#INPUT DATA
#CALCULATIONS
Z = 10+((1j)*(5)); #impedance in ohms
Y = inv([[Z]]); #admittance in mho
print (Y);
import math
#INPUT DATA
Z1 = 7.+((1j)*5); #impedance of branch1 in ohms
Z2 = 10.-((1j)*8); #impedance of branch2 in ohms
V = 230.; #supply voltage in volts
f = 50.; #frequency in hz
#CALCULATIONS
Y1 = 1/(Z1); #admittance of branch1 in mho
Y2 = 1/(Z2); #admittance of branch2 in mho
Y = Y1+Y2; #admittance of combined circuit
print (Y);
g = abs(Y); #conductance in mho;
B = math.atan(Y.imag/Y.real); #susceptance in mho
I = V*(Y); #current
print (I); #total current taken from mains in A
z = math.atan(I.imag/I.real);
pf = math.cos(z); #power factor
print "thus conductance and susceptance of the circuit is %1.3f mho and %1.3f mho respectively"%(g,B);
print "power factor is %1.3f lagging"%(pf)
import math
#Chapter-5, Example 5.23, Page 183
#INPUT DATA
V = 240.; #voltage in volts
f = 50.; #frequency in Hz
R = 15.; #resisimath.tance in ohms
I = 22.1; #current in A
#CALCULATIONS
G = 1/R; #conductance in mho
#susceptance of the circuit,B = 1/(Xl) = 0.00318/L
#admittance of the circuit,(G-jB) = (0.067-j(0.00318/L))
Y = I/V; #admittance in mho;
#Y = math.sqrt((0.067)**2+(0.00318/L)**2) = 0.092-----eqn(1)
#solving eqn(1) for L we have it as
L = math.sqrt((0.00318)**2/((Y)**2-(G)**2)); #inductance in henry
#when current is 34A
I1 = 34; #current in A
Y1 = I1/V; #admittance in mho
#for Y1 we need to find f
f1 = math.sqrt((3.183)**2/((Y1)**2-(G)**2)); #frequency in hz
print "Thus value of frequency when current is 34A is %2.1f Hz"%(f1);
import math
from numpy.linalg import inv
#Chapter-5, Example 5.24, Page 184
#INPUT DATA
L = 0.05; #inductance in henry
R2 = 20.; #resistance in ohms
R1 = 15.; #resistance in ohms
V = 200.; #supply voltage in volts
f = 50.; #frequency in hz
#CALCULATIONS
#for branch 1
Z1 = (R1)+((1j)*(2*math.pi*f*L)); #impedance in ohms
Y1 = inv([[Z1]]); #admittance in branch
I1 = V*(Y1); #current in branch
print (I1);
i1 = abs(I1); #magnitude of current
#for branch 2
Y2 = 1/R2; #admittance in branch
I2 = V*Y2; #current in branch
i2 = abs(I2); #magnitude of current
I = I1+I2; #total current in A
i = abs(I); #magnitude of total current
theta = math.atan(I.imag/I.real); #angle in radians
theta = theta*(180)/(math.pi); #angle in degrees
print "Thus current in branch1,branch2 abd total currents are %1.2f A, %d A, %2.2f A respectively"%(i1,i2,i);
print "phase angle of the combination is %2.1f degrees"%(theta);
import math
from numpy.linalg import inv
#INPUT DATA
L = 6.; #inductance in millihenry
R2 = 50.; #resistance in ohms
R1 = 40.; #resistance in ohms
C = 4.; #capacitance in uf
V = 100.; #voltage in volts
f = 800.; #frequency in hz
#CALCULATIONS
Xl = (2*math.pi*f*L*10**-3); #inductive reacmath.tance in ohms
Xc = 1/(2*math.pi*f*C*10**-6); #capacitive reacmath.tance in ohms
Y1 = inv([[(R1)+(1j*Xl)]]); #admittance of branch1 in mho
Y2 = inv([[(R2)-(1j*Xc)]]); #admittance of branch2 in mho
I1 = V*(Y1); #current in branch 1
I2 = V*(Y2); #current in branch 2
I = I1+I2; #total curremt in A
theta = (math.atan(I1.imag/I1.real))-math.atan(I2.imag/I2.real);
theta = theta*180/math.pi; #angle in degrees
print "Thus total current taken from supply is %2.2f"%(abs(I));
print "phase angle between currents of coil and capacitor is %2.2f degrees"%(theta);
import math
#INPUT DATA
Z1 = 10+(1j*15); #impedance in ohms
Z2 = 6-(1j*8); #impedance in ohms
I = 15.; #current in A
#CALCULATIONS
I1 = ((Z2)/(Z1+Z2))*(I); #umath.sing current division rule
I2 = ((Z1)/(Z1+Z2))*(I); #umath.sing current division rule
i1 = abs(I1); #magnitude of current 1
i2 = abs(I2); #magnitdude of current 2
P1 = ((i1)**2)*(Z1*(1)); #power consumed by branch 1
P2 = ((i2)**2)*(Z2*(1)); #power consumed by branch 2
print "Thus power consumed by branches 1 and 2 are %3.2f W and %4.1f W respectively"%(P1.real,P2.real);
import math
from numpy.linalg import inv
#Chapter-5, Example 5.27, Page 187
#INPUT DATA
V = 200.; #voltage in volts
f = 50.; #frequency in hz
R1 = 10.; #resistance in ohms
L1 = 0.0023; #inductance in henry
R2 = 5.; #resistance in ohms
L2 = 0.035; #inductance in henry
#CALCULATIONS
Xl1 = (2*math.pi*f*L1); #inductive reacmath.tance in branch 1 in ohm
Xl2 = (2*math.pi*f*L2); #inductive reacmath.tance in branch 2 in ohm
Y1 = inv([[10+(1j*7.23)]]); #admittance of branch 1 in mho
Y2 = inv([[5+(1j*10.99)]]); #admittance of branch 2 in mho
Y = Y1+Y2; #total admittance in mho
I1 = V*(Y1); #current through branch1
I2 = V*(Y2); #current through branch2
I = I1+I2; #total current in A
theta = math.atan(I.imag/I.real); #angle in radians
pf_of_combination = math.cos(theta); #powerfactor---->lagging
print "Thus currents in branch1, branch2 and total current are %2.1f A, %2.1f A and %2.2f A respectively"%(abs(I1),abs(I2),abs(I));
print "pf of combination is %1.3f"%(pf_of_combination);
import math
#INPUT DATA
f = 50.; #freq in hz
V = 100.; #volatge in V
L1 = 0.015; #inductance in branch 1 in henry
L2 = 0.08; #inductance in branch 2 in henry
R1 = 2.; #resistance of branch 1 in ohms
x1 = 4.71; #reacmath.tance of branch 1 in ohms
R2 = 1.; #resistance of branch 2 in ohms
x2 = 25.13; #reacmath.tance of branch 2 in ohms
Z1 = (R1)+(1j*x1); #impedance of branch1 in ohms
Z2 = (R2)+(1j*x2); #impedance of branch1 in ohms
I1 = V/Z1; #current in branch 1 in A
print "current in branch 1 in A"
print (I1);
I2 = V/Z2; #current in branch 2 in A
print "current in branch 2 in A"
print (I2);
I3 = I1+I2; #total current in A
print "total current in A"
print (I3);
#note:Answer for real part of total current given in textbook is wrong.Please check the calculations
import math
from numpy.linalg import inv
#CALCULATIONS
R = 8; #resistance in ohms
Xc = -(1j)*12; #capacitive reacmath.tance in ohms
Y = (inv([[R]])+inv([[Xc]])); #admittance in mho
print (Y);
import math
from numpy.linalg import inv
#CALCULATIONS
R = 3; #resistance in ohms
Xl = (1j)*4; #inductive reacmath.tance in ohms
Y = (inv([[R]])+inv([[Xl]])); #admittance in mho
print (Y);
import math
#INPUT DATA
R = 10.; #resistance in ohms
L = 10.; #inductance in milli henry
C = 1.; #capacitance in uF
V = 200.; #applied voltage in volts
#CALCULATIONS
fr = 1/(2*math.pi*(math.sqrt(L*C*10**-3*10**-6))); #resonant frequency in hz
I0 = V/(R); #current at resonance in A
Vr = I0*R; #voltage across resistance in volts
Xl = 2*math.pi*fr*L*10**-3; #inductance in ohms
Vl = I0*Xl; #voltage across inductor in volts
Xc = inv([[2*math.pi*fr*C*10**-6]]); #capacitance in ohms
Vc = I0*Xc; #voltage across capacitor in volts
wr = 2*math.pi*fr #angular resonant frewuency in rad/sec
Q = (wr*L*10**-3)/(R); #quality factor
Bw = (fr/Q); #bandwidth in hz
print "Thus resonant frequency and current are %4.2f hz and %d A respectively"%(fr,I0);
print "voltages across resistance, inductance and capacitance are %d V, %d V and %d V respectively"%(Vr,Vl,Vc);
print "bandwidth and quality factor are %3.2f hz and %d respectively"%(Bw,Q);
import math
from numpy.linalg import inv
#Chapter-5, Example 5.32, Page 196
#INPUT DATA
V = 220.; #applied voltage in volts
f = 50.; #frequency in hz
Imax = 0.4; #maximum current in A
Vc = 330.; #voltage across capacitance in volts
#at resonance condition I0 = 0.4 A
I0 = 0.4 #current in A
#CALCULATIONS
Xc = (Vc)/(I0); #capacitive reacmath.tance in ohms
C = inv([[2*math.pi*f*Xc]]); #capacitance in F
#at resonance condition Xc = Xl, hence
L = Xc/(2*math.pi*f); #inductance in henry
R = V/(Imax); #resistance in ohms
print "Thus resistance, inductance and capacitance are %d ohms, %1.2f H and %g F respectively"%(R,L,C);
import math
#INPUT DATA
R1 = 5; #resistance of branch1 in ohms
R2 = 2; #resistance of branch2 in ohms
L = 10; #inductance in mH
C = 40; #capacitance in uF
#CALCULATIONS
fr = (1./(2*math.pi*(math.sqrt(L*C*10**-9))))*(math.sqrt(((C*10**-6*(R1)**2)-L*10**-3)/((C*10**-6*(R2)**2)-L*10**-3))); #resonant frequency in hz
print "Thus resonant frequency is %f hz"%(fr);
import math
#INPUT DATA
R = 20; #resistance in ohms
L = 0.2; #inductance in H
C = 100; #capacitance in uF
#resistance will be non-inductive only at reosnant frequency
#CALCULATIONS
fr = (1./(2*math.pi*(math.sqrt(L*C*10**-6))))*(math.sqrt((L-(C*10**-6*(R)**2))/(L))); #resonant frequency in hz
print "Thus resonant frequency is %2.2f hz"%(fr);
Rf = (L)/(C*R*10**-6); #non-inductive resistance
print "Thus value of non-inductive resistance is %d ohms"%(Rf);
#INPUT DATA
Q = 250; #quality factor
fr = 1.5*10**6; #resonant freq in hertz
#CALCULATIONS
Bw = (fr)/(Q); #bandwidth in Hz
hf1 = fr+Bw; #half power freq 1
hf2 = fr-Bw; #half power freq 2
print "Thus bandwidth is %d hz"%(Bw);
print "Thus value of half-power frequencies are %g hz and %g hz"%(hf1,hf2);
import math
#INPUT DATA
L = 40*10**-3; #inductance in henry
C = 0.01*10**-6; #capacitance in uf
#CALCULATIONS
fr = 1./(2*math.pi*math.sqrt(L*C)); #resonant frequency
print "Thus resonant frequency is %d hz"%(fr);
import math
from numpy.linalg import inv
#Chapter-5, Example 5.37, Page 198
#INPUT DATA
V = 120.; #source voltage in volts
R = 50.; #resistance in ohms
L = 0.5; #inductance in Henry
C = 50.; #capacitance in uF
#CALCULATIONS
#at Resonance
fr = (1./(2*math.pi*(math.sqrt(L*C*10**-6)))); #resonant frequency in hz
I0 = V/R; #current at resonance in A
Vl = (1j)*(I0*L); #voltage developed across inductor in volts
Vc = (-1j)*(I0*L); #voltage developed across capacitor in volts
Q = (inv([[R]]))*(math.sqrt(L/(C*10**-6))); #quality factor
Bw = (fr)/(Q); #Bandwidth in Hz
#given resonance is to occur at 300 rad/sec,then
wr = 300; #wr = (2*math.pi*f*r)------->measured in Hz
#wr = inv(math.sqrt(L*Cn))
Cr = inv([[L*(wr)**2]]); #capacitance required in uF
print "Thus resonant frequency, current, quality factor and bandwidth are %2.1f Hz, \
%1.1f A, %d and %2.1f hz respectively"%(fr,I0,Q,Bw);
print "New value of capacitance at 300 rad/sec is %g F"%(Cr)
import math
#INPUT DATA
Q = 45.; #quality factor
f1 = 600.*10**3; #freq in Hz
f2 = 1000.*10**3; #freq in Hz
#given new resistance is 50% greater than former.let us consider two reismath.tances as R1 = 1 ohm and R2 = 1.5 ohm for ease of calculation.Then
R1 = 1; #resistance in ohm
R2 = 1.5; #resistance in ohm
#CALCULATIONS
W1 = 2*math.pi*f1; #angular freq 1 in rad/sec
W2 = 2*math.pi*f2; #angular freq 2 in rad/sec
Q = 45; #quality factor
L = (Q*R1)/(W1); #inductance in henry
Q1 = (W2*L)/(R2); #new quality factor
print "Thus new quality factor is %d"%(Q1);
import math
from numpy.linalg import inv
#INPUT DATA
R = 4.; #resistance in ohm
L = 100.*10**-6; #inductance in henry
C = 250.*10**-12; #capacitance in Farads
#CALCULATIONS
fr = inv([[2*math.pi*math.sqrt(L*C)]]); #resonant frequency in Hz
Q = (inv([[R]]))*(math.sqrt(L/C)); #Q-factor
Bw = fr/Q; #bandwidth in Hz
hf1 = fr+Bw; #halfpower freq1 in Hz
hf2 = fr-Bw; #halfpower freq2 in Hz
print "Thus resonant freq, Q-factor and new halfpower frequencies are %d hz , %d, %g hz, %g hz respectively"%(fr,Q,hf1,hf2);
#note:given answers are wrong in textbook.Please check the answers
import math
from numpy.linalg import inv
#INPUT DATA
R = 10; #resistance in ohm
L = 10**-3; #inductance in henry
C = 1000*10**-12; #capacitance in Farads
V = 20; #voltage in volts
#CALCULATIONS
fr = inv([[2*math.pi*math.sqrt(L*C)]]); #resonant frequency in Hz
Q = (inv([[R]]))*(math.sqrt(L/C)); #Q-factor
Bw = fr/Q; #bandwidth in Hz
hf1 = fr+Bw; #halfpower freq1 in Hz
hf2 = fr-Bw; #halfpower freq2 in Hz
print "Thus resonant freq, Q-factor and new halfpower frequencies are %d hz , %d , %g hz, %g hz respectively"%(fr,Q,hf1,hf2);
import math
#INPUT DATA
P1 = 1000.; #power1 in watts
P2 = 1000.; #power2 in watts
#CALCULATIONS
#for case(1)
Pt = P1+P2; #total power in watts
phi = math.atan(math.sqrt(3)*((P2-P1)/(P2+P1))*(180/math.pi)); #math.since math.tan(phi) = math.sqrt(3)*((P2-P1)/(P2+P1)))
pf = math.cos(phi);
print "Thus power and powerfactor are %d W ,%d respectively"%(Pt,pf);
#for case(2)
P3 = 1000; #power3 in watts
P4 = -1000; #power4 in watts
Pt1 = P3+P4; #total power in watts
pf1 = 0; #math.since we cannot perform division by zero in scilab,it doesn't consider it as infinite quantity to yield 90 degree angle and hence powerfactor 0
print "Thus power and powerfactor are %d W ,%d respectively"%(Pt1,pf1);
import math
#INPUT DATA
V1 = 400.; #voltage in volts
Z1 = (3.+((1j)*4)); #impedance in ohms
#CALCULATIONS
#in star connected system,phase voltage = (line voltage)
Ep = V1/(math.sqrt(3)); #voltage in volts
Ip = Ep/Z1; #current in A
ip1 = abs(Ip); #line current in A
theta = math.atan(Ip.imag/Ip.real);
Pt = math.sqrt(3)*V1*ip1*math.cos(theta); #total power consumed in load in W
print "Thus total power consumed in load is %f W"%(Pt);
#note:for line current the answer given is 46.02A instead of 46.2 A and hence total power consumed changes
#INPUT DATA
V1 = 400; #voltage in volts
Il = 10; #current in A
#CALCULATIONS
#in star connected system,phase current = (line current) = I1
phase_voltage = (V1)/(math.sqrt(3)); #voltage in Volts
print "Thus phase voltage is %1.0f V"%(phase_voltage);
import math
#Chapter-5, Example 5.44, Page 209
#INPUT DATA
Z1 = (6-((1j)*8)); #impedance1 in ohms
Z2 = (16+((1j)*12)); #impedance2 in ohms
I1 = (12+((1j)*16)); #current in A
#CALCULATIONS
V = I1*Z1; #applied voltage in volts
I2 = V/(Z2); #current in other branch in A
print "current in other branch in Amps"
print (I2);
I = I1+I2; #total current in A
print "total current in Amps";
print (I);
i1 = abs(I); #magnitude in A
i2 = math.atan(I.imag/I.real);
P = V*i1*math.cos(i2); #power consumed in circuit
print "Thus voltage applied and power consumed are %d V and %d W respectively"%(V.real,P.real);
import math
#INPUT DATA
Vl = 415.; #voltage in volts
Z = (4+((1j)*6)); #impedance in each phase in ohm
#CALCULATIONS
Ip = Vl/Z; #current in each phase in A
ip1 = abs(Ip); #magnitude of Ip
Il = (math.sqrt(3))*(ip1); #line current in A
phi = math.atan(Ip.imag/Ip.real)
P = (math.sqrt(3))*Vl*Il*math.cos(phi); #power supplied in W
print "Thus power supplied is %d W"%(P);
#note:the math.cosfunction of scilab and calculator will differ slightly
#INPUT DATA
Vl = 400; #voltage in volts
Il = 20; #current in A
f = 50; #freq in hz
pf = 0.3 #power factor
#CALCULATIONS
Ip = Il/math.sqrt(3); #phase current in A
Z = Vl/Ip; #impedance in each phase in ohms
phi = math.acos(0.3); #angle in radians
Zb = Z*(math.cos(phi)+(1j)*math.sin(phi)); #impedance connected in each phase
print "Thus impedance connected in each phase in ohms";
print (Zb);
import math
#INPUT DATA
P1 = 6*10**3; #power in Kw
P2 = -1*10**3; #power in Kw
#CALCULATIONS
P = P1+P2; #total power in Kw
a = math.atan(math.sqrt(3)*((P2-P1)/(P2+P1)));
pf = math.cos(a); #power factor
print "Thus power and power factor are %d W and %1.2f respectively"%(P,pf);
import math
#INPUT DATA
Z = 3-((1j)*4); #impedance in ohms
Vl = 400; #line voltage in volts
#CALCULATIONS
Vp = Vl/(math.sqrt(3)); #phase voltage in volts
Ip = Vp/abs(Z); #phase current in Amps
#line current(Il) = phase current(Ip)
Il = Ip; #line current in A
power_factor = math.cos(math.atan(Z.imag/Z.real));
power_consumed = math.sqrt(3)*Vl*Il*power_factor;
print "Thus power consumed and power factor are %f W and %1.1f respectively"%(power_consumed,power_factor);
#note:answer computed for power consumed in textbook is wrong.Please check the calculations
import math
#INPUT DATA
Il = 10.; #current in Amps
Vl = 400.; #line voltage in volts
#CALCULATIONS
Vp = Vl/(math.sqrt(3)); #line to neutral voltage
Ip = Il; #phase current in Amps
print "Thus line to neutral voltage and phase current are %1.0f V and %d A respectively"%(Vp,Ip);
import math
#INPUT DATA
P1 = 2000; #power in watts
P2 = 1000; #power in watts
Vl = 400; #line voltage in volts
#CALCULATIONS
P = P1+P2; #power in Watts
a = math.sqrt(3*(P1-P2)/(P1+P2));
b = math.atan(math.sqrt(a));
power_factor = math.cos(b);
kVA = P/power_factor;
print "Thus power, power factor and kVA are %d W , %1.3f and %1.2f respectively"%(P,power_factor,kVA);
#note:computed value for powerfactor and kVA in textbook are wrong.Please check the calculations