from __future__ import division
from math import pi
#Given
f=10e9 #Hz
C=2.5e-12 #F
Gr=2e-4 #mho
Ge=0.025e-3 #mho
Ploss=18.5e3 #W
V0=5.5e3 #V
I0=4.5 #A
w=2*pi*f
#(i) Unloaded Q
Qun=(w*C)/Gr
print 'Unloaded quality factor: %0.3f'%Qun
#External Q
Qe=(w*C)/Ge
print 'External quality factor: %0.3f'%Qe
#(ii) Circuit effciency
n=1/(1+(Qe/Qun))
print 'Circuit effciency: %0.3f'%(n*100), '%'
#Electronic effciency
ne=1-(Ploss/(V0*I0))
print 'Electronic effciency: %0.3f'%(ne*100), '%'
#Answer for Qe is given as 6285.6 but it should be 6283.1
from math import sqrt
#Given
V0=25e3 #V
ebym=1.76e11
B0=0.0336 #T
a=5e-2 #m
b=10e-2 #m
#(i) Cut off voltage
x=(b/((b*b)-(a*a)))**2
V=(ebym*B0*B0)/(8*x)
print 'Cut off voltage: %0.3f'%(V/1000),'KV'
#(ii) Cut off magnetic field
y=((8*V0*x)/ebym)
B=sqrt(y)
print 'Cut off magnetic field: %0.3f'%(B*1000),'mT'
#Given
Pout=250e3 #W
V0=25e3 #V
I0=25 #A
ebym=1.76e11
B0=0.035 #T
a=4e-2 #m
b=8e-2 #m
#(i) Efficiency
n=Pout/(V0*I0)
print 'Efficiency:' ,n*100,'%'
#(ii) Cyclotron frequency
f=(ebym*B0)/(2*pi)
print 'Cyclotron frequency: %0.3f'%(f/10**9),'Ghz'
#(iii) Cut off magnetic field
x=(b/((b*b)-(a*a)))**2
y=((8*V0*x)/ebym)
B=sqrt(y)
print 'Cut off magnetic field: %0.3f'%(B*1000),'mT'
#(iv) Cut off voltage
V=(ebym*B0*B0)/(8*x)
print 'Cut off voltage:' ,round(V/1000),'KV'
#Answer for Cyclotron frequency is is given as 9.8GHz but it should be 0.98 GHz as value of B0=0.035 not 0.35 as taken in part 2
#Given
Gr=3e-4 #mho
Ge=3e-5 #mho
Ploss=200e3 #W
V0=22e3 #V
I0=28 #A
#(i) Circuit effciency
n=1/(1+(Gr/Ge))
print 'Circuit effciency: %0.3f'%(n*100), '%'
#(ii) Electronic effciency
ne=1-(Ploss/(V0*I0))
print 'Electronic effciency: %0.3f'%(ne*100),'%'
#Given
f=9e9 #Hz
C=2.5e-12 #F
Gr=2e-4 #mho
Ge=2.5e-5 #mho
Ploss=18.5e3 #W
V0=5.5e3 #V
I0=4.5 #A
#(i) Angular resonant frequency
w=2*pi*f
print 'Angular resonant frequency: %0.3f'%w, 'rad/s'
#(ii) Unloaded Q
Qun=round((w*C)/Gr)
print 'Unloaded quality factor:' ,Qun
#(iii) Loaded Q
Ql=round((w*C)/(Gr+Ge))
print 'Loaded quality factor:' ,Ql
#(iv) External Q
Qe=(w*C)/Ge
print 'External quality factor: %0.3f'%Qe
#(v) Circuit effciency
n=1/(1+(Qe/Qun))
print 'Circuit effciency: %0.3f'%(n*100),'%'
#(vi) Electronic effciency
ne=1-(Ploss/(V0*I0))
print 'Electronic effciency: %0.3f'%(ne*100), '%'
#Answer for external Q is given as 56.57 but it should be 5654.8
#Given
f=4e9 #Hz
V0=25e3 #V
I0=3 #A
B0=0.3 #T
D=0.8
Z0=50 #ohm
ebym=1.76e11
#(i) Electron beam phase constant
be=(2*pi*f)/sqrt(2*ebym*V0)
print 'Electron beam phase constant: %0.3f'%be,'rad/s'
#(ii) Gain Parameter
C=((I0*Z0)/(4*V0))**(1/3)
print 'Gain Parameter: %0.3f'%C
#(iii) Length for oscillation condition
N=1.25/D
l=(2*pi*N)/be
print 'Length for oscillation condition: %0.3f'%l,'m'
#Given
N=20
t=0.2e-6 #s
DC=0.001 #Duty cycle
#(i) Agile excursion
A=N/t
print 'Agile excursion:' ,A/10**6,'MHz'
#(ii) Signal frequency
f=DC/t
print 'Signal frequency:',f/1000, 'Khz'
#(iii) Agile rate
R=f/(2*N)
print 'Agile Rate:',R, 'Hz'
from math import log10
#Given
V0=1.8e3 #V
I0=1.3 #A
Pin=70 #W
n=0.22
#(i) Power generated
Pgen=n*I0*V0
print 'Power generated:' ,Pgen,'W'
#(ii) Total RF power generated
Pt=Pin+Pgen
print 'Total RF power generated:' ,Pt,'W'
#(iii) Power gain
G=Pt/Pin
Gdb=10*log10(G)
print 'Power Gain: %0.3f'%Gdb,'dB'
#Given
V0=10e3 #V
I0=2 #A
b=4e-2 #m
a=3e-2 #m
B0=0.01 #Wb/m2
ebym=1.759e11
#Cut off voltage
x=1-((b*b)/(a*a))
V=(ebym*(B0**2)*(a**2)*(x**2))/8
KV=V/1000 #Kilovolts
print 'Cut off voltage: %0.3f'%KV, 'KV'
#Magnetic flux density
y=-sqrt((8*V0)/ebym)
B=y/(a*x)
print 'Magnetic flux density: %0.3f'%B, 'T'
#Given
V0=10e3 #V
I0=2 #A
b=4e-2 #m
a=3e-2 #m
B0=0.01 #Wb/m2
ebym=1.759e11
#Cut off voltage
x=1-((b*b)/(a*a))
V=(ebym*(B0**2)*(a**2)*(x**2))/8
print 'Cut off voltage: %0.3f'%(V/1000), 'KV'
#Magnetic flux density
y=-sqrt((8*V0)/ebym)
B=y/(a*x)
print 'Magnetic flux density: %0.3f'%B, 'T'
#Given
e=1.6e-19 #J
B0=0.01 #Wb/m2
d=6e-2 #m
V0=20e3 #V
ebym=1.759e11
#(i) Hull cut off voltage
Voc=(B0*B0*d*d*ebym)/2
print 'Hull cut off voltage:' ,Voc/1000,'KV'
#(ii) Hull magnetic field
Boc=sqrt((2*V0)/ebym)/d
print 'Hull magnetic field: %0.3f'%(Boc*1000),'mT'
#Given
V0=10e3 #V
V01=5e3 #V
I0=2 #A
b=3e-2 #m
a=2e-2 #m
B0=0.01 #Wb/m2
ebym=1.759e11
#Cut off voltage
x=1-((b*b)/(a*a))
V=(ebym*(B0**2)*(a**2)*(x**2))/8
KV=V/1000 #Kilovolts
print 'Cut off voltage: %0.3f'%KV,'KV'
#Magnetic flux density
y=-sqrt((8*V01)/ebym)
B=y/(a*x)
print 'Magnetic flux density: %0.3f'%B, 'Wb/m2'
#Answer in book is wrong for Magnetic flux density as a*a ,where a=2, is taken as 5, which should be 4
#Given
N=15
t=0.3e-6 #s
DC=0.0011 #Duty cycle
#(i) Agile excursion
A=N/t
print 'Agile excursion:',A/10**6, 'MHz'
#(ii) Pulse to pulse frequency seperation
fp=1/t
print 'Pulse to pulse frequency seperation: %0.3f'%(fp/10**6),'Mhz'
#(iii) Signal frequency
f=DC/t
print 'Signal frequency: %0.3f'%(f/1000), 'Khz'
#(iv) Agile rate
Tp=N/f
R=1/(2*Tp)
print 'Agile Rate: %0.3f'%R,'ps'