.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/special_functions/zeta/plot_01_riemann_zeta.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_zeta_plot_01_riemann_zeta.py: The Riemann zeta function and Euler's product ================================================== Plots zeta(s) on the real line, including its analytic continuation to s < 1 with trivial zeros at the negative even integers, and shows Euler's product over primes converging to zeta(2) = pi^2/6. .. GENERATED FROM PYTHON SOURCE LINES 11-18 .. code-block:: Python import math import matplotlib.pyplot as plt import numpy as np from mathematicskit.special_functions import euler_product, riemann_zeta .. GENERATED FROM PYTHON SOURCE LINES 19-21 zeta on the real line ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 21-36 .. code-block:: Python s = np.concatenate([np.linspace(-9, 0.95, 500), np.linspace(1.05, 6, 200)]) values = riemann_zeta(s) fig, ax = plt.subplots() ax.plot(s[s < 1], values[s < 1], "C0") ax.plot(s[s > 1], values[s > 1], "C0") ax.plot([-2, -4, -6, -8], [0, 0, 0, 0], "ro", label="trivial zeros") ax.axhline(0, color="gray", lw=0.5) ax.set_ylim(-2, 4) ax.set_xlabel("s") ax.set_ylabel(r"$\zeta(s)$") ax.legend() print(f"zeta(2) = {riemann_zeta(2.0):.12f}, pi^2/6 = {math.pi**2 / 6:.12f}") print(f"zeta(0) = {riemann_zeta(0.0):.6f}, zeta(-1) = {riemann_zeta(-1.0):.6f} (= -1/12)") .. image-sg:: /api/gallery/special_functions/zeta/images/sphx_glr_plot_01_riemann_zeta_001.png :alt: plot 01 riemann zeta :srcset: /api/gallery/special_functions/zeta/images/sphx_glr_plot_01_riemann_zeta_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none zeta(2) = 1.644934066848, pi^2/6 = 1.644934066848 zeta(0) = -0.500000, zeta(-1) = -0.083333 (= -1/12) .. GENERATED FROM PYTHON SOURCE LINES 37-39 Euler's product over primes ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 39-43 .. code-block:: Python for bound in (10, 100, 1000, 10000): product = euler_product(2.0, bound) print(f"primes <= {bound:5d}: product = {product:.8f}, error = {abs(product - math.pi**2 / 6):.1e}") .. rst-class:: sphx-glr-script-out .. code-block:: none primes <= 10: product = 1.59505208, error = 5.0e-02 primes <= 100: product = 1.64194520, error = 3.0e-03 primes <= 1000: product = 1.64472519, error = 2.1e-04 primes <= 10000: product = 1.64491792, error = 1.6e-05 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.020 seconds) .. _sphx_glr_download_api_gallery_special_functions_zeta_plot_01_riemann_zeta.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_riemann_zeta.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_riemann_zeta.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_riemann_zeta.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_