Setting up u vector when using lsim

Viewed 233

I have a frustrating error when using Matlab where I'm trying to simulate a continuous time system in discrete time.

Ts = 0.01;
A=[-0.313 0 56.7;
    0 56.7 0;
    -0.0139 0 0.426];
B = [0.232; 0; 0.0203];
C = [0 1 0];
D = 0;

SYSC = ss(A,B,C,D);
SYSD = c2d(SYSC,Ts);

t = linspace(0,10,10/0.01)';
u = zeros(1000,3);
u(:) = 0.2;
lsim(SYSD,u,t);

I am getting the error:

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 is meant by input channels here? Overall I'm not sure how I can fix this error. I have a set time for which I want the simulation to run but I do not know how to set up my vector of inputs correctly. I am modeling three states.

1 Answers

If your input matrix is B = [0.232; 0; 0.0203] and is a 3-by-1 column vector, then the linear system given by A*x + B*u only has one control input.

So u should be:

u = zeros(1000,1);
u(:) = 0.2;

And you can simulate the discrete time system using

lsim(SYSD,u,[]);

Note that you don't need to define the time vector in lsim for the discrete simulation because u is sampled at the same rate as SYSD.

If the B matrix was 3-by-3, then you would need to have 3 control inputs.

Related