{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Theory" ] }, { "cell_type": "markdown", "source": [], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2024-04-02T04:45:32.196685Z", "start_time": "2024-04-02T04:45:30.147713Z" } }, "outputs": [ { "data": { "text/plain": "interactive(children=(FloatSlider(value=1.0, description='E0', max=2.0, min=0.1), FloatSlider(value=1.0, descr…", "application/vnd.jupyter.widget-view+json": { "version_major": 2, "version_minor": 0, "model_id": "7a7b5d47e29d4c0b9938d747926b281d" } }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": "" }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "%matplotlib inline\n", "\n", "import numpy as np\n", "from scipy.special import jv as J\n", "from scipy.integrate import cumulative_trapezoid\n", "from ipywidgets import interact\n", "import matplotlib.pyplot as plt\n", "\n", "\n", "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):\n", " Z = np.linspace(0, 10, 100)\n", "\n", " def Ez(z=Z, r=R, phi=Phi):\n", " return E0 * np.exp(-1j*beta*Z) * J(m, (k**2-beta**2)**0.5*R) * np.cos(m*Phi)\n", " \n", " mag_Ez = Ez()\n", " \n", " def En(n):\n", " Z = np.linspace(-d/2, d/2, 100)\n", " return cumulative_trapezoid(Ez(Z, 0, Phi*np.exp(1j*(beta+2*np.pi*n/d)*Z)))[-1] / d\n", " \n", " 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)])\n", " mag_Ez_sum = np.abs(Ez_sum)\n", " \n", " fig, axs = plt.subplots(1, 2, figsize=(12, 5))\n", " \n", " cax1 = axs[0].plot(Z, mag_Ez)\n", " axs[0].set_title(\"Magnitude of Ez\")\n", " axs[0].set_xlabel(\"z\")\n", " axs[0].set_ylabel(\"Ez\")\n", " \n", " cax2 = axs[1].plot(Z, mag_Ez_sum)\n", " axs[1].set_title(\"Magnitude of Ez_sum\")\n", " axs[1].set_xlabel(\"z\")\n", " axs[1].set_ylabel(\"Ez_sum\")\n", " \n", " plt.tight_layout()\n", " fig.show()\n", "\n", "\n", "interact(plot_fields,\n", " E0=(0.1, 2.0, 0.1),\n", " beta=(0.1, 5.0, 0.1),\n", " m=(0, 10),\n", " k=(0.1, 5.0, 0.1),\n", " N=(0, 20),\n", " R=(0.0, 10.0, 0.1),\n", " Phi=(0.1, 10.0, 0.1),\n", " d=(1.0, 10.0, 0.1))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.0" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }