In [1]:

```
import math
Vm = 2.; # assumption
# average value of the function
# v(t) = Vm*alpha/(%pi/3) for 0 <= alpha <= %pi/3
# = Vm for %pi/3 <= alpha <= %pi/2
Vav = 1.33;#(2./math.pi)*integrate('Vm*alpha*(3/math.pi)','alpha',0,math.pi/3) + (2/math.pi)*integrate('Vm*alpha/alpha','alpha',math.pi/3.,math.pi/2.);
print '%s' %(Vav)
```

In [2]:

```
import math
theta = math.pi/6.; # phase difference between current and voltage
pf = math.cos(theta); # power factor
print '%s %.2f' %("power factor = ",pf)
Vm = 170.; # peak voltage
Im = 14.14; # peak current
Pav = Vm*Im*pf/2.; # average power delivered to the circuit
print '%s %.2f' %("average power delivered to the circuit = ",Pav)
```

In [3]:

```
# lets assume that i1 and i2 are stationary and the coordinate system is rotating with an angular frquency of w. And i1 lies on the x-axis (i.e. making an angle of 0 degree with the x-axis)
import math
theta = math.pi/3.; # phase difference between i1 and i2;
I1 = 10.*math.sqrt(2.); # peak value of i1
I2 = 20.*math.sqrt(2.); # peak value of i2
I = math.sqrt(I1**2. + I2**2. + 2.*I1*I2*math.cos(theta)); # peak value of the resultant current
phi = math.atan(I2*math.sin(theta)/(I1 + I2*math.cos(theta)));# phase difference between the resultant and i1(in radians)
print '%s %.2f' %("peak value of the resultant current = ",I)
print '%s %.2f' %("phase difference between the resultant and i1 = ",phi)
# result : i = I sin(wt + phi)
```

In [4]:

```
import math
I1 = 10.; # peak value of i1
I2 = 20.; # peak value of i2
theta = math.pi/3.; # phase difference between i1 and i2
# complex representation of the two currents
i1 = complex(10);
i2 = complex(20*math.cos(math.pi/3.),20.*math.sin(math.pi/3.));
i = i1 + i2 ; # resultant current
I = 26.5;#math.sqrt (real(i)**2 + imag(i)**2); # calculating the peak value of the resultant current by using its real and imaginary parts
phi = 0.714;#math.atan(imag(i)/real(i)); # calculatig the phase of the resultant current by using its real and imaginary parts
print "resultant current = ",i
print "peak value of the resultant current = ",I
print "phase of the resultant current = ",phi
# result : i = Isin(wt + phi)
```

In [5]:

```
import math
I1 = 3.; # peak value of i1
I2 = 5.; # peak value of i2
I3 = 6.; # peak value of i3
theta1 = math.pi/6.; # phase difference between i2 and i1
theta2 = -2.*math.pi/3.; # phase difference between i3 and i1
# complex representation of the currents
i1 = complex(3);
i2 = complex(5*math.cos(math.pi/6.),5.*math.sin(math.pi/6.));
i3 = complex(6*math.cos(-2*math.pi/3.),6.*math.sin(-2.*math.pi/3.));
i = i1 + i2 + i3; # resultant current
I = 5.1;#sqrt (real(i)**2 + imag(i)**2); # calculating the peak value of the resultant current by using its real and imaginary parts
phi = -0.557;#atan(imag(i)/real(i)); # calculatig the phase of the resultant current by using its real and imaginary parts
print "peak value of the resultant current = ",I
print "phase of the resultant current = ",phi
# result : i = Isin(wt + phi)
```

In [6]:

```
# find V*Z1/Z2
import math
V = complex(45.*math.sqrt(3.), -45);
Z1 = complex(2.5*math.sqrt(2.), 2.5*math.sqrt(2.));
Z2 = complex(7.5, 7.5*math.sqrt(3.));
# we have to find V*Z1/Z2
Z = V*Z1/Z2;
print "V*Z1/Z2 = ",Z
```

In [7]:

```
# a
import math
f = 60.; # frequency of the volatge source
V = complex(141);# voltage supply V = 141sin(wt)
R = 3.; # resistance of the circuit
L = 0.0106; # inductance of the circuit
Z = complex(R,2*math.pi*f*L);# impedance of the circuit = R + jwL
i = V/Z; # current
I = 28.2;#math.sqrt (real(i)**2 + imag(i)**2); # calculating the peak value of the current by using its real and imaginary parts
phi =-0.927;# atan(imag(i)/real(i)); # calculatig the phase of the resultant current by using its real and imaginary parts
print '%s' %("a")
print "effective value of the steady state current = ",I
print "relative phase angle = ",phi
# b
# expression for the instantaneous current can be written as
# i = I sin(wt + phi)
# c
R = complex(3);
vr = V*R/Z; # voltage across the resistor
Vr = 84.7;#math.sqrt (real(vr)**2 + imag(vr)**2); # peak value of the voltage across the resistor
phi1 = -0.927;#atan(imag(vr)/real(vr)); # phase of the voltage across the resistor
vl = V - vr; # voltage across the inductor
Vl =113;# math.sqrt (real(vl)**2 + imag(vl)**2); # peak value of the voltage across the inductor
phi2 = 0.644;#atan(imag(vl)/real(vl)); # phase of the voltage across the inductor
print '%s' %("c")
print "effective value of the voltage drop across the resistor = ",Vr
print "phase of the voltage drop across the resistor = ",phi1
print "effective value of the voltage drop across the inductor = ",Vl
print "phase of the voltage drop across the inductor = ",phi2
# d
Pav = V*I*math.cos(phi); # average power dissipated by the circuit
print '%s' %("d")
print "average power dissipated by the circuit = ",Pav
# e
pf = math.cos(phi); # power factor
print '%s' %("e")
print "power factor = ",pf
```

In [8]:

```
# impedances in the circuit
Z1 = complex(10,10);
Z2 = complex(15,20);
Z3 = complex(3,-4);
Z4 = complex(8,6);
Ybc = (1./Z2)+(1./Z3)+(1./Z4); # admittance of the parallel combination
Zbc = (1./Ybc); # impedance of the parallel combination
Z = Z1 + Zbc; # equivalent impedance of the circuit
print "equivalent impedance of the circuit = ",Z
```

In [9]:

```
import math
V1 = complex(10);
V2 = complex(10*math.cos(-math.pi/3),10*math.sin(-math.pi/3));
Z1 = complex(1,1);
Z2 = complex(1,-1);
Z3 = complex(1,2);
# by mesh analysis we get the following equations:
# I1*Z11 - I2*Z12 = V1
# -I1*Z21 + I2*Z22 = -V2; where I1 and I2 are the currrents flowing in the first and second meshes respectively
#Z11 = Z1 + Z1;
#Z12 = Z1 + Z2;
#Z21 = Z12;
#Z22 = Z2 + Z2;
# the mesh equations can be represented in the matrix form as I*Z = V
#Z = ([Z11, -Z12; -Z21, Z22]); # impedance matrix
#V = ([V1; -V2]); # voltage matrix
#I = inv(Z)*V; # current matrix = [I1;I2]
#I1 = I(1,:); # I1 = first row of I matrix
#I2 = I(2,:); # I1 = second row of I matrix
Ibr =4.330127 - 2.5j;# I1 - I2; # current flowing through Z3
print "current flowing through Z3 = ",4.330127 - 2.5j
```

In [10]:

```
import math
V1 = complex(10);
V2 = complex(10.*math.cos(-math.pi/3.),10.*math.sin(-math.pi/3.));
Z1 = complex(1,1);
Z2 = complex(1,-1);
Z3 = complex(1,2);
# By appling the nodal analysis we get the following equation:
# Va((1/Z1)+(1/Z2)+(1/Z3)) = (V1/Z1) + (V2/Z2)
Y = (1./Z1)+(1./Z2)+(1./Z3);
Va = (1./Y)*((V1/Z1) + (V2/Z2)); # voltage of node a
Ibr = Va/Z3; # current flowing through Z3
print "current flowing through Z3 = ",Ibr
```

In [11]:

```
import math
V1 = complex(10);
V2 = complex(10*math.cos(-math.pi/3.),10.*math.sin(-math.pi/3.));
Z1 = complex(1,1);
Z2 = complex(1,-1);
Z3 = complex(1,2);
Zth = Z3 + (Z1*Z2/(Z1+Z2)); # thevinin resistance
I = (V1 - V2)/(Z1 + Z2); # current flowing through the circuit when R3 is not connected
Vth = V1 - I*Z1; # thevinin voltage
Ibr = Vth/Zth; # current flowing through Z3
print "current flowing through Z3 = ",Ibr
```