.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/special_functions/hypergeometric/plot_01_gauss_hypergeometric.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_hypergeometric_plot_01_gauss_hypergeometric.py: Gauss's hypergeometric function contains the elementary functions ====================================================================== Recovers log(1 + z), arcsin z, and a Chebyshev polynomial from 2F1 with special parameters, and checks Gauss's summation theorem at z = 1. .. GENERATED FROM PYTHON SOURCE LINES 10-15 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from mathematicskit.special_functions import chebyshev_polynomial, gamma_function, hypergeometric_2f1 .. GENERATED FROM PYTHON SOURCE LINES 16-18 Three familiar functions in one family ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 18-36 .. code-block:: Python z = np.linspace(-0.95, 0.95, 300) log_curve = z * hypergeometric_2f1(1.0, 1.0, 2.0, -z) arcsin_curve = z * hypergeometric_2f1(0.5, 0.5, 1.5, z**2) cheb_curve = hypergeometric_2f1(-4, 4, 0.5, (1 - z) / 2) fig, ax = plt.subplots() ax.plot(z, log_curve, label=r"$z\,{}_2F_1(1,1;2;-z) = \ln(1+z)$") ax.plot(z, arcsin_curve, label=r"$z\,{}_2F_1(\frac{1}{2},\frac{1}{2};\frac{3}{2};z^2) = \arcsin z$") ax.plot(z, cheb_curve, label=r"${}_2F_1(-4,4;\frac{1}{2};\frac{1-z}{2}) = T_4(z)$") ax.set_xlabel("z") ax.legend(fontsize="small") ax.set_title("Special cases of the hypergeometric function") print(f"max |log error| = {np.max(np.abs(log_curve - np.log1p(z))):.1e}") print(f"max |arcsin error| = {np.max(np.abs(arcsin_curve - np.arcsin(z))):.1e}") print(f"max |T_4 error| = {np.max(np.abs(cheb_curve - chebyshev_polynomial(4, z))):.1e}") .. image-sg:: /api/gallery/special_functions/hypergeometric/images/sphx_glr_plot_01_gauss_hypergeometric_001.png :alt: Special cases of the hypergeometric function :srcset: /api/gallery/special_functions/hypergeometric/images/sphx_glr_plot_01_gauss_hypergeometric_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none max |log error| = 1.9e-14 max |arcsin error| = 2.4e-15 max |T_4 error| = 1.7e-15 .. GENERATED FROM PYTHON SOURCE LINES 37-39 Gauss's summation theorem at z = 1 ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 39-44 .. code-block:: Python a, b, c = 0.5, 0.25, 2.0 gauss = gamma_function(c) * gamma_function(c - a - b) / (gamma_function(c - a) * gamma_function(c - b)) print(f"\n2F1({a}, {b}; {c}; 1) = {hypergeometric_2f1(a, b, c, 1.0):.12f}") print(f"Gamma ratio = {gauss:.12f}") .. rst-class:: sphx-glr-script-out .. code-block:: none 2F1(0.5, 0.25; 2.0; 1) = 1.112835788899 Gamma ratio = 1.112835788899 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.045 seconds) .. _sphx_glr_download_api_gallery_special_functions_hypergeometric_plot_01_gauss_hypergeometric.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_gauss_hypergeometric.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_gauss_hypergeometric.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_gauss_hypergeometric.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_