{"id":829,"date":"2025-07-20T05:25:28","date_gmt":"2025-07-20T05:25:28","guid":{"rendered":"https:\/\/synchrotron-light.net\/wp\/?page_id=829"},"modified":"2025-07-21T05:28:00","modified_gmt":"2025-07-21T05:28:00","slug":"appendices","status":"publish","type":"page","link":"https:\/\/synchrotron-light.net\/wp\/?page_id=829","title":{"rendered":"Appendices"},"content":{"rendered":"<p>Below is a set of python codes associated with the Appendices of Daniele Pelliccia and David M. Paganin, &#8220;Synchrotron Light: A Physics Journey from Laboratory to Cosmos&#8221; (Oxford University Press, 2025).<\/p>\n<p>In order to run any of these python codes, you will need to include the following header.<\/p>\n<pre class=\"theme:obsidian lang:python decode:true\">from scipy import special\r\nimport numpy as np\r\nimport matplotlib.pyplot as plt\r\nimport math\r\n\r\nsynchrotron_style = {\r\n    'font.family': 'FreeSerif',\r\n    'font.size': 30,\r\n    'axes.linewidth': 2.0,\r\n    'axes.edgecolor': 'black',\r\n    'grid.color': '#5b5b5b',\r\n    'grid.linewidth': 1.2,\r\n}<\/pre>\n<h2>Appendix A: transformation linking the angular variables <span class=\"wp-katex-eq\" data-display=\"false\">\\varphi<\/span> and<\/h2>\n<h2 id=\"The-basics:-plotting-a-radial-field\"><span class=\"wp-katex-eq\" data-display=\"false\">\\psi<\/span><\/h2>\n<p>See Fig. A.1<\/p>\n<pre class=\"theme:obsidian lang:python decode:true\">phi = np.linspace(-np.pi, np.pi, 361)\r\n\r\nwith plt.style.context(('seaborn-v0_8-whitegrid')):\r\n    plt.rcParams.update(synchrotron_style)\r\n    fig = plt.figure(figsize=(8.5,6.5))\r\n    for eps in [0, 0.5, 0.999]:\r\n        plt.plot(phi, phi-eps*np.sin(phi), lw=3)   \r\n    \r\n    plt.xticks([-np.pi, -np.pi\/2, 0, np.pi\/2, np.pi], ['-$\\\\pi$', '-$\\\\pi\/2$', '0', '$\\\\pi\/2$', '$\\\\pi$'], fontsize = 26)\r\n    plt.yticks([-np.pi, -np.pi\/2, 0, np.pi\/2, np.pi], ['-$\\\\pi$', '-$\\\\pi\/2$', '0', '$\\\\pi\/2$', '$\\\\pi$'], fontsize = 26)\r\n    plt.grid(True)\r\n\r\n    plt.xlabel('$\\\\varphi$')\r\n    plt.ylabel('$\\\\psi$')   \r\n    plt.show()<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-830\" src=\"https:\/\/synchrotron-light.net\/wp\/wp-content\/uploads\/2025\/07\/shynchrotron-light-A.1.png\" alt=\"\" width=\"700\" height=\"532\" srcset=\"https:\/\/synchrotron-light.net\/wp\/wp-content\/uploads\/2025\/07\/shynchrotron-light-A.1.png 700w, https:\/\/synchrotron-light.net\/wp\/wp-content\/uploads\/2025\/07\/shynchrotron-light-A.1-480x365.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 700px, 100vw\" \/><\/p>\n<h2>Appendix B: Boundary conditions for perfectly reflecting cavity walls<\/h2>\n<p>See Fig. B.1.<\/p>\n<pre class=\"theme:obsidian lang:python decode:true\">ell = 1\r\nm = 1\r\nx1 = np.linspace(-0.2, 0, 20)\r\nx0 = np.linspace(0, ell, 100)\r\nx2 = np.linspace(ell, 1.2, 20)\r\n\r\nwith plt.style.context(('seaborn-v0_8-whitegrid')):\r\n    plt.rcParams.update(synchrotron_style)\r\n    fig, ax = plt.subplots(1, 1,figsize=(10,8))\r\n    plt.plot(x0, np.sin(np.pi*m*x0\/1), 'b', lw=4, label = \"$m=10$\")\r\n    plt.plot(x0, np.sin(2*np.pi*m*x0\/1), 'r', lw=4, label = \"$m=20$\")\r\n    plt.plot(x2, -np.sin(np.pi*m*x2\/1), 'b--', lw=4)\r\n    plt.plot(x1, -np.sin(np.pi*m*x1\/1), 'b--', lw=4)\r\n    plt.plot(x2, np.sin(2*np.pi*m*x2\/1), 'r--', lw=4)\r\n    plt.plot(x1, np.sin(2*np.pi*m*x1\/1), 'r--', lw=4)\r\n    \r\n    ax.set_xticks([0,0.5,1])\r\n    ax.set_xticklabels([\"0\", \"0.5\", \"1\"], fontsize=30)\r\n    ax.set_yticks([-1,0, 1])\r\n    ax.set_yticklabels([\"-1\", \"0\",\"1\"], fontsize=30)        \r\n    plt.xlabel('$x$', fontsize=20)\r\n    plt.ylabel('$\\\\sin(\\\\pi mx\/\\\\ell)$', fontsize=26)\r\n    plt.legend(fontsize=26, handlelength=1, frameon=True, framealpha=1, \\\r\n               loc = 'center left', bbox_to_anchor=(0.17, 0.2))\r\n    plt.show()<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-832\" src=\"https:\/\/synchrotron-light.net\/wp\/wp-content\/uploads\/2025\/07\/shynchrotron-light-B.1.png\" alt=\"\" width=\"700\" height=\"566\" srcset=\"https:\/\/synchrotron-light.net\/wp\/wp-content\/uploads\/2025\/07\/shynchrotron-light-B.1.png 700w, https:\/\/synchrotron-light.net\/wp\/wp-content\/uploads\/2025\/07\/shynchrotron-light-B.1-480x388.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 700px, 100vw\" \/><\/p>\n<h2>Appendix D: Relation between Taylor and Pad\u00e9 coefficients of <span class=\"wp-katex-eq\" data-display=\"false\">g(\\tau)<\/span><\/h2>\n<p>Calculation leading to the plot in Fig. D.1. See also Fig. 4.23.<\/p>\n<pre class=\"theme:obsidian lang:python decode:true\">def cn_recursive(n):\r\n    # Base case: c_0 = 0\r\n    if n == 0:\r\n        return 0\r\n    # Recursive case: c_n = c_{n-1}\/2 + 1\/2^(n-1)\r\n    else:\r\n        return 0.5*cn_recursive(n-1) + 1\/2**(n-1)\r\n\r\ndef derivative_K(z, N):\r\n    if N == 0:\r\n        return z*special.kv(2\/3,z\/2)\r\n    else:\r\n        return cn_recursive(N)*special.kvp(2\/3,z\/2,n=N-1) + (z\/2**N)*special.kvp(2\/3,z\/2,n=N)<\/pre>\n<p>&nbsp;<\/p>\n<pre class=\"theme:obsidian lang:python decode:true\">x = np.linspace(0.25,10.25,401)\r\n\r\n# Point of maximum\r\npoint_max = np.argmax(x*special.kv(2\/3,x\/2))\r\n\r\n# Calculate the Taylor series up the the order ord\r\nord = 4\r\na = np.zeros(ord)\r\ntayl_exp = np.zeros_like(x)\r\nfor i in range(ord):\r\n    test = derivative_K(x, i)\r\n    a[i] = test[30]\/math.factorial(i)\r\n    tayl_exp += a[i]*(x-x[30])**i\r\n\r\nA = a[0]\r\nD = (a[2]**2 - a[3]*a[1]) \/ (a[1]**2 -a[2]*a[0])\r\nC = -a[0]*D\/a[1] - a[2]\/a[1]\r\nB = a[1]+a[0]*C\r\nxmax = 1.0+(np.sqrt(A**2*D**2 + B*D*(B-A*C)) - A*D)\/(B*D)\r\npade = (A+B*(x-1)) \/ (1+C*(x-1)+D*(x-1)**2)\r\n\r\nwith plt.style.context(('seaborn-v0_8-whitegrid')):\r\n    plt.rcParams.update(synchrotron_style)\r\n    fig, axs = plt.subplots(1,2, figsize=(21,8))\r\n    axs[0].plot(x, x*special.kv(2\/3,x\/2), 'k', lw=3,label = \"Exact\")\r\n    axs[0].plot(x, tayl_exp, 'r', lw=3,label=\"Taylor\")\r\n    axs[0].plot(x, pade, 'b', lw=3,label=\"Pade'\")\r\n    axs[0].set_xlim([0.18, 1.8])\r\n    axs[0].set_ylim([1, 1.25])\r\n    \r\n    axs[0].tick_params(axis='x', labelsize=36)\r\n    axs[0].tick_params(axis='y', labelsize=36)\r\n    axs[0].set_xlabel('$\\\\tau$', fontsize=36)\r\n    axs[0].set_ylabel(\"$g(\\\\tau)$\", fontsize=36)  \r\n    axs[0].legend(fontsize = 34, frameon=True, framealpha=0.9, loc = 'upper right', labelspacing=0.3, handlelength=1)\r\n    \r\n    axs[1].plot(x, x*special.kv(2\/3,x\/2), 'k', lw=3,label = \"Exact\")\r\n    axs[1].plot(x, tayl_exp, 'r', lw=3,label=\"Taylor\")\r\n    axs[1].plot(x, pade, 'b', lw=3,label=\"Pade'\")\r\n    axs[1].set_xlim([0.18, 10])\r\n    axs[1].set_ylim([0.05, 1.25])\r\n    \r\n    axs[1].tick_params(axis='x', labelsize=32)\r\n    axs[1].tick_params(axis='y', labelsize=32)\r\n    axs[1].set_xlabel('$\\\\tau$', fontsize=36)\r\n    axs[1].set_ylabel(\"$g(\\\\tau)$\", fontsize=36)  \r\n    axs[1].legend(fontsize = 34, frameon=True, framealpha=0.9, labelspacing=0.3, handlelength=1)\r\n\r\nplt.show()<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-833\" src=\"https:\/\/synchrotron-light.net\/wp\/wp-content\/uploads\/2025\/07\/shynchrotron-light-D.1-1024x424.png\" alt=\"\" width=\"700\" height=\"290\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Below is a set of python codes associated with the Appendices of Daniele Pelliccia and David M. Paganin, &#8220;Synchrotron Light: A Physics Journey from Laboratory to Cosmos&#8221; (Oxford University Press, 2025). In order to run any of these python codes, you will need to include the following header. from scipy import special import numpy as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":79,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"class_list":["post-829","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/synchrotron-light.net\/wp\/index.php?rest_route=\/wp\/v2\/pages\/829","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/synchrotron-light.net\/wp\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/synchrotron-light.net\/wp\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/synchrotron-light.net\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/synchrotron-light.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=829"}],"version-history":[{"count":2,"href":"https:\/\/synchrotron-light.net\/wp\/index.php?rest_route=\/wp\/v2\/pages\/829\/revisions"}],"predecessor-version":[{"id":834,"href":"https:\/\/synchrotron-light.net\/wp\/index.php?rest_route=\/wp\/v2\/pages\/829\/revisions\/834"}],"up":[{"embeddable":true,"href":"https:\/\/synchrotron-light.net\/wp\/index.php?rest_route=\/wp\/v2\/pages\/79"}],"wp:attachment":[{"href":"https:\/\/synchrotron-light.net\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=829"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}