Need assistance hard coding

조회 수: 1 (최근 30일)
Hunter
Hunter 2022년 11월 1일
댓글: Star Strider 2022년 11월 1일
clear, clc
m1 = 1;
m2 = 4;
mu1 = 0.2;
mu2 = 5;
b = 0.2;
t = 0:0.1:50;
for k = 0:0.2:1
A = [0 1 0 0; (-k) -0.4 k 0.4; 0 0 0 1; (k/4) 0.1 (-k/4) -1.3];
B = [5; 0; 0; 0];
C = eye(4);
D = 0;
u = zeros(size(t));
u(1,1) = 5;
sys = ss(A,B,C,D);
[y,x] = lsim(sys, u, t);
subplot(2,2,1)
plot(t,y(:,1))
title('Displacement - B=0.2 Variying K')
xlabel('Time (s)')
ylabel('Displacement')
hold on
plot(t,y(:,3))
subplot(2,2,2)
plot(t,y(:,2))
title('Velocity - B=0.2 Variying K')
xlabel('Time')
ylabel('Velocity')
hold on
plot(t,y(:,4))
end
for b1 = 0:0.2:1
A = [0 1 0 0; (-0.2) -(b1+0.2) 0.2 (0.2+b1); 0 0 0 1; -0.05 (0.2+b1)/4 -0.05 -(b1+5)/4];
B = [5; 0; 0; 0];
C = eye(4);
D = 0;
u = zeros(size(t));
u(1,1) = 5;
sys = ss(A,B,C,D);
[y,x] = lsim(sys, u, t);
subplot(2,2,3)
plot(t,y(:,1))
title('Displacement - K=0.2 Variying B')
xlabel('Time (s)')
ylabel('Displacement')
hold on
plot(t,y(:,3))
subplot(2,2,4)
plot(t,y(:,2))
title('Velocity - K=0.2 Variying B')
xlabel('Time (s)')
ylabel('Velocity')
hold on
plot(t,y(:,4))
end
% trying to figureout why my output looks nothing simular to these graphs. My output graphs are drastically different.
  댓글 수: 3
DGM
DGM 2022년 11월 1일
That'd be from CST.
Star Strider
Star Strider 2022년 11월 1일
It’s difficult to determine what you’re doing. The lsim function is good for random inputs, however the step or impulse functions (or stepplot or impulseplot) might be better for this. They have options you can set as well to vary the step amplitude. See the documentation for each function and setoptions for details.

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

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by