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 chan

Hi All, I got an error when trying to solve a 4 dof dynamic system with sinusoidal load on dof #1 and dof #3 using a state space model. I created the state space model and make sure that it follows the size appropriately, however the error still persists:
"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."
I have checked that my U input and my T has the same rows. And the U has the same column as the same matrix size as input. What possibly can I improve from my code?
clc
clear
clc
%specify the timestep
dt = 0.1;
tmax = 10;
t = [0:dt:tmax]';
time = t';
%assemble the M matrix
m = [0.5 0.5 1.2 1.2];
M = diag(m);
%assemble the K matrix
k1 = 100;
k2 = 80;
k3 = 70;
k4 = 50;
k5 = 80;
k6 = 60;
k11 = k1 + k2 + k5;
k12 = -k2;
k13 = 0;
k14 = -k5;
k22 = k2 + k3 + k6;
k23 = -k3;
k24 = k6;
k33 = k3+k4;
k34 = -k4;
k44 = k4 + k5 +k6;
k21 = k12;
k31 = k13;
k32 = k23;
k41 = k14;
k42 = k24;
k43 = k34;
K = [k11 k12 k13 k14; ...
k21 k22 k23 k24; ...
k31 k32 k33 k34; ...
k41 k42 k43 k44];
%assemble the F matrix
b2 = [10 0 0 0; 0 0 -5 0; 0 0 0 0; 0 0 0 0]';
%assemble the C matrix
C = 0.01*K;
%assemble the state space model
MK = M\K;
MC = -M\C;
I = eye(length(M));
zer = zeros(length(M));
A = [zer I; -MK -MC];
B = [zeros(4) M\b2]';
C = [eye(length(A))];
D = zeros(8,4);
dyn = ss(A, B, C, D)
dyn = A = x1 x2 x3 x4 x5 x6 x7 x8 x1 0 0 0 0 1 0 0 0 x2 0 0 0 0 0 1 0 0 x3 0 0 0 0 0 0 1 0 x4 0 0 0 0 0 0 0 1 x5 -520 160 0 160 5.2 -1.6 0 -1.6 x6 160 -420 140 -120 -1.6 4.2 -1.4 1.2 x7 0 58.33 -100 41.67 0 -0.5833 1 -0.4167 x8 66.67 -50 41.67 -158.3 -0.6667 0.5 -0.4167 1.583 B = u1 u2 u3 u4 x1 0 0 0 0 x2 0 0 0 0 x3 0 0 0 0 x4 0 0 0 0 x5 20 0 0 0 x6 0 0 -4.167 0 x7 0 0 0 0 x8 0 0 0 0 C = x1 x2 x3 x4 x5 x6 x7 x8 y1 1 0 0 0 0 0 0 0 y2 0 1 0 0 0 0 0 0 y3 0 0 1 0 0 0 0 0 y4 0 0 0 1 0 0 0 0 y5 0 0 0 0 1 0 0 0 y6 0 0 0 0 0 1 0 0 y7 0 0 0 0 0 0 1 0 y8 0 0 0 0 0 0 0 1 D = u1 u2 u3 u4 y1 0 0 0 0 y2 0 0 0 0 y3 0 0 0 0 y4 0 0 0 0 y5 0 0 0 0 y6 0 0 0 0 y7 0 0 0 0 y8 0 0 0 0 Continuous-time state-space model.
x0 = [0 0 0 0 0 0 0 0];
Tf = 10;
Ts = 0.1;
[u1,t] = gensig("sine",20,Tf,Ts);
[u2] = zeros(length(u1),1);
[u3,~] = gensig("sine",12,Tf,Ts);
[u4] = zeros(length(u1),1);
u = [u1 u2 u3 u4 u4 u4 u4 u4]';
size(A)
ans = 1×2
8 8
size(B)
ans = 1×2
8 4
size(C)
ans = 1×2
8 8
size(D)
ans = 1×2
8 4
size(time)
ans = 1×2
1 101
size(u)
ans = 1×2
8 101
y = lsim(dyn,u,x0,time);
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.
plot(y(:,4))

 Réponse acceptée

The size of u is 8 x 101. But as the error message says, it must have the same number of rows as t has elements (101), and it must have the same number of columns as the system has inputs (4). So u should be 101 x 4. Perhaps it should be
u = [u1 u2 u3 u4]

2 commentaires

Hi Paul,
Thank you for your answer. I tried it, however the problem still persists with the same error message.
The time and x0 inputs to lsim need to be reversed, as below. Note the warning recommending to use a smaller time step, but the code runs.
%specify the timestep
dt = 0.1;
tmax = 10;
t = [0:dt:tmax]';
time = t';
%assemble the M matrix
m = [0.5 0.5 1.2 1.2];
M = diag(m);
%assemble the K matrix
k1 = 100;
k2 = 80;
k3 = 70;
k4 = 50;
k5 = 80;
k6 = 60;
k11 = k1 + k2 + k5;
k12 = -k2;
k13 = 0;
k14 = -k5;
k22 = k2 + k3 + k6;
k23 = -k3;
k24 = k6;
k33 = k3+k4;
k34 = -k4;
k44 = k4 + k5 +k6;
k21 = k12;
k31 = k13;
k32 = k23;
k41 = k14;
k42 = k24;
k43 = k34;
K = [k11 k12 k13 k14; ...
k21 k22 k23 k24; ...
k31 k32 k33 k34; ...
k41 k42 k43 k44];
%assemble the F matrix
b2 = [10 0 0 0; 0 0 -5 0; 0 0 0 0; 0 0 0 0]';
%assemble the C matrix
C = 0.01*K;
%assemble the state space model
MK = M\K;
MC = -M\C;
I = eye(length(M));
zer = zeros(length(M));
A = [zer I; -MK -MC];
B = [zeros(4) M\b2]';
C = [eye(length(A))];
D = zeros(8,4);
dyn = ss(A, B, C, D);
x0 = [0 0 0 0 0 0 0 0];
Tf = 10;
Ts = 0.1;
[u1,t] = gensig("sine",20,Tf,Ts);
[u2] = zeros(length(u1),1);
[u3,~] = gensig("sine",12,Tf,Ts);
[u4] = zeros(length(u1),1);
u = [u1 u2 u3 u4];
y = lsim(dyn,u,time,x0); % this line was incorrect
Warning: The input signal is undersampled. Use a sampling period smaller than 3.1e-02.
plot(time,y(:,4))

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by