from __future__ import division
from math import pi
M_r=5000# #relative permeability
R=10*10**-2#
r=2*10**-2#
N=100# #number of turns
#complex number 'i' is used as a symbol here
I=2*1J# #here 'i' represents sin(200*pi*t), not as a complex number
M_o=4*pi*10**-7# #permeability of free space
M=M_r*M_o# #permeability of the core material
phi=M*N*I*r**2/(2*R)# #flux
FL=N*phi# #flux linkages
print " All the values in the textbook are approximated hence the values in this code differ from those of Textbook"
print 'In the below two values,i represents sin(200*pi*t)' #t-time
print 'flux = j*{:0.3e} webers'.format(phi.imag)
print 'flux linkages = j*{:.2f} weber turns'.format(FL.imag)
#differentiating 'λ' with respect to t
print 'In the below answer, i represents cos(200*pi*t)'
print 'Voltage induced in the coil = {0:.2f}+j*{1:0.2f} volts'.format((FL*200*pi).real,(FL*200*pi).imag)
from __future__ import division
from math import pi
M_r=6000# #relative permeability
M_o=4*pi*10**-7# #permeability of free space
w_r=3*10**-2# #width of rectangular cross-section
d_r=2*10**-2# #depth of rectangular cross-section
N=500# #number of turns of coil
B_gap=0.25# #flux density
gap=0.5*10**-2# #air gap
#centerline of the flux path is a square of side 6cm
l_s=6*10**-2# #side of square
l_core=4*l_s-gap# #mean length of the iron core
A_core=w_r*d_r# #cross-sectional area of the core
M_core=M_r*M_o# #permeability of core
R_core=l_core/(M_core*A_core)# #reluctance of the core
A_gap=(d_r+gap)*(w_r+gap)# #effective area of gap
M_gap=M_o# #permeability of air(gap)
R_gap=gap/(M_gap*A_gap)# #reluctance of gap
R=R_gap+R_core# #total reluctance
phi=B_gap*A_gap# #flux
F=phi*R# #magnetomotive force
i=F/N# #current
print " All the values in the textbook are approximated hence the values in this code differ from those of Textbook"
print 'Current value = %0.2f amperes'%i
from __future__ import division
from math import pi
w_core=2*10**-2# #width
d_core=2*10**-2# #depth
A_core=w_core*d_core# #area of core
M_r=1000# #relative permeability
M_o=4*pi*10**-7# #permeability of free space
gap_a=1*10**-2#
gap_b=0.5*10**-2#
N=500# #number of turns of coil
i=2# #current in the coil
l_c=10*10**-2# #length for center path
R_c=l_c/(M_r*M_o*A_core)# #reluctance of center path
#For left side
#taking fringing ino account
A_gap_a=(w_core+gap_a)*(d_core+gap_a)# #area of gap a
R_gap_a=gap_a/(M_o*A_gap_a)# #reluctance of gap a
l_s=10*10**-2# #side of square
l_core_l=3*l_s-gap_a# #mean length on left side
R_core_l=l_core_l/(M_r*M_o*A_core)# #reluctance of core
R_L=R_core_l+R_gap_a# #total reluctance on left side
#For right side
#taking fringing ino account
A_gap_b=(w_core+gap_b)*(d_core+gap_b)# #area of gap b
R_gap_b=gap_b/(M_o*A_gap_b)# #reluctance of gap b
l_s=10*10**-2# #side of square
l_core_r=3*l_s-gap_b# #mean length on right side
R_core_r=l_core_r/(M_r*M_o*A_core)# #reluctance of core
R_R=R_core_r+R_gap_b# #total reluctance on right side
R_T=R_c+1/((1/R_L)+(1/(R_R)))# #total reluctance
phi_c=N*i/(R_T)# #flux in the center leg of coil
#by current-division principle
phi_L=phi_c*R_R/(R_L+R_R)# #left side
phi_R=phi_c*R_L/(R_L+R_R)# #right side
B_L=phi_L/A_gap_a# #flux density in gap a
B_R=phi_R/A_gap_b# #flux density in gap b
print " All the values in the textbook are approximated hence the values in this code differ from those of Textbook"
print 'flux density in gap a = %0.2f tesla'%B_L
print 'flux density in gap b = %0.2f tesla'%B_R
from __future__ import division
N=500# #number of turns of coil
R=4.6*10**6# #reluctance of the magnetic path from ex15.5
L=N**2/R# #inductance
print " All the values in the textbook are approximated hence the values in this code differ from those of Textbook"
print 'Inductance of the given coil = %0.2f milli-henry'%(L*10**3) #milli-10**-3
from __future__ import division
R=10**7# #reluctance of core
N_1=100# #turns for coil 1
N_2=200# #turns for coil 2
L_1=N_1**2/R# #self-inductance of coil 1
L_2=N_2**2/R# #self-inductance of coil 2
#here, complex number i represents i_1 in textbook
phi_1=N_1*1J/R# #flux produced by i(i_1)
L_21=N_2*phi_1# #flux linkages of coil 2 from current in coil 1
M=L_21/1J# #mutual inductance
#milli-(10**-3)
print 'self-inductance of coil 1 =',L_1*10**3,'milli henry'
print 'self-inductance of coil 2 =',L_2*10**3,'in milli henry'
print 'mutual inductance of the coils =',M*10**3, 'milli henry'
from __future__ import division
V_s_rms=4700# #for source
V_L_rms=220# #load voltage
tr=V_s_rms/V_L_rms# #turns ratio
print " All the values in the textbook are approximated hence the values in this code differ from those of Textbook"
print 'The required turns ratio N1/N2 = %0.3f'%tr
from __future__ import division
V_1_rms=110#
R_L=10#
tr=5# #turns ratio(N1/N2)
V_2_rms=V_1_rms/tr# #primary and secondary voltage relation
#a)open switch
print 'OPEN switch'
print 'Primary voltage = %0.2f volts'%V_1_rms
print 'Secondary voltage = %0.2f volts'%V_2_rms
#As switch is open, current in second winding is 0 which implies the current in primary coil to be 0 (ideal transformer condition)
print 'Current in primary and secondary windings =',0,'in amperes'
#b)closed switch
print 'CLOSED switch'
I_2_rms=V_2_rms/R_L# #ohm's law
I_1_rms=I_2_rms/tr# #ideal transformer condition
print 'Primary voltage = %0.2f volts'%V_1_rms
print 'Secondary voltage = %0.2f volts'%V_2_rms
print 'Current in primary winding = %0.2f amperes'%I_1_rms
print 'Current in secondary winding = %0.2f amperes'%I_2_rms
from __future__ import division
from cmath import sin,cos,polar,phase,sqrt
V_s=1000*complex(cos(0),sin(0))# #source voltage phasor
R_1=10**3#
R_L=10#
Z_L_1=R_L+1J*20# #impedance
tr=10# #turns ratio(N1/N2)
Z_L_2=(tr**2)*Z_L_1# #reflecting Z_L_1 onto primary side
Z_s=R_1+Z_L_2# #total impedance seen by the source
Z_s_max = abs(Z_s)
Z_s_phi=phase(Z_s)
#primary quantities
I_1=V_s/Z_s#
I_1_max = abs(I_1)
I_1_phi = phase(I_1)
V_1=I_1*Z_L_2#
V_1_max=abs(V_1)
V_1_phi=phase(V_1)
#using turns ratio to find secondary quantities
I_2=tr*I_1#
I_2_max=abs(I_2)
I_2_phi=phase(I_2)
V_2=V_1/tr#
V_2_max=abs(V_2)
V_2_phi=phase(V_2)
I_2_rms=I_2_max/sqrt(2)#
P_L=(I_2_rms**2)*R_L# #power to load
print " All the values in the textbook are approximated hence the values in this code differ from those of Textbook"
#we take real parts of angles to take out neglegible and unnecessary imaginary parts(if any are there)
print 'PRIMARY CURRENT:'
print 'peak value = %0.2f amperes'%I_1_max
print 'phase angle = %0.2f degrees'%((I_1_phi*180/pi).real)
print 'PRIMARY VOLTAGE:'
print 'peak value = %0.2f amperes'%(V_1_max)
print 'phase angle = %0.2f degrees'%((V_1_phi*180/pi).real)
print 'SECONDARY CURRENT'
print 'peak value = %0.2f amperes'%I_2_max
print 'phase angle = %0.2f degrees'%((I_2_phi*180/pi).real)
print 'SECONDARY VOLTAGE'
print 'peak value = %0.2f amperes'%(V_2_max)
print 'phase angle = %0.2f degrees'%((V_2_phi*180/pi).real)
print 'power delivered to load = %0.2f watts'%abs(P_L)
from __future__ import division
from cmath import polar,pi,sin,cos
V_s=1000*complex(cos(0),sin(0))# #source voltage phasor
R_1=10**3#
tr=10# #turns ratio(N1/N2)
V_S=V_s/tr# #reflected voltage
V_S_max=polar(V_S)[0]
V_S_phi=polar(V_S)[1]
R1=R_1/(tr**2)# #reflected resistance
#we take real parts of angles to take out neglegible and unnecessary imaginary parts(if any are there)
print 'Reflected voltage:'
print 'Peak value = %0.2f volts'%V_S_max
print 'phase angle = %0.2f degrees'%(V_S_phi*180/pi)
print 'Reflected resistance = %0.2f ohms'%R1
from __future__ import division
from cmath import polar,pi,sin,cos,acos
V_L_max=240#
V_L=V_L_max*complex(cos(0),sin(0))# #load voltage
R_1=3#
R_2=0.03#
R_c=100*10**3# #core-loss resistance
tr=10# #turns ratio(N1/N2)
#leakage reactances
Z_1=1J*6.5#
Z_2=1J*0.07#
Z_m=1J*15*10**3#
P_R=20*10**3# #rated power
I_2_max=P_R/(V_L.real)#
PF=0.8# #power factor
phi=-acos(PF)# #-ve for lagging power
I_2=complex(I_2_max*cos(phi),I_2_max*sin(phi))# #phasor
I_1=I_2/tr# #primary current
I_1_max=polar(I_1)[0]
I_1_phi =polar(I_1)[1]
V_2=V_L+(R_2+Z_2)*I_2# #KVL equation
V_1=tr*V_2#
V_s=V_1+(R_1+Z_1)*I_1# #KVL equation
V_s_max = polar(V_s)[0]
V_s_phi =polar(V_s)[1]#
P_loss=((V_s_max**2)/R_c)+((I_1_max**2)*R_1)+((I_2_max**2)*R_2)# #power loss in transformer
P_L=V_L*I_2*PF# #power to load
P_in=P_L+P_loss# #input power
P_eff=(1-(P_loss/P_in))*100#
#under no-load condtions
I_1=0#
I_2=0#
V_1=V_s_max#
V_no_load=V_1/tr#
PR=((V_no_load-V_L_max)/V_L_max)*100#
print 'Percent regulation = %0.2f'%PR