.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/special_functions/bessel/plot_01_bessel_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_bessel_plot_01_bessel_functions.py: Bessel functions of the first and second kind ==================================================== Plots J_0, J_1 (regular at the origin) and Y_0 (singular at the origin) over a range of x, and finds J_0's first zero. .. GENERATED FROM PYTHON SOURCE LINES 10-15 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from mathematicskit.special_functions import bessel_first_kind, bessel_second_kind .. GENERATED FROM PYTHON SOURCE LINES 16-18 Evaluate over a range ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 18-36 .. code-block:: Python x = np.linspace(0.1, 10.0, 200) j0 = bessel_first_kind(0.0, x) j1 = bessel_first_kind(1.0, x) y0 = bessel_second_kind(0.0, x) fig, ax = plt.subplots() ax.plot(x, j0, label=r"$J_0(x)$") ax.plot(x, j1, label=r"$J_1(x)$") ax.plot(x, y0, label=r"$Y_0(x)$") ax.axhline(0, color="gray", lw=0.5) ax.set_ylim(-1.5, 1.1) ax.set_xlabel("x") ax.set_title("Bessel functions of the first and second kind") ax.legend() print(f"J_0(0.1) = {j0[0]:.4f}, Y_0(0.1) = {y0[0]:.4f} (Y_0 diverges toward x=0)") .. image-sg:: /api/gallery/special_functions/bessel/images/sphx_glr_plot_01_bessel_functions_001.png :alt: Bessel functions of the first and second kind :srcset: /api/gallery/special_functions/bessel/images/sphx_glr_plot_01_bessel_functions_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none J_0(0.1) = 0.9975, Y_0(0.1) = -1.5342 (Y_0 diverges toward x=0) .. GENERATED FROM PYTHON SOURCE LINES 37-39 The first zero of J_0 (approximately 2.4048) ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 39-43 .. code-block:: Python sign_changes = np.where(np.diff(np.sign(j0)) != 0)[0] first_zero = x[sign_changes[0]] print(f"\nfirst zero of J_0 near x = {first_zero:.4f} (known value: 2.4048)") .. rst-class:: sphx-glr-script-out .. code-block:: none first zero of J_0 near x = 2.3884 (known value: 2.4048) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.028 seconds) .. _sphx_glr_download_api_gallery_special_functions_bessel_plot_01_bessel_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_01_bessel_functions.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_bessel_functions.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_bessel_functions.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_