Why are my lines not showing on my graph ?

조회 수: 1 (최근 30일)
Christian Thomas
Christian Thomas 2021년 12월 10일
댓글: Peter Bonavita 2021년 12월 10일
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(1,length(t));
x0 = [1 0 0];
CL_FFFB= lsim(syscl,r,t,x0);
figure(1);
plot(t,CL_FFFB,'r-');
Nbar = rscale(syscl,Kt);
obpole1 = -3;
obpole2 = -4;
obpole3 = -6;
L = place(A', C', [obpole1 obpole2 obpole3])';
At = [A-B*Kt B*Kt ; zeros(size(A)) A-L*C];
Bt = [ B*Nbar ; zeros(size(B))];
Ct = [ C zeros(size(C)) ];
obsys = ss(At, Bt, Ct, 0);
x0ob = [0 0 0];
[yob,t,xob] = lsim(obsys,zeros(size(t)),t,[x0ob x0ob]);
figure(2);
plot(t,xob(:,1),'r');
hold on
plot(t,xob(:,2),'b');
hold on
plot(t,xob(:,1),'--r');
hold on
plot(t,xob(:,2),'--b')
  댓글 수: 1
Christian Thomas
Christian Thomas 2021년 12월 10일
When I run the code it shows the first figure but the second figure has just a straight line with out any other vaules on it.

댓글을 달려면 로그인하십시오.

답변 (1개)

Star Strider
Star Strider 2021년 12월 10일
I don’t even get a straight line, because there is not such functyion as ‘rscale’ in the online documentation.
That aside, look at the ‘C’ matris in ‘syscl’ and note that the second and third elements (columns) are 0 so the outputs related to those states are also 0. That could account for the straight line (assumed to be at 0) for those states and state trajectories.
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)
syscl = A = x1 x2 x3 x1 1 2 -4 x2 1 1 4 x3 -6.319 -8.906 -3.7 B = u1 x1 0 x2 0 x3 -0.875 C = x1 x2 x3 y1 0 0 1 D = u1 y1 0 Continuous-time state-space model.
t=0:0.1:10;
r=ones(1,length(t));
x0 = [1 0 0];
CL_FFFB= lsim(syscl,r,t,x0);
figure(1);
plot(t,CL_FFFB,'r-');
Nbar = rscale(syscl,Kt);
Unrecognized function or variable 'rscale'.
obpole1 = -3;
obpole2 = -4;
obpole3 = -6;
L = place(A', C', [obpole1 obpole2 obpole3])';
At = [A-B*Kt B*Kt ; zeros(size(A)) A-L*C];
Bt = [ B*Nbar ; zeros(size(B))];
Ct = [ C zeros(size(C)) ];
obsys = ss(At, Bt, Ct, 0);
x0ob = [0 0 0];
[yob,t,xob] = lsim(obsys,zeros(size(t)),t,[x0ob x0ob])
figure(2);
plot(t,xob(:,1),'r');
hold on
plot(t,xob(:,2),'b');
hold on
plot(t,xob(:,1),'--r');
hold on
plot(t,xob(:,2),'--b')
.
  댓글 수: 3
Star Strider
Star Strider 2021년 12월 10일
With respect to ‘rscale’ I prefer not to go looking for it, so if it is available it needs to be included in the code as a function at the end of the posted code.
With respect to the straight line, my previous observation holds, specifically that the ‘C’ matrix in ‘syscl’ has a 0 value in element 2, so those state and state trajectory outputs will be identically 0. To get a different result, replace ‘C(2)’ with some non-zero value, perhaps 1.
.
Peter Bonavita
Peter Bonavita 2021년 12월 10일
Assuming you're using this rscale from the Michigan Controls Tutorials site, the data you're plotting in xob consists of all zeros, hence the straight line at Y=0.
>> xob
xob =
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
Star Strider's answer is correct; they explain the zeros in the other matrices lead to zero output.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Scatter Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by