I have designed a system using a minimum realization.

I have the A, B, C matrices and I have assigned closed loop poles for the system.

I used the place command to find my K matrix.

I am wondering if it is possible to use the lsim matlab command to simulate my closed loop system (A-B*K)?

$$x' = Ax+Bu$$ $$u=-Kx$$ $$x' = (A-BK)x$$ $$y=Cx$$

All examples I have found for lsim use the system transfer function or the open loop system.

I have seen examples such as this:

t = 0:0.01:10;         % simulation time = 10 seconds
u = zeros(size(T));    % no input
x0 = [0.1 0.1 0.1];    % initial conditions of the three states
sys= ss(A,B,C,D);

But I am not sure how to use this with the closed loop (A-B*K) system.

Any help would be appreciated! Thank you.


1 Answer 1


Yes, you can using the feedback command. However, if your open-loop system is defined by your state-space system sys= ss(A,B,C,D), then your closed-loop system would be defined as follows (and not by A-B*K as you suggest):

CL_loop = feedback(sys,K); % K is your controller/compensator, this needs to be an LTI object
lsim(CL_loop,u,t,x0); % you might have additional states due to the feedback loop, and so would need additional IC

Note that you may also need to change your input vector, as it's now representing your desired trajectory.

Update after comment & question edit

I think it's just a matter of creating a new state-space representation with the appropriate matrices, e.g.:

CL_loop = sys(A-B*K,zeros(size(B)),C,zeros(size(D))); % implement x'=(A-B*K)*x & y = C*x
  • $\begingroup$ Thank you for reading! This seems to still not be exactly what I am looking for, as the feedback that I would like is u=-Kx. I think what you provided would give u =-Ky. $\endgroup$
    – DarkLink
    Commented May 1, 2019 at 1:01
  • $\begingroup$ I have updated my answer based on the extra information you provided in the question, I think it's just a matter of constructing a state-space system with the right matrices. $\endgroup$
    – am304
    Commented May 1, 2019 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.