.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/complex_analysis/residues/plot_04_laurent_series.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_residues_plot_04_laurent_series.py: Laurent series: expansions with negative powers in an annulus ============================================================= Pierre Alphonse Laurent (1843, after Weierstrass in 1841) expanded a function holomorphic in an annulus :math:`r < |z - a| < R` as :math:`\sum_{n=-\infty}^{\infty} a_n (z-a)^n`, with every coefficient a contour integral :math:`a_n = \frac{1}{2\pi i}\oint f(z)(z-a)^{-n-1}dz`. For :math:`f(z) = 1/((z-1)(z-2))` the expansion depends on the annulus: in :math:`1 < |z| < 2` it is :math:`a_n = -2^{-n-1}` for :math:`n \ge 0` and :math:`a_n = -1` for :math:`n < 0`. .. GENERATED FROM PYTHON SOURCE LINES 15-29 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from mathematicskit.complex_analysis import circle_contour, contour_integral def f(z): return 1.0 / ((z - 1.0) * (z - 2.0)) def laurent_coefficient(n, radius): return contour_integral(lambda z: f(z) * z ** (-n - 1), circle_contour(0.0, radius)) / (2j * np.pi) .. GENERATED FROM PYTHON SOURCE LINES 30-32 Coefficients by contour integration in three annuli --------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 32-46 .. code-block:: Python orders = np.arange(-5, 6) closed_form = np.where(orders >= 0, -(2.0 ** (-orders - 1.0)), -1.0) fig, ax = plt.subplots() for radius, label in ((0.5, "|z| < 1 (Taylor)"), (1.5, "1 < |z| < 2"), (3.0, "|z| > 2")): coefficients = np.array([laurent_coefficient(n, radius) for n in orders]).real ax.plot(orders, coefficients, "o-", label=label) if radius == 1.5: print(f"max |numeric - closed form| in 1 < |z| < 2: {np.max(np.abs(coefficients - closed_form)):.1e}") ax.set_xlabel("n") ax.set_ylabel("$a_n$") ax.set_title("Laurent coefficients of 1/((z-1)(z-2)) depend on the annulus") ax.legend() .. image-sg:: /api/gallery/complex_analysis/residues/images/sphx_glr_plot_04_laurent_series_001.png :alt: Laurent coefficients of 1/((z-1)(z-2)) depend on the annulus :srcset: /api/gallery/complex_analysis/residues/images/sphx_glr_plot_04_laurent_series_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none max |numeric - closed form| in 1 < |z| < 2: 1.4e-12 .. GENERATED FROM PYTHON SOURCE LINES 47-49 The truncated series converges only inside its annulus ------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 49-57 .. code-block:: Python z = 1.5 * np.exp(0.7j) for terms in (5, 10, 20, 40): n = np.arange(-terms, terms + 1) a = np.where(n >= 0, -(2.0 ** (-n - 1.0)), -1.0) print(f"{terms:>2} terms each side: |partial sum - f(z)| = {abs(np.sum(a * z**n) - f(z)):.2e}") plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none 5 terms each side: |partial sum - f(z)| = 7.32e-02 10 terms each side: |partial sum - f(z)| = 3.21e-02 20 terms each side: |partial sum - f(z)| = 2.13e-03 40 terms each side: |partial sum - f(z)| = 5.78e-06 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.095 seconds) .. _sphx_glr_download_api_gallery_complex_analysis_residues_plot_04_laurent_series.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/residues/plot_04_laurent_series.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_laurent_series.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_04_laurent_series.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_04_laurent_series.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_