Plotting 3 outputs on the same graph

1 visualización (últimos 30 días)
MN
MN el 4 de Dic. de 2020
Comentada: MN el 7 de Dic. de 2020
I want to know how I can plot 3 outputs obtained from state space approach on the same graph?
The only difference between the graphs are the parameter kg (Ground spring constant).
I want to plot 3 outputs on the same graph, with first output having kg= 100, second one with kg=350, and last one with kg=850
I attached my code, so I appricate if you show me how I can get the graph.
  1 comentario
MN
MN el 7 de Dic. de 2020
Another question my impulse has a magnitude of 10mm. Should i change the code to [U,T,X]= impulse(My_sys,10*10^-3)?

Iniciar sesión para comentar.

Respuesta aceptada

KSSV
KSSV el 4 de Dic. de 2020
Editada: KSSV el 4 de Dic. de 2020
Run a loop and save it into a matrix and plot at the end.
%% Part 7
clc; clear; close;
Ur_M=53; m1=Ur_M/12.33; m2=Ur_M/12.33; m3=Ur_M/6.16; m4=Ur_M/1.48; k1=6; k2=6; k3=10; k4=10; k5=18; c1=0.3; c2=0.65; c4=1.9; ms=0.3;
ks=403; cs=2150;
ub=1;
KG = [100 350 850] ;
u1_soft_disp_imp = cell(3,1) ;
for i = 1:length(KG)
kg = KG(i) ;
A= [0 1 0 0 0 0 0 0 0 0; (-kg-ks)/ms -cs/ms ks/ms cs/ms 0 0 0 0 0 0;
0 0 0 1 0 0 0 0 0 0; ks/m1 cs/m1 (-ks-k1-k2)/m1 (-cs-c1-c2)/m1 k2/m1 c2/m1 k1/m1 c1/m1 0 0;
0 0 0 0 0 1 0 0 0 0; 0 0 k2/m2 c2/m2 (-k3-k2)/m2 -c2/m2 k3/m2 0 0 0; 0 0 0 0 0 0 0 1 0 0;
0 0 k1/m3 c1/m3 k3/m3 0 (-k1-k3-k4-k5)/m3 (-c1-c4)/m3 (k4+k5)/m3 c4/m3;
0 0 0 0 0 0 0 0 0 1; 0 0 0 0 0 0 (k4+k5)/m4 c4/m4 (-k4-k5)/m4 -c4/m4];
B= [0; kg/ms; 0; 0; 0; 0; 0; 0; 0; 0];
C= [1 0 0 0 0 0 0 0 0 0; 0 0 1 0 0 0 0 0 0 0; 0 0 0 0 1 0 0 0 0 0; 0 0 0 0 0 0 1 0 0 0; 0 0 0 0 0 0 0 0 1 0];
D= [0; 0; 0; 0; 0];
My_sys=ss(A,B,C,D)
[U,T,X]= impulse(My_sys)
u1_soft_disp_imp{i} = X(:,3) ;
end
figure
hold on
for i = 1:3
plot(u1_soft_disp_imp{i}) % use proper indexing
end
legend('disp due to impulse input for soft soil','disp due to impulse input for hard soil','disp due to impulse input for very hard soil')
  3 comentarios
KSSV
KSSV el 4 de Dic. de 2020
I thougt you are going to save a column array into u1_soft_disp_imp, but it looks you are saving a matrix.
I have modified the code. Now the output is saved into a cell. USe cell indexing, save the data for each loop index and plot at the end.
MN
MN el 4 de Dic. de 2020
Another question my impulse has a magnitude of 10mm. Should i change the code to [U,T,X]= impulse(My_sys,10*10^-3)?

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by