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

2 views (last 30 days)
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)

Accepted Answer

Star Strider
Star Strider on 13 Feb 2021
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 Comments
Star Strider
Star Strider on 14 Feb 2021
As always, my pleasure!
I was not certain if my changes were what you wanted, so I appreciate your follow-up!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!