.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/control_systems/frequency/plot_01_nyquist_stability_criterion.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_control_systems_frequency_plot_01_nyquist_stability_criterion.py: Nyquist's stability criterion ============================= Long-distance telephone repeaters with feedback sometimes "sang". Harry Nyquist (1932) showed how to predict this from the measured open-loop frequency response alone. Trace :math:`L(j\omega)` for all frequencies (:func:`~engineeringkit.control_systems.nyquist`): the closed loop has :math:`Z = N + P` unstable poles, where :math:`N` counts clockwise encirclements of :math:`-1` (:func:`~engineeringkit.control_systems.nyquist_encirclements`) and :math:`P` the unstable open-loop poles. .. GENERATED FROM PYTHON SOURCE LINES 16-22 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from engineeringkit.control_systems import feedback, nyquist_encirclements, poles, transfer_function from engineeringkit.control_systems.visualizers import plot_nyquist .. GENERATED FROM PYTHON SOURCE LINES 23-27 A stable plant at two gains --------------------------- :math:`K/(s+1)^3` crosses the negative real axis at :math:`-K/8`. .. GENERATED FROM PYTHON SOURCE LINES 27-38 .. code-block:: Python fig, axes = plt.subplots(1, 2, figsize=(10, 4)) for K in [4.0, 12.0]: loop = transfer_function([K], [1, 3, 3, 1]) N = nyquist_encirclements(loop) Z = int(np.sum(poles(feedback(loop)).real > 0)) print(f"K = {K:4.1f}: N = {N}, P = 0, closed-loop unstable poles Z = {Z}") assert Z == N + 0 plot_nyquist(loop, ax=axes[0], label=f"K = {K:g}, N = {N}") axes[0].set(xlim=(-3, 13), ylim=(-8, 8), title=r"$K/(s+1)^3$") .. image-sg:: /api/gallery/control_systems/frequency/images/sphx_glr_plot_01_nyquist_stability_criterion_001.png :alt: $K/(s+1)^3$ :srcset: /api/gallery/control_systems/frequency/images/sphx_glr_plot_01_nyquist_stability_criterion_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none K = 4.0: N = 0, P = 0, closed-loop unstable poles Z = 0 K = 12.0: N = 2, P = 0, closed-loop unstable poles Z = 2 [(-3.0, 13.0), (-8.0, 8.0), Text(0.5, 1.0, '$K/(s+1)^3$')] .. GENERATED FROM PYTHON SOURCE LINES 39-44 An unstable plant stabilised by feedback ---------------------------------------- :math:`2/(s-1)` has one unstable pole (:math:`P = 1`); one counter-clockwise encirclement (:math:`N = -1`) gives :math:`Z = 0`. .. GENERATED FROM PYTHON SOURCE LINES 44-56 .. code-block:: Python loop = transfer_function([2], [1, -1]) N = nyquist_encirclements(loop) Z = int(np.sum(poles(feedback(loop)).real > 0)) print(f"2/(s-1): N = {N}, P = 1, Z = {Z}") assert N == -1 and Z == N + 1 plot_nyquist(loop, ax=axes[1], label="$2/(s-1)$") axes[1].set(title="Unstable open loop, stable closed loop") axes[1].set_aspect("equal") fig.tight_layout() plt.show() .. rst-class:: sphx-glr-script-out .. code-block:: none 2/(s-1): N = -1, P = 1, Z = 0 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.233 seconds) .. _sphx_glr_download_api_gallery_control_systems_frequency_plot_01_nyquist_stability_criterion.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/control_systems/frequency/plot_01_nyquist_stability_criterion.ipynb :alt: Launch JupyterLite :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_nyquist_stability_criterion.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_nyquist_stability_criterion.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_nyquist_stability_criterion.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_