Index in position 2 exceed array bound (must not exceed 1)?

12 vues (au cours des 30 derniers jours)
Christian Thomas
Christian Thomas le 10 Déc 2021
A = [ 1 2 -4; 1 1 4; 0 -1 4];
B = [0 ;0; 10];
C = [ 0 0 1];
D = 0;
poles = [ -0.5-1i -0.5+1i -0.7];
Kt = place(A,B,poles);
F = inv(C*inv(-A+(B*Kt))*B);
Acl=A-(B*Kt);
Bcl=B*F;
Ccl=C;
Dcl=0;
syscl=ss(Acl,Bcl,Ccl,Dcl);
t=0:0.1:10;
r=ones(size(t));
x0 = [1 0 0];
[y,t,x]= lsim(syscl,ones(size(t)),t);
figure(1);
plot(t,y,'r');
obpole1 = -0.5+1i;
obpole2 = -0.5-1i;
obpole3 = -0.7;
L = place(A',C', [obpole1 obpole2 obpole3])';
At = [A-B*Kt B*Kt ; zeros(size(A)) A-L*C];
Bt = [ B ; zeros(size(B))];
Ct = [ C zeros(size(C)) ];
obsys = ss(At, Bt, Ct, 0);
x0ob = [0 0 0];
[yob,t,xob] = lsim(obsys,ones(size(t)),t,[x0 x0ob]);
figure(2);
plot(t,yob,'b');
figure(3);
plot(t,yob(:,1),'r');
hold on
plot(t,yob(:,2),'b');
Index in position 2 exceeds array bounds. Index must not exceed 1.
hold on
plot(t,y(:,1),'--r');
hold on
plot(t,y(:,2),'--b')

Réponses (2)

Yusuf Suer Erdem
Yusuf Suer Erdem le 10 Déc 2021
Modifié(e) : Yusuf Suer Erdem le 10 Déc 2021
your 'yob' matrix has a single column but you are asking for its second column. that is why it is happening. recover it please.

Walter Roberson
Walter Roberson le 10 Déc 2021
A = [ 1 2 -4; 1 1 4; 0 -1 4];
B = [0 ;0; 10];
C = [ 0 0 1];
D = 0;
poles = [ -0.5-1i -0.5+1i -0.7];
Kt = place(A,B,poles);
F = inv(C*inv(-A+(B*Kt))*B);
Acl=A-(B*Kt);
Bcl=B*F;
Ccl=C;
Dcl=0;
syscl=ss(Acl,Bcl,Ccl,Dcl);
t=0:0.1:10;
r=ones(size(t));
x0 = [1 0 0];
[y,t,x]= lsim(syscl,ones(size(t)),t);
figure(1);
plot(t,y,'r');
obpole1 = -0.5+1i;
obpole2 = -0.5-1i;
obpole3 = -0.7;
L = place(A',C', [obpole1 obpole2 obpole3])';
At = [A-B*Kt B*Kt ; zeros(size(A)) A-L*C];
Bt = [ B ; zeros(size(B))];
Ct = [ C zeros(size(C)) ];
obsys = ss(At, Bt, Ct, 0);
x0ob = [0 0 0];
obsys
obsys = A = x1 x2 x3 x4 x5 x6 x1 1 2 -4 0 0 0 x2 1 1 4 0 0 0 x3 -6.319 -8.906 -3.7 6.319 7.906 7.7 x4 0 0 0 1 2 14.92 x5 0 0 0 1 1 10.35 x6 0 0 0 0 -1 -3.7 B = u1 x1 0 x2 0 x3 10 x4 0 x5 0 x6 0 C = x1 x2 x3 x4 x5 x6 y1 0 0 1 0 0 0 D = u1 y1 0 Continuous-time state-space model.
tf(obsys)
ans = 10 s^2 - 20 s - 10 ------------------------------ s^3 + 1.7 s^2 + 1.95 s + 0.875 Continuous-time transfer function.
[yob,t,xob] = lsim(obsys,ones(size(t)),t,[x0 x0ob]);
figure(2);
plot(t,yob,'b');
size(yob)
ans = 1×2
101 1
figure(3);
plot(t,yob(:,1),'r');
hold on
plot(t,yob(:,2),'b');
Index in position 2 exceeds array bounds. Index must not exceed 1.
hold on
plot(t,y(:,1),'--r');
hold on
plot(t,y(:,2),'--b')
Notice the transfer function equivalent is one input to one output. Notice that your state space C only has one row, and so defines only one output.

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by