首先准备一个传递函数sys,
然后使用lsim(sys,u,t,x0)函数(通用的时序分析的函数)
u: The input u
is an array having as many rows as time samples (length(t)
) and as many columns as system inputs.
x0:further specifies an initial condition x0
for the system states. This syntax applies only when sys
is a state-space model. x0
is a vector whose entries are the initial values of the corresponding states of sys
.
迭代使用的关键是使用上一步的结果,对x0进行赋值
具体实现:使用python环境,使用 control库。
关键代码片段如下:
1 #u是前文设置的系统输入,t是时序 2 lastValue=0 3 result=[] 4 for i in range(len(t) - 1): 5 y= lsim(T1, U=u[i:i + 2], T=t[i:i + 2], X0=lastValue) 6 lastValue = y[2][1] 7 result.append(y[0][0])
注意,y是三个数组的元组形式 y=(yout, T ,xout) 。X0传递的是xout。