# 使用python绘制根轨迹图

最近在学自动控制原理，发现根轨迹这一张全是绘图的，然而书上教的全是使用matlab进行计算机辅助绘图。但国内对于使用python进行这种绘图的资料基本没有，后来发现python-control包已经将matlab的rlocus封装进去，matlab能做的python也能做。使用python绘制根轨迹图主要使用的是python-control包下的matlab.rlocus函数，具体内容可以参考：https://python-control.readthedocs.io/en/0.8.0/generated/control.matlab.rlocus.html?highlight=rlocus

官网对rclous函数的介绍：

control.matlab.rlocus
control.matlab.rlocus(sys, kvect=None, xlim=None, ylim=None, plotstr='-', Plot=True, PrintGain=True, grid=False)
Root locus plot

Calculate the root locus by finding the roots of 1+k*TF(s) where TF is self.num(s)/self.den(s) and each k is an element of kvect.

Parameters:
sys (LTI object) – Linear input/output systems (SISO only, for now)
kvect (list or ndarray, optional) – List of gains to use in computing diagram
xlim (tuple or list, optional) – control of x-axis range, normally with tuple (see matplotlib.axes)
ylim (tuple or list, optional) – control of y-axis range
Plot (boolean, optional (default = True)) – If True, plot root locus diagram.
PrintGain (boolean (default = True)) – If True, report mouse clicks when close to the root-locus branches, calculate gain, damping and print
grid (boolean (default = False)) – If True plot s-plane grid.
Returns:
rlist (ndarray) – Computed root locations, given as a 2d array
klist (ndarray or list) – Gains used. Same as klist keyword argument if provided.

from control import *     #导入control包，没有的可以使用pip install control命令进行安装
from matplotlib import pyplot as plt    #导入matplotlib包进行绘图

sy1 = tf([1],[4,4,1,0])     #将参数按照tf命令的格式赋值给sy1，前一个[]是分子中s的参数，第二个[]是分母s的参数

rlocus(sy1)
plt.show()

from control import *
from matplotlib import pyplot as plt

sy1 = tf([1],[4,4,1,0])

rlocus(sy1)
plt.show()

09-24
09-19

01-25
03-11
05-10
12-20
05-14
05-17
01-04
01-11 4万+
03-31 908
06-04
02-25 6246
10-26 624
01-12 2739
08-04
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客