from __future__ import division
from math import sqrt, pi
#Given
#Given
I0=30e-3 #A
V0=3e3 #V
Z0=10 #ohm
l=0.1624 #m
f=10e9 #Hz
#(i) Gain parameter
C=((I0*Z0)/(4*V0))**(1/3)
print 'Gain parameter: %0.3f'%C
N=(l*f)/(0.593e6*sqrt(V0))
#(ii) Power Gain
Ap=-9.54+(47.3*C*N)
print 'Power gain: %0.3f'%Ap,'dB'
ve=0.593e6*sqrt(V0)
be=(2*pi*f)/ve
#Four propogation constants
gam1=((-sqrt(3)*be*C)/2)+(1J*be*(2+C))/2
gam2=((sqrt(3)*be*C)/2)+(1J*be*(2+C))/2
gam3=1J*be*(1-C)
gam4=-1J*be*(1-((C*C*C)/4))
print 'Four propogation constants:\n {:.3f}\n{:.3f}\n{:.3f}\n{:.3f}\n'.format(gam1,gam2,gam3,gam4)
#Calculations for propogation constants are wrong in book for gam 3 and 4, hence answers dont match
#Given
I0=20e-3 #A
V0=4e3 #V
Z0=100 #ohm
N=30
C=((I0*Z0)/(4*V0))**(1/3)
#Gain
Ap=-9.54+(47.3*C*N)
print 'Gain:' ,Ap,'dB'
#Given
c=3e8 #m/s
d=2e-3 #m
p=50e2 #turns per m
e=1.6e-19 #J
m=9.1e-31
# Axial phase velocity
vp=c/(pi*p*d)
print 'Axial phase velocity: %0.3f'%vp,'m/s'
#Anode voltage
V0=(m*vp*vp)/(2*e)
print 'Anode voltage: %0.3f'%V0, 'V'
from math import sin
#Given
a=(4.4*pi)/180 #radians
c=3e8 #m/s
f=8e9 #Hz
al=2 #Np/m
#Phase velocity
vp=c*sin(a)
#Propogation constant
be=(2*pi*f)/vp
gam=al+(1J*be)
print 'Propogation constant: {:.3f}'.format(gam)
#Given
Vc=11e3 #V
Ir=0.85 #A
V0=31e3 #V
Pout=50e3 #W
I=7 #A
#Electronic efficiency
ne=Pout/(V0*I)
print 'Electronic efficiency: %0.3f'%(ne*100), '%'
#Overall efficiency
no=Pout/(Vc*(I-Ir))
print 'Overall efficiency: %0.3f'%(no*100), '%'
#Answer for elecytronic efficiency should be 23.04% but it is given as 36.4 in book
#Given
I0=0.95 #A
V0=7e3 #V
Z0=20 #ohm
N=20
C=((I0*Z0)/(4*V0))**(1/3)
#Gain
Ap=-9.54+(47.3*C*N)
print 'Gain: %0.3f'%Ap,'dB'
#Given
Vc=12e3 #V
V0=30e3 #V
Pout=60e3 #W
I=7.5 #A
#Electronic efficiency
ne=Pout/(V0*I)
print 'Electronic efficiency: %0.3f'%(ne*100), '%'
#Overall efficiency
no=Pout/(Vc*I)
print 'Overall efficiency: %0.3f'%(no*100),'%'
#Given
Vc=20e3 #V
V0=32e3 #V
Pout=75e3 #W
I=7 #A
#Electronic efficiency
ne=Pout/(V0*I)
print 'Electronic efficiency: %0.3f'%(ne*100),'%'
#Overall efficiency
no=Pout/(Vc*I)
print 'Overall efficiency: %0.3f'%(no*100), '%'
#Given
I0=500e-3 #A
V0=10e3 #V
Z0=25 #ohm
l=.20 #m
f=5.93e9 #Hz
#Gain parameter
C=((I0*Z0)/(4*V0))**(1/3)
print 'Gain parameter: %0.3f'%C
N=(l*f)/(0.593e6*sqrt(V0))
#Gain
Ap=-9.54+(47.3*C*N)
print 'Gain of TWT: %0.3f'%Ap,'dB'
#Given
Pout=250 #W
n=0.15
V0=7.5e3 #V
f=6.15e9 #Hz
c=3e8 #m/s
#(i) Input Power
Pi=Pout/n
print 'Input Power: %0.3f'%Pi,'W'
#(ii) Beam current
I0=Pi/V0
print 'Beam current: %0.3f'%I0,'A'
#(iii) Beam velocity
vb=0.593e6*sqrt(V0)
print 'Beam velocity: %0.3f'%vb, 'm/s'
#(iv) Radius of helix
a=(2*vb)/(2*pi*f)
print 'Radius of helix: %0.3f'%a,'m'
#(v) Electron beam radius
r=(3*a)/4
print 'Electron beam radius: %0.3f'%r, 'm'
#(vi) Pitch of helix
p=(2*pi*a*vb)/c
print 'Pitch of helix: %0.3f'%p,'m'
#(vii) Current density
J0=I0/(pi*r*r)
print 'Current density: %0.3f'%(J0/1000),'kA/msqr'
#(viii) Magnetic field for beam confinement
B=(4*8.3e-4*sqrt(I0/(r*r*sqrt(V0))))
print 'Magnetic field for beam confinement:' ,round(B*1000),'mT'
#Given
I0=30e-3 #A
V0=3e3 #V
Z0=10 #ohm
l=0.1624 #m
f=10e9 #Hz
C=((I0*Z0)/(4*V0))**(1/3)
N=(l*f)/(0.593e6*sqrt(V0))
#Gain
Ap=-9.54+(47.3*C*N)
print 'Gain: %0.3f'%Ap,'dB'
ve=0.593e6*sqrt(V0)
be=(2*pi*f)/ve
#Four propogation constants
gam1=((-sqrt(3)*be*C)/2)+(1J*be*(2+C))/2
gam2=((sqrt(3)*be*C)/2)+(1J*be*(2+C))/2
gam3=1J*be*(1-C)
gam4=-1J*be*(1-((C*C*C)/4))
print 'Four propogation constants:\n {:.3f}\n{:.3f}\n{:.3f}\n{:.3f}\n'.format(gam1,gam2,gam3,gam4)
#Calculations for propogation constants are wrong for gam 3 and 4 hence answers dont match
#Given
I0=35e-3 #A
V0=4e3 #V
Z0=20 #ohm
f=10e9 #Hz
#(i) Gain parameter
C=((I0*Z0)/(4*V0))**(1/3)
print 'Gain parameter:' ,C
ve=0.593e6*sqrt(V0)
be=(2*pi*f)/ve
#Four propogation constants
gam1=((-sqrt(3)*be*C)/2)+(1J*be*(2+C))/2
gam2=((sqrt(3)*be*C)/2)+(1J*be*(2+C))/2
gam3=1J*be*(1-C)
gam4=-1J*be*(1-((C*C*C)/4))
print 'Four propogation constants:\n {:.3f}\n{:.3f}\n{:.3f}\n{:.3f}\n'.format(gam1,gam2,gam3,gam4)
#Calculations for propogation constants are wrong hence answers dont match