运行具有“lsim”命令的代码时出错。

时间:2022-01-07 03:06:05

I want to run the following code but I keep getting this error:

我想运行下面的代码,但我一直得到这个错误:

Error using DynamicSystem/lsim (line 85) When simulating the response to a specific input signal, the input data U must be a matrix with as many rows as samples in the time vector T, and as many columns as input channels.

当使用DynamicSystem/lsim(第85行)模拟对特定输入信号的响应时,输入数据U必须是一个矩阵,它的行数与时间向量T的采样数相同,并且有许多列作为输入通道。

the code is:

的代码是:


V=300;
Vdc=700;
L=10*10^-3;
C=1500*10^-6;
R=1;
Dd=sqrt(2)*300/700;
w=2*pi*50;
A=[-R/L w -Dd/L 0 0;
    -w -R/L -Dd/L 0 0;
    (3*Dd)/2*C 0 0 0 0;
    0 1 0 0 0;
    0 0 1 0 0;];
B=[-Vdc/L 0;
    0 -Vdc/L;
    0 0;
    0 0;
    0 0;];
C=[1 0 0 0 0;
    0 1 0 0 0;
    0 0 1 0 0;];
D=[0 0;
    0 0;
    0 0;];
states={'id','iq','vdc','iq_dot','vdc_dot'};
inputs={'dd','dq'};
outputs={'id','iq','vdc'};
sys_ss=ss(A,B,C,D,'statename',states,'inputname',inputs,'outputname',outputs);
Q=eye(5);
I=eye(2);
K=lqr(A,B,Q,I);
Ac=[(A-B*K)];
Bc=[B];
Cc=[C];
Dc=[D];
states={'id','iq','vdc','iq_dot','vdc_dot'};
inputs={'r'};
outputs={'id','iq','vdc'};
sys_cl=ss(Ac,Bc,Cc,Dc,'statename',states,'inputname',inputs,'outputname',outputs);
x0=[0.1,0.1,0.1];
t=0:0.01:5;
r=zeros(size(t));
[y,t]=lsim(sys_cl,r,t,x0);
plot(t,y)

any help is highly appreciated.

非常感谢您的帮助。


1 个解决方案

#1


0  

You make two mistakes, use command 'help lsim' to look up instructions.

你犯了两个错误,使用命令“帮助lsim”查找指令。

[yout,x] = lsim(a, b, c, d, u, t, x0)

1.The matrix U has as many columns as inputs in SYS and its i-th row specifies the input value at time T(i). 2.The length of the initial condition X0 must match the number of states.

1。矩阵U与系统中输入的列一样多,它的第i行指定时间T(i)的输入值。2。初始条件X0的长度必须与状态数相匹配。

So, I change your code like this:

因此,我改变你的代码如下:

sys_cl=ss(Ac,Bc,Cc,Dc,'statename',states,'inputname',inputs,'outputname',outputs);
x0=[0.1,0.1,0.1, 0.1,0.1];
t=0:0.01:5;
r=zeros(length(inputs), length(t));
[y,t]=lsim(sys_cl,r,t,x0);

#1


0  

You make two mistakes, use command 'help lsim' to look up instructions.

你犯了两个错误,使用命令“帮助lsim”查找指令。

[yout,x] = lsim(a, b, c, d, u, t, x0)

1.The matrix U has as many columns as inputs in SYS and its i-th row specifies the input value at time T(i). 2.The length of the initial condition X0 must match the number of states.

1。矩阵U与系统中输入的列一样多,它的第i行指定时间T(i)的输入值。2。初始条件X0的长度必须与状态数相匹配。

So, I change your code like this:

因此,我改变你的代码如下:

sys_cl=ss(Ac,Bc,Cc,Dc,'statename',states,'inputname',inputs,'outputname',outputs);
x0=[0.1,0.1,0.1, 0.1,0.1];
t=0:0.01:5;
r=zeros(length(inputs), length(t));
[y,t]=lsim(sys_cl,r,t,x0);