MATLAB Answers

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?

조회 수: 1(최근 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

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

채택된 답변

Walter Roberson
Walter Roberson 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)
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
Walter Roberson
Walter Roberson 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.

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

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by