Getting a "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
2 views (last 30 days)
Show older comments
I have a state space representation of a dynamical system. It 1 input and 3 outputs. I get the following error when I run my code: "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." What am I doing wrong? Thank you.
clc
clear all
close all
t = 0:0.05:10;
m0 = 0.25; m1 = 0.1; m2= 0.08; %[kg]
L1 = 0.25; L2 = 0.2; %[m]
g = 9.81; %[m/s^2]
u = sin(size(t)); %[N]
A = [0 1 0 0 0 0;
0 0 0 0 0 0;
0 0 0 1 0 0;
0 0 (3*(m1+2*m2))/(2*L1*(m1+3*m2)) 0 0 0;
0 0 0 0 0 1;
0 0 0 0 3*g/2*L2 0];
B = [1/(m0+m1+m2);0;0;0;0;0];
C = [1 0 0 0 0 0
0 0 1 0 0 0
0 0 0 0 1 0];
D = [0;
0;
0];
states = {'x' 'x_dot' 'theta1' 'theta1_dot' 'theta2' 'theta2_dot'};
inputs = {'u'};
outputs = {'x'; 'theta1'; 'theta2'};
sys_ss = ss(A,B,C,D,'statename',states,'inputname',inputs,'outputname',outputs);
set(sys_ss,'InputName',inputs)
set(sys_ss,'OutputName',outputs)
[y,t] = lsim(sys_ss,u,t);
plot(t,y)
0 Comments
Answers (1)
Walter Roberson
on 25 Oct 2020
t = 0:0.05:10;
That has 201 entries. When you pass that vector of 201 entries into the time slot of lsim() then your state table, u, needs to have 201 rows.
u = sin(size(t))
size(t) is [1 201], so you are taking the sine of 1 radian and 201 radians, producing a 1 x 2 output.
Perhaps what you wanted was
u = sin(t);
but that would give you a 1 x 201 array, which would have one row instead of length(t) rows. So you would need
u = sin(t(:));
0 Comments
See Also
Categories
Find more on Digital Filter Analysis 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!