{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from __future__ import print_function\n", "from ipywidgets import interact, interactive, fixed\n", "import ipywidgets as widgets\n", "import numpy as np\n", "from numpy import exp, pi, sin, cos\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Using the analytical solution used by Siau (1984):\n", "\n", "$$\n", "E = 1-1.27\\exp{(-2.47\\tau)}\\cos{\\left(\\frac{\\pi}{2}\\frac{x}{l}\\right)}+0.425\\exp{(-22.2\\tau)}\\cos{\\left(\\frac{3\\pi}{2}\\frac{x}{l}\\right)}\n", "$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Where $l$ is half-thickness of the sample, $x$ is the position in the sample, and $\\tau = tD/l^2$, we can formulate this into the following Python function:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def E_x(tau,x,l):\n", " E = (1-1.27*exp(-2.47*tau)*cos(pi/2*x/l)\n", " +0.425*exp(-22.2*tau)*cos(3*pi/2*x/l))\n", " return E" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The following is the interactive plot for visualizing the \n", "$E$ values for various values of $\\tau$ and $l = 3$ mm:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "fc342ced17e1409d9bf0025a477db0e2", "version_major": 2, "version_minor": 0 }, "text/plain": [ "interactive(children=(FloatSlider(value=0.2, description='tau', max=3.0, step=0.01), Output()), _dom_classes=(…" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def plotE(tau):\n", " li = 3\n", " xi = np.linspace(-li,li,num=100)\n", " E_xi = E_x(tau,xi,li)\n", " plt.plot(xi,E_xi)\n", " plt.title(f'tau = {tau}')\n", " plt.xlabel('x')\n", " plt.ylabel('E')\n", " plt.ylim(-0.1,1)\n", " plt.show()\n", "interact(plotE,\n", " tau = widgets.FloatSlider(min=0,max=3,step=0.01,value=0.2))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6.8" } }, "nbformat": 4, "nbformat_minor": 2 }
 %% Cell type:code id: tags:  python from __future__ import print_function from ipywidgets import interact, interactive, fixed import ipywidgets as widgets import numpy as np from numpy import exp, pi, sin, cos import matplotlib.pyplot as plt  %% Cell type:markdown id: tags: Using the analytical solution used by Siau (1984): $$E = 1-1.27\exp{(-2.47\tau)}\cos{\left(\frac{\pi}{2}\frac{x}{l}\right)}+0.425\exp{(-22.2\tau)}\cos{\left(\frac{3\pi}{2}\frac{x}{l}\right)}$$ %% Cell type:markdown id: tags: Where $l$ is half-thickness of the sample, $x$ is the position in the sample, and $\tau = tD/l^2$, we can formulate this into the following Python function: %% Cell type:code id: tags:  python def E_x(tau,x,l): E = (1-1.27*exp(-2.47*tau)*cos(pi/2*x/l) +0.425*exp(-22.2*tau)*cos(3*pi/2*x/l)) return E  %% Cell type:markdown id: tags: The following is the interactive plot for visualizing the $E$ values for various values of $\tau$ and $l = 3$ mm: %% Cell type:code id: tags:  python def plotE(tau): li = 3 xi = np.linspace(-li,li,num=100) E_xi = E_x(tau,xi,li) plt.plot(xi,E_xi) plt.title(f'tau = {tau}') plt.xlabel('x') plt.ylabel('E') plt.ylim(-0.1,1) plt.show() interact(plotE, tau = widgets.FloatSlider(min=0,max=3,step=0.01,value=0.2))  %%%% Output: display_data %%%% Output: execute_result