使用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.

下面根据介绍来实现绘制根轨迹图的功能:

一、导入必备包(control、matplotlib)

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

二、设定计算的参数

例如:G(S)H(S) = \frac{K}{4S^{3}+4S^{2}+S},那么输入:

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

三、调用rlocus函数进行绘图

rlocus(sy1)
plt.show()

根轨迹图如下

完整代码

from control import *
from matplotlib import pyplot as plt

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

rlocus(sy1)
plt.show()

 

转载于:https://www.cnblogs.com/circleyuan/p/10350177.html

  • 1
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值