.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/special_functions/elliptic/plot_02_jacobi_elliptic_functions.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_special_functions_elliptic_plot_02_jacobi_elliptic_functions.py: Jacobi elliptic functions and the pendulum ================================================ Plots sn, cn, dn for m = 0.9, showing their real period 4K(m), and uses them to write the exact motion of a large-amplitude pendulum. .. GENERATED FROM PYTHON SOURCE LINES 10-15 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from mathematicskit.special_functions import complete_elliptic_integral_first_kind, jacobi_elliptic_functions .. GENERATED FROM PYTHON SOURCE LINES 16-18 sn, cn, dn over two periods ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 18-34 .. code-block:: Python m = 0.9 K = complete_elliptic_integral_first_kind(m) u = np.linspace(0, 8 * K, 800) r = jacobi_elliptic_functions(u, m) fig, ax = plt.subplots() ax.plot(u / K, r.sn, label="sn") ax.plot(u / K, r.cn, label="cn") ax.plot(u / K, r.dn, label="dn") ax.set_xlabel("u / K(m)") ax.set_title(f"Jacobi elliptic functions, m = {m}") ax.legend() print(f"K({m}) = {K:.6f}; sn(K) = {jacobi_elliptic_functions(K, m).sn:.12f}") print(f"max |sn^2 + cn^2 - 1| = {np.max(np.abs(r.sn**2 + r.cn**2 - 1)):.1e}") .. image-sg:: /api/gallery/special_functions/elliptic/images/sphx_glr_plot_02_jacobi_elliptic_functions_001.png :alt: Jacobi elliptic functions, m = 0.9 :srcset: /api/gallery/special_functions/elliptic/images/sphx_glr_plot_02_jacobi_elliptic_functions_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none K(0.9) = 2.578092; sn(K) = 1.000000000000 max |sn^2 + cn^2 - 1| = 2.2e-16 .. GENERATED FROM PYTHON SOURCE LINES 35-37 Exact pendulum motion: sin(theta/2) = k sn(K - t, k^2) with omega_0 = 1 ------------------------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 37-51 .. code-block:: Python theta0 = np.radians(150.0) k = np.sin(theta0 / 2) K_pend = complete_elliptic_integral_first_kind(k**2) t = np.linspace(0, 4 * K_pend, 400) theta = 2 * np.arcsin(k * jacobi_elliptic_functions(K_pend - t, k**2).sn) print(f"\n150 degree pendulum: period 4K = {4 * K_pend:.4f}, small-angle period 2 pi = {2 * np.pi:.4f}") fig, ax = plt.subplots() ax.plot(t, np.degrees(theta), label="exact (Jacobi sn)") ax.plot(t, np.degrees(theta0 * np.cos(t)), "--", label="small-angle approximation") ax.set_xlabel(r"$\omega_0 t$") ax.set_ylabel("angle (degrees)") ax.legend() .. image-sg:: /api/gallery/special_functions/elliptic/images/sphx_glr_plot_02_jacobi_elliptic_functions_002.png :alt: plot 02 jacobi elliptic functions :srcset: /api/gallery/special_functions/elliptic/images/sphx_glr_plot_02_jacobi_elliptic_functions_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 150 degree pendulum: period 4K = 11.0723, small-angle period 2 pi = 6.2832 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.055 seconds) .. _sphx_glr_download_api_gallery_special_functions_elliptic_plot_02_jacobi_elliptic_functions.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_jacobi_elliptic_functions.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_jacobi_elliptic_functions.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_jacobi_elliptic_functions.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_