import math
#Variable declaration
h=1.5*10**-6 #peak gain wavelength
delt=10**-9 #mode spacing
l=300*10**-6 #length
c=2.998*10**8 #speed of light
r=0.09 #facet reflectivities
gs=3.020
#Calculation
n=(h**2)/(2*delt*l) #refractive index
a=c/(math.pi*n*l)
d=1-(math.sqrt(r)*gs)
f=2*math.sqrt(math.sqrt(r)*gs)
B=a*math.asin(d/f) #spectral bandwidth
#Result
print'Refractive index of a medium = %.2f'%n
print'3dB spectral bandwidth = %.1f GHz'%(B*10**-9)
import math
#Variable declaration
gs=30 #gain in dB
g=200 #net gain
loge=0.434 #log(e)
gs1=1000
m=2.2 #mode no
nsp=4 #spontaneous emission factor
h1=6.626*10**-34 #plancks constant
f=1.94*10**14
B=1.0*10**12 #bandwidth
#Calculation
L=gs/(10*g*loge) #length of the device
P=m*nsp*(gs1-1)*h1*f*B #noise power spectral density
#Result
print'(a) Length of the device = %.2f mm'%(L*10**3)
print'(b) Noise power spectral density = %.2f mW'%(P*10**3)
import math
#Variable declaration
Gp=62.2 #parametric peak gain in dB
log=10*math.log10(0.25)
Pp=1.4 #signal power in watt
L=500 #length in meter
log2=20*math.log10(2.7182818284)
#Calculation
y=(Gp-log)/(Pp*L*log2) #fiber nonlinear coefficient
Gp2=10*math.log10((y*Pp*L)**2) #parametric gain
#Result
print'(a) Fiber nonlinear coefficient = %.2f x 10^-3 W^-1 km^-1'%(y*1000)
print'(b) Quadratic gain, Gp = %.2f dB'%(Gp2)
import math
#Variable declaration
pt=0.5*10**-3 #input signal power
dpt=0.01*10**-6 #input signal power variation
h=1.55*10**-6 #signal wavelength
a=-1 #linewidth enhancement factor
dn=-1.2*10**-26 #differential refractive index
#Calculation
delt=(-a*dpt)/(4*math.pi*pt) #frequency chirp
dg=(4*math.pi*dn)/(h*a) #differential gain
#Result
print'(a) Frequency chirp variation = %.2f MHz'%(delt*10**6)
print'(b) Differential gain = %.2f x10^-20 m^2'%(dg*10**20)