%matplotlib inline
import numpy as np
from scipy.special import jv as J
from scipy.integrate import cumulative_trapezoid
from ipywidgets import interact
import matplotlib.pyplot as plt
def plot_fields(E0=1.0, beta=1.0, m=0, k=2.0, N=5, R=0.0, Phi=0.1, d=5.0):
Z = np.linspace(0, 10, 100)
def Ez(z=Z, r=R, phi=Phi):
return E0 * np.exp(-1j*beta*Z) * J(m, (k**2-beta**2)**0.5*R) * np.cos(m*Phi)
mag_Ez = Ez()
def En(n):
Z = np.linspace(-d/2, d/2, 100)
return cumulative_trapezoid(Ez(Z, 0, Phi*np.exp(1j*(beta+2*np.pi*n/d)*Z)))[-1] / d
Ez_sum = sum([En(n) * np.exp(-1j*(beta+2*np.pi*n/d)*Z) * J(m, (k**2-(beta+2*np.pi*n/d)**2)**0.5*R) * np.cos(m*Phi) for n in range(-N, N+1, 1)])
mag_Ez_sum = np.abs(Ez_sum)
fig, axs = plt.subplots(1, 2, figsize=(12, 5))
cax1 = axs[0].plot(Z, mag_Ez)
axs[0].set_title("Magnitude of Ez")
axs[0].set_xlabel("z")
axs[0].set_ylabel("Ez")
cax2 = axs[1].plot(Z, mag_Ez_sum)
axs[1].set_title("Magnitude of Ez_sum")
axs[1].set_xlabel("z")
axs[1].set_ylabel("Ez_sum")
plt.tight_layout()
fig.show()
interact(plot_fields,
E0=(0.1, 2.0, 0.1),
beta=(0.1, 5.0, 0.1),
m=(0, 10),
k=(0.1, 5.0, 0.1),
N=(0, 20),
R=(0.0, 10.0, 0.1),
Phi=(0.1, 10.0, 0.1),
d=(1.0, 10.0, 0.1))