使用python绘制根轨迹图
2024-10-19 01:31:58
最近在学自动控制原理,发现根轨迹这一张全是绘图的,然而书上教的全是使用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包进行绘图
二、设定计算的参数
例如:,那么输入:
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()
最新文章
- deb包的安装及dpkg命令小结
- 读写注册表 registrykey 创建删除
- 基于bootstrap + php +ajax datatable 插件的使用
- Javascript中的字典和散列
- js按钮浮动随手指方向移动而移动
- json格式的日期格式化
- XPATH基础入门资料
- Android Listener 监听的几种写法
- 最小生成树之prim
- PO、BO、VO、DTO、POJO、DAO的区别
- 通过API函数来控制SQLite数据库增删改查
- Android Bitmap与DrawAble与byte[]与InputStream之间的转换工具类【转】
- 2.8. 创建 NSManagedObject 的子类 (Core Data 应用程序实践指南)
- android 原生camera——设置模块修改
- The 4 Essentials of Video Content Marketing Success
- mysql 关联表修改数据
- IdentityServer4实战 - 必须使用HTTPS问题解析
- win7 / mysql-8.0.11-winx64 安装的测坑步骤
- abap对象的创建和调用。方法调用
- 分页sql写法【只用最新的】