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?

조회 수: 4 (최근 30일)
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
Virendra Kowale
Virendra Kowale 2021년 2월 14일
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)
error that I am receiving:-
Matrix dimensions must agree.
Error in antiresonance_part_two (line 36)
u = x_zero.*-exp(-14.5*t)

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

채택된 답변

Walter Roberson
Walter Roberson 2021년 2월 14일
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)
ans = 1×2
1 101
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
Virendra Kowale
Virendra Kowale 2021년 2월 14일
yes u r right I didn't mention but I was trying something like that. So that input u corresponds to time t
u = zeros(length(t), 2);
C is output matrix, so I think number columns should be dependent upon B matrix.
Please correct me if I am wrong
Walter Roberson
Walter Roberson 2021년 2월 14일
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.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Computations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by