how to simulate using lsim command I am receiving error because of variable 't'(time).

1 回表示 (過去 30 日間)
s = -14.5
A = [-3, 5, -7, 0; 0.5, -1.5, 0.5, -7.5; -5, 0, -3, 0; -0.5, -5, 0, -7];
B = [1, 0; 0, -1; -2, 0; 0, 1];
C = [1, 0, 0, 0; 0, -1, 0, 0];
D = [-1, 0; 2, 0];
sys = ss(A,B,C,D);
M = (s*eye(4,4) - A);
P = [ M, -B; C, D]
k = rank(P)
d = det(P)
uM = null(P,'r')
sys2 = tf( sys );
[y,t] = lsim(sys2 ,uM , t)
size(y)
Error that I am receiving:-
When simulating the response to a specific input signal, the input
data U must be a matrix with as many rows as samples in the time
vector T, and as many columns as input channels.
Unrecognized function or variable 't'.
Error in antiresonance_part_two (line 40)
[y,t] = lsim(sys2 ,uM , t)

採用された回答

Star Strider
Star Strider 2021 年 2 月 13 日
The input ‘u’ must have the same number of columns as ‘B’.
I have no idea what you actually want to do (or what your ‘u’ is), so in their absence, try this as a relevant (and working) example with your system:
A = [-3, 5, -7, 0; 0.5, -1.5, 0.5, -7.5; -5, 0, -3, 0; -0.5, -5, 0, -7];
B = [1, 0; 0, -1; -2, 0; 0, 1];
C = [1, 0, 0, 0; 0, -1, 0, 0];
D = [-1, 0; 2, 0];
sys = ss(A,B,C,D);
t = linspace(0, 2.5, 250).';
u = sin(2*pi*t*[1 5]);
[y,t] = lsim(sys, u, t);
figure
yyaxis left
plot(t, u(:,1), '--b')
hold on
plot(t, u(:,2), '--r')
hold off
yyaxis right
plot(t, y(:,1), '-b')
hold on
plot(t, y(:,2), '-r')
hold off
grid
xlabel('Time')
ylabel('Amplitude')
legend('u_1', 'u_2', 'y_1', 'y_2', 'Location','N')
Make appropriate changes to get the result you want.
  5 件のコメント
Virendra Kowale
Virendra Kowale 2021 年 2 月 14 日
Thanks a ton. It worked. It does what I want.
Star Strider
Star Strider 2021 年 2 月 14 日
As always, my pleasure!
I was not certain if my changes were what you wanted, so I appreciate your follow-up!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTime and Frequency Domain Analysis についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by