How do I get my graphs to converge on one ?

2 visualizaciones (últimos 30 días)
Christian Thomas
Christian Thomas el 10 de Dic. de 2021
Respondida: dpb el 10 de Dic. de 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: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 ?

Respuestas (1)

dpb
dpb el 10 de Dic. de 2021
...
[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.

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by