Wrong Nyquist plot using python control package

656 views Asked by At

I am trying to use python to plot a Nyquist plot. However, I can't get it right.

This is the code I am using:

import control
import matplotlib.pyplot as plt

#Creating a transfer function G
s = control.TransferFunction.s

K0 = 10
T = 10
G = K0 / (s**2 * (T*s + 1))

control.nyquist(G)
plt.grid(True)
plt.title('Nyquist Diagram of G(s)')
plt.xlabel('Re(s)')
plt.ylabel('Im(s)')
plt.show()

The code outputs this graph:

Nyquist plot output image

But the plot should look like this (from wolfram):

wolfram Nyquist plot

Why is the Nyquist plot from the control package wrong? How can I get it right?

Thank you very much.

2

There are 2 answers

1
esantix On

You'll have to adjust that via matplotlib parameters. The nyquist funtion you are using passes **kwars to matplotlib.

You can see that

control.nyquist

is an alias for

# Function aliases
bode = bode_plot
nyquist = nyquist_plot

which has this inputs:

def nyquist_plot(syslist, omega=None, Plot=True, color=None,
             labelFreq=0, *args, **kwargs):
"""
Nyquist plot for a system

Plots a Nyquist plot for the system over a (optional) frequency range.

Parameters
----------
syslist : list of LTI
    List of linear input/output systems (single system is OK)
omega : freq_range
    Range of frequencies (list or bounds) in rad/sec
Plot : boolean
    If True, plot magnitude
color : string
    Used to specify the color of the plot
labelFreq : int
    Label every nth frequency on the plot
*args
    Additional arguments for :func:`matplotlib.plot` (color, linestyle, etc)
**kwargs:
    Additional keywords (passed to `matplotlib`)

Returns
-------
real : array
    real part of the frequency response array
imag : array
    imaginary part of the frequency response array
freq : array
    frequencies
0
seonhan1 On

It's because you have 2 poles on the jw axis (on the s plane). The transfer function is singular at s=0 (because of s^2 in the denominator of G). Nyquist function in Python or Matlab varies s from j(-inf) to j(+inf), and obviously G is singular when s= j(0). You need to write another code that plots G while s is varied from 0.01+j(-inf) to 0.01+j(+inf), where 0.01 is any small positive number so that P=0. You can also choose negative small number like -0.01. In this case, P=2. In short, Nyquist Python function cannot help you when there is a pole or zero on the imaginary axis on the s plane.