from __future__ import division
from math import sqrt, pi
#Given
f=10e9 #Hz
v=9e3 #V
i=40e-3 #A
l=3 #cm
l1=l/100 #m
G=2e-6 #mho
bet=0.92
j1x=0.582
x=1.841
ebym=1.7e11 #J
#Maximum voltage
w=2*pi*f
v0x=sqrt(2*ebym)
thet=(w*l1)/(v0x*sqrt(v))
av=(bet**2*thet*i*j1x)/(x*v*G)
print 'Maximum voltage:%0.3f'%av,'V'
#Power Gain
ic=2*i*j1x
v2=(bet*ic)/G
pout=bet*ic*v2
pin=2*i*v
#Efficiency
eet=pout/pin
print 'Power gain: %0.3f'%(eet*100), '%'
#Answer for effciency comes out to be wrong, it is calculted wrongly in book
#Given
l=2 #cm
l1=l/100 #m
f=5e9 #Hz
i=25e-3 #A
n=21/4
e=1.6e-19
m=9.1e-31
thetag=0
bet=1
j1x=0.582
x=1.841
#(i) Beam Voltage
v0=(m*l1*l1*f*f)/(2*e*n*n)
print 'Beam voltage: %0.3f'%v0, 'V'
#(ii) Input voltage
v1=x*v0/(pi*bet*n)
print 'Input voltage: %0.3f'%v1,'V'
#(iii) Output voltage
v2=0.25*v0
print 'Output voltage %0.3f'%v2,'V'
#(iv) Power output
pmax=i*v0*j1x
print 'Maximum power output: %0.3f'%pmax, 'W'
#(v) Efficiency
eet=j1x*bet*v2/v0
print 'Efficiency:' ,eet*100,'%'
from math import sin
#Given
r0=45e3 #W
j0=25e-3 #A
V=1500 #V
f=5e9 #hz
d=1 #mm
d1=d/1000 #m
l=3.5 #cm
l1=l/100 #m
rsh=32e3 #ohms
j1x=0.582
x=1.841
#(i) Input gap voltage
w=2*pi*f
v0=(5.93e5*sqrt(V))
thetag=(w*d1)/v0
bet=sin(thetag/2)/(thetag/2)
theta0=(w*l1)/v0
v1=(2*V*x)/(bet*theta0)
print 'Input gap voltage: %0.3f'%v1
#(ii) Voltage gain
av=(bet**2*theta0*j1x*rsh)/(r0*x)
print 'Voltage gain %0.3f'% av
from math import cos
#Given
V=1000 #V
r0=40e3 #ohm
i0=25e-3 #A
f=3e9 #Hz
d=1 #mm
d1=d/1000 #m
l=4 #cm
l1=4/100 #m
j1x=0.582
x=1.841
rsh=30e3 #ohm
#(i) Input gap voltage
w=2*pi*f
v0=(5.93e5*sqrt(V))
thetag=(w*d1)/v0
bet=sin(thetag/2)/(thetag/2)
theta0=(w*l1)/v0
vmax=(2*V*x)/(bet*theta0)
print 'Input gap voltage: %0.3f'%vmax, 'V'
#(ii) Voltage gain
av=(bet*bet*theta0*j1x*rsh)/(r0*x)
print 'Voltage gain: %0.3f'%av
#(iii) Efficiency
v2=bet*2*i0*j1x*rsh
eet=(bet*2*i0*j1x*v2)/(2*i0*V)
print 'Efficiency: %0.3f'%(eet*100),'%'
#(iv) Beam loading conductance
gbl=(i0/(2*V))*((bet*bet)-(bet*cos(thetag/2)))
print 'Beam loading conductance:%0.3e'%gbl
#Answer for beam loading conductance is calculated wrong in book
#Given
f=3e9 #hz
v=900 #V
i=30e-3 #A
d=4 #cm
d1=d/100 #m
gap=1 #mm
gap1=1/1000 #m
rsh=40e3 #ohm
x=1.841
j1x=0.582
r=40e3 #ohm
ebym=1.758e11 #J
#(i) Electron velocity
v0=sqrt(2*ebym*v)
print 'Electron velocity: %0.3f'%v0,'m/s'
#(ii) Electron transit time
t=d1/v0
print 'Electron transit time: %0.3f'%t,'s'
#(iii) Input voltage gap
w=2*pi*f
theta0=(w*d1)/v0
thetag=(w*gap1)/v0
bet=sin(thetag/2)/(thetag/2)
v2=(2*v*x)/(bet*theta0)
print 'Input voltage gap: %0.3f'%v2, 'V'
#(iv) Voltage gain
av=(bet**2*theta0*j1x*rsh)/(x*r)
print 'Voltage gain: %0.3f'%av
#Values of v and f are changed in question and answer, hence vaules used in answer are taken.
#Also second part has not been done in book
from math import sqrt, log10
#Given
f=8e9 #hz
i=2.5 #A
v=20e3 #V
bet=1
amp=10*sqrt(2) #V
rsh=10e3 #ohm
rsho=30e3 #ohm
dc=1e-6 #c/m**3
rf=0.5
e=1.6e-19
ee=8.854e-12
m=9.1e-31 #kg
#(i) Induced current
w=2*pi*f
wq=rf*sqrt((e*dc)/(m*ee))
#Amplitude of induced current
ic=(i*w*(bet**2)*amp)/(2*v*wq)
print 'Induced current: %0.3f'%ic,'A'
#Induced voltage
icrms=ic/sqrt(2)
v2rms=icrms*rsho
print 'Induced voltage: %0.3f'%v2rms,'V'
#(ii) Power gain
pg=(((i*w)**2)*(bet**4)*rsh*rsho)/(4*((v*wq)**2))
pgdb=10*log10(pg)
print 'Power gain: %0.3f'%pgdb,'dB'
#(iii) Electronic efficiency
eeta=((icrms**2)*rsho)/(i*v)
print 'Electronic efficiency: %0.3f'%(eeta*100),'%'
#Given
f=3e9 #hz
l=4 #cm
l1=4/100 #m
d=0.1 #cm
d1=d/100 #m
V=900 #V
i0=30e-3 #A
rsh=25e3 #ohm
x=1.841
j1x=0.582
#(i) Input voltage for maximum output
v0=0.593e6*sqrt(V)
w=2*pi*f
theta0=w*l1/v0 #rad
thetag=w*d1/v0 #rad
bet=sin(thetag/2)/(thetag/2)
v1max=2*V*x/(bet*theta0) #v
print 'Input voltage for maximum output: %0.3f'%v1max,'V'
#(ii) Voltage gain
r0=V/i0 #ohm
av=((bet**2)*theta0*j1x*rsh)/(x*r0) #V
print 'Voltage gain: %0.3f'%av, 'V'
#(iii) Efficiency
ic=2*i0*j1x #A
v2=bet*ic*rsh #V
eet=bet*ic*v2/(2*i0*V)
print 'Efficiency: %0.3f'%(eet*100), '%'
#(iv) Beam loading conductance
gb=(i0/(V*2))*(bet**2-(bet*cos(thetag/2))) #ohm
print 'Beam loading conductance: %0.3e'%gb,'ohm'
#Given
f=5e9 #hz
v0=10e3 #V
d=1 #mm
d1=d/1000 #m
v1=100 #V
#(i) Gap transit time
vv0=0.593e6*sqrt(v0) #m/sec
tau=d1/vv0 #sec
print 'Gap transit time: %0.3e'%tau,'sec'
#Gap transit angle
w=2*pi*f
thetag=w*tau #rad
print 'Gap transit angle: %0.3f'%thetag, 'rad'
#(ii) Beam coupling coefficient
betin=sin(thetag/2)/(thetag/2)
print 'Beam coupling coefficient: %0.3f'%betin
#(iii) Velocity of electron leaving buncher gap
vig=vv0*(1+((betin*v1)/(2*v0))) #m/sec
print 'Velocity of electron leaving buncher gap: %0.3f'%vig, 'm/sec'
#(iv) Depth of modulation
m=betin*v1/v0
print 'Depth of modulation: %0.3f'%m
#Given
f=10e9 #hz
v0=15e3 #V
i0=2.5e-3 #A
d=1 #cm
d1=d/100 #m
vrms=10 #V
bet=1
p=1e-8 #C/m**3
rf=0.6
e=1.6e-19
m=9.1e-31
ee=8.854e-12
#(i) DC electron beam phase cobstant
vv0=(0.593e6*sqrt(v0))
w=2*pi*f
bete=w/vv0 #rad/m
print 'DC electron beam phase constant: %0.3f'%bete,'rad/m'
#(ii) Reduced plasma frequency and reduced plasma phase constant
wq=rf*sqrt(e*p/(m*ee)) #rad/m
print 'Reduced plasma frequency: %0.3f'%wq,'rad/m'
betq=wq/vv0 #rad/sec
print 'Reduced plasma phase constant: %0.3f'%betq,'rad/sec'
#(iii) Gap transit time
tau=d1/vv0 #sec
vtg=vv0*(1+(bet*vrms*sin(w*tau)/(2*v0))) #m/sec
print 'Gap transit time: %0.3f'%vtg, 'm/sec'
#Given
f=4e9 #hz
v0=10e3 #V
i0=0.75 #A
v1=2 #V
bet=1
rsh=10e3 #ohm
p=5e-5 #C/m**3
r=0.6
rsht=4e3 #ohm
e=1.6e-19
m=9.1e-31
ee=8.854e-12
#(i) Induced current and voltage in output cavity
w1=sqrt(e*p/(m*ee)) #rad/sec
w=2*pi*f
wq=0.5*w1 #rad/sec
rr=w/wq
i4=((i0**3)*(rr**3)*(bet**6)*v1*(rsh**2))/(8*(v0**3)) #A
print 'Induced current: %0.3f'%i4,'A'
v4=i4*rsht #V
print 'Induced voltage: %0.3f'%(v4/1000), 'kV'
#(ii) Power output
pout=(i4**4)*rsht #W
print 'Power output: %0.3f'%pout, 'W'
#Answer for Pout should be 13.43 kW but it is given as 10.89kW as value of I4 is calculated as 1.289 but it comes out to be 1.35
#Given
f=8e9 #hz
v0=500 #V
l=1.2 #mm
l1=l/1000 #m
rsh=18e3 #ohm
ebym=1.759e11
ee=8.854e-12
#(i) Repeller voltage
n=1+(3/4)
v11=(ebym*n*n)/(8*(l1**2)*(f**2))
vr=sqrt(v0/v11)-v0
print 'Repeller voltage: %0.3f'%vr,'V'
#(ii) Required dc current
v2=200 #V
j1x=0.582
i=v2/(2*rsh*j1x) #A
print 'Required dc current: %0.3f'%(i*1000), 'mA'
#Answer for repeller voltage is calculated wrong in book
#Given
f=9e9 #hz
v0=361 #V
i0=30e-3 #A
l=0.1 #cm
l1=l/100 #m
x=2.408
j1x=0.582
ebym=1.759e11
#Maximum power output
n=1
pout=2*i0*v0*x*j1x/(2*pi*(n+(3/4))) #W
print 'Maximum power output: %0.3f'%pout,'W'
#Operating repeller voltage
vr=((6.744e-6*sqrt(v0)*l1*f)/(n+(3/4)))-v0 #v
print 'Operating repeller voltage: %0.3f'%vr,'V'
#Given
f=9e9 #hz
v0=250 #V
l=0.5 #cm
l1=l/100 #m
#Bandwidth
n=3
df=(n+(3/4))/(6.774e-6*l1*sqrt(v0)) #hz
print 'Bandwidth: %0.3f'%(df/10**6),'Mhz'
#Given
f=10e9 #hz
v0=600 #V
vr=250 #V
ebym=1.759e11
#Repeller space
n=1
l=sqrt((ebym*(n+(3/4))**2*(vr+v0)**2)/(8*f**2*v0)) #m
print 'Repeller space: %0.3f'%(l*1000),'mm'
#Given
v0=300 #V
i0=20e-3 #A
v1=40 #V
n=2
x=2.408
j1x=0.52
#(i) Input power
pin=i0*v0 #W
print 'Input power:' ,pin,'W'
#(ii) Output power
pout=(2*v0*i0*x*j1x)/((2*pi*n)-(pi/2)) #W
print 'Output power: %0.3f'%pout, 'W'
#Efficiency
eet=pout/pin
print 'Efficiency: %0.3f'%(eet*100), '%'
#Answer for output power in book is 0.7 which is wrong, it should be 1.3W
#Hence answer of efficiency also changes
#Given
f=10e9 #hz
v0=600 #V
l=0.1 #cm
l1=l/100 #m
bet=0.9
ebym=1.759e11
n=2
j1x=0.575 #from standard table
#(i) Repeller voltage
vr=((6.744e-6*sqrt(v0)*l1*f)/(n-(1/4)))-v0 #V
print 'Repeller voltage:',round(vr), 'V'
#(ii) Bunching parameter
v1=200 #V
x=bet*v1*2*pi*(n-(1/4))/(2*v0)
print 'Bunching parameter: %0.3f'%x
#(iii) Required DC current
rsh=20e3 #ohm
i=v1/(2*rsh*j1x) #A
print 'Required DC current: %0.3f'%(i*1000),'mA'
#(iv) Electronic efficiency
eet=2*x*j1x/(2*pi*(n-(1/4)))
print 'Electronic efficiency:',eet*100, '%'
#Given
f=10e9 #hz
v0=300 #V
j0=0.3 #A/cm
i0=45e-3 #A
rb=sqrt(i0/(pi*j0)) #mm
print 'Electron beam radius: %0.3f'%(rb*10),'mm'
r=rb*(120/100) #mm
print 'Radius of cathode disc:%0.3f'%(r*10),'mm'
d=sqrt(2.335e-6*(300)**(3/2)/j0) #mm
print 'Cathode anode spacing: %0.3f'%(d*10),'mm'
#Anode hole has to be 15% larger than cathode disc
ra=r*1.15 #mm
print 'Anode hole: %0.3f'%(ra*10),'mm'
from math import tan, exp
#Given
f=9e9 #hz
v0=300 #V
vr=125 #V
bet=0.9
c=3e8 #m/s
w=2*pi*f
br=2.18 #mm
e0=8.854e-12
ebym=1.7e11
#From sin(theta)/theta table, thetag is found out to be
thetag=0.25*pi
d=(2*thetag*0.593e6*sqrt(v0))/w
print 'Distance: %0.3f'%(d*1000),'mm'
#Axial cavity length
l=c/(10*f) #m
print 'Axial cavity length: %0.3f'%(l*1000),'mm'
#Ratio of outer to inner conductor
a=1.5*br
a1=a/1000
x=d/(w*e0*a1*a1*60*tan((w*l)/c))
bbya=exp(x)
print 'Ratio of outer to inner conductor: %0.3f'%bbya
#radii of outer and inner conductor
print 'Radius of outer conductor:',a, 'mm'
b=1.52*a #mm
print 'Radius of inner conductor:' ,b,'mm'
#Repeller spacing
lopt=sqrt(ebym*(19/4)**2*(v0+vr)**2/(8*f**2*v0)) #m
print 'Repeller spacing: %0.3f'%(lopt*1000),'mm'
#Answer for radii of outer and inner conductor have wrong calculations in book
#Also ratio of outer to inner conductor is also calculated wrong