.. 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_02_argument_principle.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_02_argument_principle.py: The argument principle: counting zeros minus poles by winding ============================================================= :math:`\frac{1}{2\pi i}\oint_\gamma f'/f = N - P`, the number of zeros minus poles inside :math:`\gamma`. Equivalently, the image curve :math:`f(\gamma)` winds :math:`N - P` times around 0. For a quintic, counting roots inside disks of growing radius needs no root finder at all. .. GENERATED FROM PYTHON SOURCE LINES 13-23 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from mathematicskit.complex_analysis import argument_principle, circle_contour coefficients = [1, -0.5, 0.2, -1.3, 0.1, 0.4] p = lambda z: np.polyval(coefficients, z) dp = lambda z: np.polyval(np.polyder(coefficients), z) roots = np.roots(coefficients) .. GENERATED FROM PYTHON SOURCE LINES 24-26 Root counts from the argument principle --------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 26-35 .. code-block:: Python for radius in (0.3, 0.6, 0.9, 1.2, 1.5): circle = circle_contour(0.0, radius) print( f"|z| < {radius}: phase winding = {argument_principle(p, circle)}, " f"oint p'/p = {argument_principle(p, circle, fprime=dp)}, " f"numpy.roots = {int(np.sum(np.abs(roots) < radius))}" ) .. rst-class:: sphx-glr-script-out .. code-block:: none |z| < 0.3: phase winding = 0, oint p'/p = 0, numpy.roots = 0 |z| < 0.6: phase winding = 1, oint p'/p = 1, numpy.roots = 1 |z| < 0.9: phase winding = 2, oint p'/p = 2, numpy.roots = 2 |z| < 1.2: phase winding = 5, oint p'/p = 5, numpy.roots = 5 |z| < 1.5: phase winding = 5, oint p'/p = 5, numpy.roots = 5 .. GENERATED FROM PYTHON SOURCE LINES 36-38 The image curve winds around 0 once per enclosed zero ----------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 38-52 .. code-block:: Python fig, axes = plt.subplots(1, 2, figsize=(10, 5)) for radius in (0.6, 1.2): circle = circle_contour(0.0, radius) z = circle.points() axes[0].plot(z.real, z.imag, label=f"|z| = {radius}") w = p(z) axes[1].plot(w.real, w.imag, label=f"p(|z| = {radius}): winds {argument_principle(p, circle)}x") axes[0].plot(roots.real, roots.imag, "ko", label="roots") axes[1].plot(0, 0, "k+", ms=12) for ax, title in zip(axes, ("z-plane", "w = p(z)"), strict=False): ax.set_aspect("equal") ax.set_title(title) ax.legend(fontsize=8) .. image-sg:: /api/gallery/complex_analysis/residues/images/sphx_glr_plot_02_argument_principle_001.png :alt: z-plane, w = p(z) :srcset: /api/gallery/complex_analysis/residues/images/sphx_glr_plot_02_argument_principle_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.184 seconds) .. _sphx_glr_download_api_gallery_complex_analysis_residues_plot_02_argument_principle.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_02_argument_principle.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_argument_principle.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_argument_principle.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_argument_principle.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_