Clear Filters
Clear Filters

Simulating linear model, can't understand error

2 views (last 30 days)
I have a linear system called "ss" identified using "velocity", "position", and "time_sec_" vectors imported from a CSV file.
Used time interval of 0.02, delay of 0.4, included disturbance.
The 3rd order system looks like this:
>> [A,B,C,D,K,x0,dA,dB,dC,dD,dx0] = idssdata(ss)
A =
-0.2101 -3.0985 -0.8638
2.5007 -4.9519 -11.9558
0.1966 0.4627 8.4746
B =
C =
31.8116 -0.8537 0.0245
D =
K =
x0 =
dA =
1.0e+14 *
1.2124 0.1556 0.1185
2.6893 1.5376 1.1212
2.1587 1.5017 1.2671
dB =
1.0e+11 *
dC =
1.0e+14 *
1.0754 0.0817 0.0737
dD =
dx0 =
1.0e+14 *
I want to simulate the system. It's SISO (velocity -> position) but because it's third order I have to duplicate the velocity three times, one for each system state variable.
U = velocity * ones(1, 3)
Here is what I am calling lsim with:
>> size(U)
ans =
2415 3
>> size(time_sec_)
ans =
2415 1
I attempt to simulate the system:
lsim(ss, U, time_sec_)
Matlab returns the following error:
Error using DynamicSystem/lsim
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.
This error message doesn't make sense because:
  • U has as many rows as time samples in time_sec_ vector
  • U has as many columns as rows in "B" matrix in the model (third order model, B has 3 rows)
  • time_sec_ vector has one row for each time sample
  • Time samples are absolute values increasing in time, in seconds

Accepted Answer

Paul on 16 Apr 2024
Edited: Paul on 17 Apr 2024
Hi Valeriy,
Because the B matrix has one column, the input to the system is a scalar. Hence the U input to lsim should have one column and as many rows as time samples. Each entry in U is the scalar input to the the system at the corresponding time sample in time_sec_
Also, I suggest not using ss as a variable name. Doing so overrides the same-named functions in a couple of different toolboxes.
which ss -all
/MATLAB/toolbox/control/ctrlmodels/@ss/ss.m % ss constructor /MATLAB/toolbox/control/ctrlmodels/@DynamicSystem/ss.m % DynamicSystem method /MATLAB/toolbox/ident/ident/@idParametric/ss.m % idParametric method /MATLAB/toolbox/mpc/mpc/@mpc/ss.m % mpc method /MATLAB/toolbox/shared/controllib/engine/@StaticModel/ss.m % StaticModel method
  1 Comment
Valeriy on 17 Apr 2024
This is the first thing I tried but it didn't work. I finally realized that the first error message I got was complaining about the time vector, because it was the original time samples which were not completely evenly spaced.
It finally succeeded when I generated the time samples synthetically, and used that as the time input to lsim:
linspace(7, 64, 29000)

Sign in to comment.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!