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

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

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

thank you so much I treid but in my question
u(t) = p*exp(zt)
where,
p = x0
x0 = transpose([0,0,0,-0.1333])
z = invariant zero, which i got i.e. (z = -14.5)
t is time which I am taking as t = 0:0.1:10;
and when i try to run this command [y,t] = lsim(sys ,u , t)
I receive the following error
Matrix dimensions must agree.
Error in antiresonance_part_two (line 38)
u = x_zero.*exp(-14.5*t)
here is the entire code
clear all
close all
clc
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)
uM = null(P,'r')
I = transpose(uM)
%sys2 = tf( sys );
t = linspace(0, 2.5, 10).';
x_zero = transpose([0,0,0,-0.1333])
u = x_zero.*exp(-14.5*t)
x0= initial(sys,x_zero)
[y,t] = lsim(sys ,u , t)
As always, my pleasure!
Experiment with this:
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);
uM = null(P,'r');
I = transpose(uM);
%sys2 = tf( sys );
t = linspace(0, 2.5, 10).';
x_zero = transpose([0,0,0,-0.1333]);
u = (x_zero([3 4],:)*exp(-14.5*t.')).'; % Changed To Match Dimensions Of ‘B’
x0= initial(sys,x_zero);
[y,t] = lsim(sys ,u , t);
figure
yyaxis left
plot(t, u, '-')
ylabel('Input')
yyaxis right
plot(t, y, '-')
ylabel('Output')
grid
It runs without error. You will need to determine if it does what you want.
I added the figure so that I could see the result.
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)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!