import math
#Example 15.4")
# Given
#L1 = 0.1H L2 = 0.2H")
#i1 = 4A i2 = 10A")
L1 = 0.1;L2 = 0.2
i1 = 4;i2 = 10;
#The energy stored in coupled coils is
#W = (L1*i1**2)/2+(L2*i2**2)/2+M*i1*i2")
#a)")
M = 0.1;
W = (L1*i1**2)/2+(L2*i2**2)/2+M*i1*i2;
print "Total Energy in the coils = %3.2fJ"%(W);
#b)")
M = math.sqrt(2)/10;
W = (L1*i1**2)/2+(L2*i2**2)/2+M*i1*i2;
print "Total Energy in the coils = %3.2fJ"%(W);
#c)")
M = -0.1;
W = (L1*i1**2)/2+(L2*i2**2)/2+M*i1*i2;
print "Total Energy in the coils = %3.2fJ"%(W);
#a)")
M = -math.sqrt(2)/10;
W = (L1*i1**2)/2+(L2*i2**2)/2+M*i1*i2;
print "Total Energy in the coils = %3.2fJ"%(W);
import math
from scipy.linalg import polar
#Example 15.7")
# Given
#N1 = 20 N2 = N3 = 10")
#I2 = 10(-53.13 deg) I3 = 10(-45 deg)")
N1 = 20;
N2 = 10;
N3 = 10;
I2mag = 10;
I2ph = -53.13;
I3mag = 10;
I3ph = -45;
#From figure 15.14
#N1*I1-N2*I2-N3*I3 = 0")
#Solving for I1
Xmag = N2*I2mag
Xph = I2ph
x = Xmag*math.cos((Xph*math.pi)/180);
y = Xmag*math.sin((Xph*math.pi)/180);
z = complex(x,y)
Ymag = N3*I3mag
Yph = I3ph
x1 = Ymag*math.cos((Yph*math.pi)/180);
y1 = Ymag*math.sin((Yph*math.pi)/180);
z1 = complex(x1,y1)
I1 = (z+z1)/N1
R,Theta = polar([[I1]]);
R = R[0][0].real
Theta = Theta[0][0].real
print "I1 = %3.2f%3.2f deg) A"%(R,(Theta*180)/math.pi);
import math
from scipy.linalg import polar
#Example 15.8")
# Given
#L1 = 0.2H L2 = 0.1H")
#M = 0.1H R = 10ohm")
#v1 = 142.3*math.sin(100*t)")
L1 = 0.2;L2 = 0.1
M = 0.1;R = 10;
v1mag = 142.3;
w = 100;
#Let Input impedance be Z1 and can be calculated as
#From the equations in 15.10
#Z1 = 1j*w*L1+((M*w)**2)/(Z2+1j*w*L2)")
Z1 = 1j*w*L1+((M*w)**2)/(R+1j*w*L2)
R,Theta = polar([[Z1]])
R = R[0][0].real
Theta = Theta[0][0].real
#If I1 is the input current
I1mag = v1mag/R
I1ph = -(Theta*180)/math.pi
#In time domain form
print "i1 = %3.1f*math.sin%d*t%3.1f deg) A)"%(I1mag,w,I1ph);
import math
from sympy import Symbol
s = Symbol('s')
# Given
#L1 = 0.2H L2 = 0.1H")
#M = 0.1H R = 10ohm")
#v1 = u(t) a unit step function")
L1 = 0.2;
L2 = 0.1
M = 0.1;
R = 10;
v1 = 1;
w = 100;
#Let Input impedance be Z1 and can be calculated as
#From the equations in 15.10
#Z1(s) = L1*s-((M*s)**2)/(R+L2*s)")
Z1 = L1*s-(((M*s)**2)/(R+L2*s))
#Proper rearranging of co-efficients
Num = Z1/0.01
Den = Z1*100
print "Z1(s)",Num/Den
Y1 = 1./Z1
print "Y1(s)",Den/Num
#As the input is unit step function the value is 1V for t>0
#In exponential form the value is represented as exp(s*t) with s = 0 as the pole of Y1(s)
#Therefore forced response
k = 1/L1;
print "Forced response i1,f = %d*t) A)"%(k);