.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/complex_analysis/holomorphic/plot_01_euler_formula.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 or to run this example in your browser via JupyterLite. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_complex_analysis_holomorphic_plot_01_euler_formula.py: Euler's formula: e^{i theta} = cos theta + i sin theta ====================================================== Euler's 1748 formula wraps the real line around the unit circle: :math:`e^{i\theta}` is the point at angle :math:`\theta`, and :math:`e^{i\pi} + 1 = 0`. The domain coloring of :math:`e^z` shows the consequence for the whole plane: the hue (phase) depends only on :math:`\operatorname{Im} z`, so :math:`e^z` repeats every :math:`2\pi i`. .. GENERATED FROM PYTHON SOURCE LINES 13-19 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from mathematicskit.complex_analysis import circle_contour, domain_coloring from mathematicskit.complex_analysis.visualizers import plot_domain_coloring .. GENERATED FROM PYTHON SOURCE LINES 20-22 e^{i theta} traces the unit circle ---------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 22-38 .. code-block:: Python theta = np.linspace(0, 2 * np.pi, 9) unit_circle = circle_contour(0.0, 1.0) print("max |e^{i theta} - (cos theta + i sin theta)| =", np.max(np.abs(np.exp(1j * theta) - (np.cos(theta) + 1j * np.sin(theta))))) print("e^{i pi} + 1 =", np.exp(1j * np.pi) + 1) fig, ax = plt.subplots() circle = unit_circle.points() ax.plot(circle.real, circle.imag, "C0") for t in theta[:-1]: w = np.exp(1j * t) ax.plot([0, w.real], [0, w.imag], "C1", lw=0.8) ax.annotate(rf"$\theta={t / np.pi:.2g}\pi$", (w.real, w.imag), textcoords="offset points", xytext=(5, 5), fontsize=8) ax.set_aspect("equal") ax.set_title(r"$e^{i\theta} = \cos\theta + i\sin\theta$") .. image-sg:: /api/gallery/complex_analysis/holomorphic/images/sphx_glr_plot_01_euler_formula_001.png :alt: $e^{i\theta} = \cos\theta + i\sin\theta$ :srcset: /api/gallery/complex_analysis/holomorphic/images/sphx_glr_plot_01_euler_formula_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none max |e^{i theta} - (cos theta + i sin theta)| = 0.0 e^{i pi} + 1 = 1.2246467991473532e-16j Text(0.5, 1.0, '$e^{i\\theta} = \\cos\\theta + i\\sin\\theta$') .. GENERATED FROM PYTHON SOURCE LINES 39-41 e^z is periodic with period 2 pi i ---------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 41-45 .. code-block:: Python result = domain_coloring(np.exp, (-2, 2), (-2 * np.pi, 2 * np.pi), resolution=300) plot_domain_coloring(result, title=r"$e^z$: phase depends only on Im z") print("e^{z + 2 pi i} == e^z:", np.allclose(np.exp(result.z + 2j * np.pi), result.w)) .. image-sg:: /api/gallery/complex_analysis/holomorphic/images/sphx_glr_plot_01_euler_formula_002.png :alt: $e^z$: phase depends only on Im z :srcset: /api/gallery/complex_analysis/holomorphic/images/sphx_glr_plot_01_euler_formula_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none e^{z + 2 pi i} == e^z: True .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.250 seconds) .. _sphx_glr_download_api_gallery_complex_analysis_holomorphic_plot_01_euler_formula.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: lite-badge .. image:: images/jupyterlite_badge_logo.svg :target: ../../../../lite/lab/index.html?path=api/gallery/complex_analysis/holomorphic/plot_01_euler_formula.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_euler_formula.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_euler_formula.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_euler_formula.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_