How do I get my graphs to converge on one ?

조회 수: 2(최근 30일)
Christian Thomas 2021년 12월 10일
답변: VBBV 2021년 12월 11일
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:20;
r=ones(size(t));
x0= [1 0 0];
[y,t,x]= lsim(syscl,r,t,x0);
figure(1);
plot(t,y(:,1),'r-');
%part B
P_1= -0.5-1i;
P_2 = -0.5+1i;
P_3 = -0.7;
L = place(A', C', [P_1 P_2 P_3])';
At = [A-B*Kt B*Kt ; zeros(size(A)) A-L*C];
Bt = [ B ; zeros(size(B))];
Ct = [ C zeros(size(C)) ];
syst = ss(At,Bt,Ct,0);
x0ob = [ 0 0 0];
[yob,t,xob] = lsim(syst,r,t,[x0 x0ob]);
figure(2);
plot(t,xob(:,1),'r');
hold on
plot(t,xob(:,2),'b');
hold on
plot(t,x(:,1),'--r');
hold on
plot(t,x(:,2),'--b')
So in figure 2 my graphs go up to 150 im trying to get them to go up 1 any suggestion ?

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

답변(2개)

dpb 2021년 12월 10일
...
[yob,t,xob] = lsim(syst,r,t,[x0 x0ob]);
figure(2);
hold on
plot(t,xob(:,1)/max(xob(:,1)),'r');
plot(t,xob(:,2)/abs(min(xob(:,1))),'b');
...
One hold is on, it can't get any "onner"...once is enough.
If want the others as well, the "trick" should be obviousl
One can get a lot more clever in that min/max(xob) will each return a row vector of the size of the columns so could vectorize the calculations first -- Q? is do you want both sides to be scaled to respective max/min or just the max overall, or what?
You could also do the plotting with vector notation instead of repeated calls, saving the line handles and then decorating the lines later.
댓글 수: 0표시숨기기 이전 댓글 수: -1

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

VBBV 2021년 12월 11일
x0ob = [1 0 0];% Use same initial
[yob,t,xob] = lsim(syst,r,t,[x0; x0ob]);
Use the same initial conditions for two different sets as above

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

Community Treasure Hunt

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

Start Hunting!

Translated by