.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/special_functions/lambert_w/plot_01_lambert_w_branches.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_lambert_w_plot_01_lambert_w_branches.py: The two real branches of the Lambert W function ==================================================== Plots W_0 and W_{-1}, the two real inverses of w e^w, which meet at the branch point z = -1/e, and uses W to solve x^x = 27. .. GENERATED FROM PYTHON SOURCE LINES 10-17 .. code-block:: Python import math import matplotlib.pyplot as plt import numpy as np from mathematicskit.special_functions import lambert_w .. GENERATED FROM PYTHON SOURCE LINES 18-20 Both real branches ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 20-34 .. code-block:: Python z0 = np.linspace(-1 / math.e + 1e-9, 6.0, 400) zm1 = np.linspace(-1 / math.e + 1e-9, -1e-4, 400) fig, ax = plt.subplots() ax.plot(z0, lambert_w(z0), label=r"$W_0$ (principal)") ax.plot(zm1, lambert_w(zm1, branch=-1), label=r"$W_{-1}$") ax.plot(-1 / math.e, -1, "ko", label=r"branch point $(-1/e, -1)$") ax.set_ylim(-6, 2) ax.set_xlabel("z") ax.set_ylabel("W(z)") ax.set_title(r"Solutions of $we^w = z$") ax.legend() .. image-sg:: /api/gallery/special_functions/lambert_w/images/sphx_glr_plot_01_lambert_w_branches_001.png :alt: Solutions of $we^w = z$ :srcset: /api/gallery/special_functions/lambert_w/images/sphx_glr_plot_01_lambert_w_branches_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 35-37 The omega constant and a transcendental equation ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 37-44 .. code-block:: Python omega = lambert_w(1.0) print(f"Omega = W(1) = {omega:.12f}, exp(-Omega) = {math.exp(-omega):.12f}") y = 27.0 x = math.log(y) / lambert_w(math.log(y)) print(f"x^x = {y:g} is solved by x = ln y / W(ln y) = {x:.12f}") .. rst-class:: sphx-glr-script-out .. code-block:: none Omega = W(1) = 0.567143290410, exp(-Omega) = 0.567143290410 x^x = 27 is solved by x = ln y / W(ln y) = 3.000000000000 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.028 seconds) .. _sphx_glr_download_api_gallery_special_functions_lambert_w_plot_01_lambert_w_branches.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_lambert_w_branches.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_lambert_w_branches.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_lambert_w_branches.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_