I want to use 'u' as zero matrix in order to simulate the matrix but I am receiving the following error, which is mentioned below the code. what's the possible solution?
2 views (last 30 days)
Show older comments
Virendra Kowale
on 14 Feb 2021
Commented: Star Strider
on 14 Feb 2021
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)
d = det(P)
uM = null(P,'r')
sys2 = tf( sys );
t = 0:0.1:10;
u = zeros([4 1]) %this is the matrix because of which I am receiving error
[y,t] = lsim(sys2 ,u , t)
size(y)
error:-
Error using DynamicSystem/lsim (line 84)
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.
Error in antiresonance_part_two (line 44)
[y,t] = lsim(sys2 ,u , t)
4 Comments
Star Strider
on 14 Feb 2021
See my Answer to wheat is apparently a cuplicate of this Question how to simulate using lsim command I am receiving error because of variable 't'(time).
Accepted Answer
Walter Roberson
on 14 Feb 2021
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.
Let us look at what you have
t = 0:0.1:10;
size(t)
t has 101 samples. According to the error message (which we will assume to be correct as it says the same thing as the documentation for lsim says), as many rows as samples in the time u must have 101 rows as well.
u = zeros([4 1]) %this is the matrix because of which I am receiving error
That is clearly 1 column. Does it satisfy as many columns as input channels ?
C = [1, 0, 0, 0; 0, -1, 0, 0];
2 rows for C -> two input channels. So u must have two columns because the system has two input channels.
Therefore, you would be able to get something to run if you used
u = zeros(length(y), 2);
Would it be a meaningful run? Probably not. Row K of u should be the list of inputs corresponding to time t(K), so using zeros() like that is telling lsim() that the inputs are zero at every time step. Not impossible, but not likely.
2 Comments
Walter Roberson
on 14 Feb 2021
You are right, the number of inputs is the number of columns of B, not the number of rows of C. It happened to be the same in this case.
More Answers (0)
See Also
Categories
Find more on Matrix Computations 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!