import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from ipywidgets import StaticInteract, RangeWidget
x = np.linspace(-2*np.pi,2*np.pi,501)
sum = 0
for i in range(10):
sum += np.sin(i*x)
plt.plot(sum**2)
[<matplotlib.lines.Line2D at 0xaffd28cc>]
x = np.linspace(-2*np.pi,2*np.pi,501)
def plot(i):
fig, ax = plt.subplots(figsize=(6, 6),
subplot_kw={'axisbg':'#EEEEEE',
'axisbelow':True})
ax.grid(color='w', linewidth=2, linestyle='solid')
sum = 0
for i in range(10):
sum += np.sin(i*x)
ax.plot(x,sum**2, lw=5, alpha=0.4)
#ax.set_xlim(-50, 50)
#ax.set_ylim(0, 1)
return fig
StaticInteract(plot,i=RangeWidget(1, 10, 1))
print len(np.arange(-27e-9,27e-9,1e-12))
54000
A = 0
phase_factor = 0
c = 3e+08
L = 1.5
FSR = c/(2*L)
t = np.arange(-27e-9,27e-9,1e-12)
#go from -27ns to +27ns in steps of 1 ps.
total = 0
Upper = 1.9355e+14 + 3e+04*FSR;
# Upper frequency limit : c / lambda+%(80comb modes * FSR )
f = np.arange(1.9355e14,Upper,FSR)
#for i in range(len(f)+1):
for i in range(1000):
# go from fundamental laser frequenc y to 148
# higher freqs by steps of 1 FSR
#phase = np.random.rand()*phase_factor;
#E = A*np.cos(2*np.pi*f[i]*t + phase);
E += A*np.cos(2*np.pi*f[i]*t)
#total = total+E;
time = t/(1e-9);
#plt.plot(time,total/max(total));
plt.plot(time,E/max(E));
plt.xlim([-20,20]);
'''
figure; plot(time,(total)/max((total)));
xlabel('time/ns');
'''
-c:22: RuntimeWarning: invalid value encountered in divide
"\nfigure; plot(time,(total)/max((total)));\n\nxlabel('time/ns');\n"
max(total)
0.0
A = 1
phase_factor = 0
c = 3e+08
L = 1.5
FSR = c/(2*L)
t = np.arange(-27e-9,27e-9,1e-12)
#go from -27ns to +27ns in steps of 1 ps.
total = 0
Upper = 1.9355e+14 + 3e+04*FSR
# Upper frequency limit : c / lambda+%(80comb modes * FSR )
f = np.arange(1.9355e14,Upper,FSR)
temp = 0
for i in range(10):
temp += np.cos(2*np.pi*f[i]*t)
plt.plot(t,temp**2/max(temp**2))
[<matplotlib.lines.Line2D at 0xb114c6ac>]
A = 1
phase_factor = 0
c = 3e+08
L = 1.5
FSR = c/(2*L)
t = np.arange(-27e-9,27e-9,1e-12)
#go from -27ns to +27ns in steps of 1 ps.
total = 0
Upper = 1.9355e+14 + 3e+04*FSR
# Upper frequency limit : c / lambda+%(80comb modes * FSR )
f = np.arange(1.9355e14,Upper,FSR)
def plot(i):
fig, ax = plt.subplots(figsize=(6, 6),
subplot_kw={'axisbg':'#EEEEEE',
'axisbelow':True})
ax.grid(color='w', linewidth=2, linestyle='solid')
temp = 0
j = 0
while j < i:
temp += np.cos(2*np.pi*f[j]*t)
j += 1
ax.plot(t,temp/max(temp), lw=5, alpha=0.4)
#ax.set_xlim(-50, 50)
#ax.set_ylim(0, 1)
return fig
StaticInteract(plot,i=RangeWidget(1, 5, 1))
A = 1
phase_factor = 0
c = 3e+08
L = 1.5
FSR = c/(2*L)
x = np.arange(0,6,1e-02)
#go from -27ns to +27ns in steps of 1 ps.
total = 0
Upper = 1.9355e+14 + 3e+04*FSR
# Upper frequency limit : c / lambda+%(80comb modes * FSR )
f = np.arange(1.9355e14,Upper,FSR)
#x = np.linspace(0,np.pi/2.,21)
def plot(t):
fig, ax = plt.subplots(figsize=(4, 3),
subplot_kw={'axisbg':'#EEEEEE',
'axisbelow':True})
ax.grid(color='w', linewidth=2, linestyle='solid')
temp = 0
j = 0
while j < 5:
temp += np.cos(2*np.pi*f[j]*(x/c -t*1e-08))
j += 1
ax.plot(x,temp**2/max(temp**2), lw=5, alpha=0.4)
#ax.set_xlim(-50, 50)
#ax.set_ylim(0, 1)
return fig
StaticInteract(plot,t=RangeWidget(0.5, 2.5, 0.25))