import math
#Variable declaration
Zo=100
ZL=complex(50,-75)
B=2*math.pi
XL=-0.75
RL=0.5
Y_L=Zo/ZL
#Calculations&Results
G_L=Y_L.real
B_L=Y_L.imag
print "Y_L=",Y_L
A=G_L*(G_L-1)+B_L**2
print "A=%.4f"%A
ds=(math.degrees(math.atan((XL+math.sqrt(XL**2-A*(1-RL)))/A)))/B
print "ds=%f*lambda"%ds
ds=(math.degrees(math.atan((XL-math.sqrt(XL**2-A*(1-RL)))/A)))/B
print "ds=%f*lambda"%ds
X_s=-1.2748
Ls=1./B*1./math.degrees(math.atan(X_s))
print "Ls=%f*lambda"%Ls
X_s=1.2748
Ls=1./B*1/math.degrees(math.atan(X_s))
print "Ls=%f*lambda"%Ls
#Incorrect solution in the textbook
import math
import cmath
#Variable declaration
FL=0.4*cmath.exp(complex(0,-30*math.pi/180))
Fin=0.2*cmath.exp(complex(0,45*math.pi/180))
#Calculations&Results
Z_L=(1+FL)/(1-FL)
Z_in=(1+Fin)/(1-Fin)
Y_in=(1-Fin)/(1+Fin)
print "Z_L=",Z_L
print "Z_in=",Z_in
print "Y_in=",Y_in
#Y_in=(1+complex(0,(Z_L*math.tan(Bl*math.pi/180))))/(Z_L+complex(0,math.tan(Bl*math.pi/180)))
Y_in1=1/Z_in
print "Y_in=",Y_in1
import math
#Variable declaration
RL=50
Rs=75
#Calculations
R1=math.sqrt(Rs*(Rs-RL))
R2=math.sqrt(RL**2*Rs/(Rs-RL))
attenuation=20*math.log10(R2*RL/(R1*(R2+RL)+R2*RL))
#Result
print "\nR1=%.1f ohm\nR2=%.1f ohm\nattenuation(dB)=%.2f dB"%(R1,R2,attenuation)
import math
#Variable declaration
Rp=600 #ohms
Rs=50 #ohms
W=2*math.pi*400*10**6
Q=math.sqrt(Rp/Rs-1)
#Calculations
Xs=Q*Rs
Xp=Rp/Q
Cs=1./W/Xs
Lp=Xp/W
Ls=Xs/W
Cp=1./W/Xp
#Results
print "\nQ=%.4f\nXs=%.4f ohm\nXp=%.4f ohm\nCs=%.2e F\nLp=%.3e H\nLs=%.3e H\nCp=%.2e F" %(Q,Xs,Xp,Cs,Lp,Ls,Cp)
import math
#Variable declaration
Rp=600 #ohm
Rs=173.2 #ohm
Q=math.sqrt(Rp/Rs-1)
#Calculations&Results
Xs=Q*Rs
Xp=Rp/Q
print "Q=%.6f\nXs=%.4f ohm\nXp=%.4f ohm\n" %(Q,Xs,Xp)
Rp=173.2 #ohm
Rs=50 #ohm
Q=math.sqrt(Rp/Rs-1)
Xs=Q*Rs
Xp=Rp/Q
print "\nQ=%.4f\nXs=%.4f ohm\nXp=%.4f ohm\n"%(Q,Xs,Xp)
import math
#Variable declaration
f=500*10**6
W=2*math.pi*f
Rp=50
Rs=10
Q=math.sqrt(Rp/Rs-1)
#Calculations
Xs=Q*Rs
Xp=Rp/Q
Ls=(Xs-10)/W
Cp=1/W/Xp
Cs=1/W/(Xs+10)
Lp=Xp/W
#Result
print "\nQ=%.0f\nXs=%.0f ohm\nXp=%.0f ohm\nLs=%.4e H\nCp=%.4e F\nCs=%.3e F\nLp=%.4e H"%(Q,Xs,Xp,Ls,Cp,Cs,Lp)
import math
#Variable declaration
ZL=10**3/complex(8,-12)
Rp=50
W=2*math.pi*10**9
Rs=ZL.real
Q=math.sqrt(Rp/Rs-1)
#Calculations
Xs=Q*Rs
Xc=Xs+ZL.imag
Xp=Rp/Q
C=1/W/Xc
L=Xp/W
#Result
print "ZL=",ZL
print "\nQ=%.4f\nXs=%.4f ohm\nXp=%.4f ohm\nC=%.4e F\nL=%.4e H\n"%(Q,Xs,Xp,C,L)
print "\nXs=57.6923-21.0654 ohm\nXp=91.2909 ohm\nCp=1.7434 F"
import math
#Variable declaration
W=2*math.pi*10**9
Gs=0.02
Gp=0.008
Q=math.sqrt(Gs/Gp-1)
#Calculations
Bs=Gs/Q
Bp=Q*Gp
#Result
print "\nQ=%.4f\nBs=%.4f S\nBp=%.2f S\n"%(Q,Bs,Bp)