1.35 How to build and connect a closed loop control systems and show the response?

1.35.1 example 1, single input, single output closed loop

1.35.1 example 1, single input, single output closed loop

Given the following simple closed loop system, show the step response. Let mass \(M=1\text {kg}\), damping coefficient \(c=1 \text {newton-seconds per meter}\) and let the stiffness coefficient be \(k=20\text {newton per meter}\).

pict

Using propertional controller \(J(s)=k_p\) where \(k_p=400\). First connect the system and then show \(y(t)\) for 5 seconds when the reference \(y_r(t)\) is a unit step function.

Mathematica

m = 1; c = 1; k = 20; kp = 400; 
plant      = TransferFunctionModel[1/(m s^2 + c s + k), s]; 
controller = TransferFunctionModel[kp, s]; 
sys        = SystemsModelSeriesConnect[plant, controller]; 
sys        = SystemsModelFeedbackConnect[sys]; 
o          = OutputResponse[sys, UnitStep[t], t]; 
Plot[o, {t, 0, 10}, Frame -> True, PlotRange -> All, 
  FrameLabel -> {{"y(t)", None}, 
    {"t (sec)", "response of closed loop"}}, 
    BaseStyle -> 14]
 

pict

Matlab

close all; 
m = 1; c = 1; k = 20; 
s          = tf('s'); 
plant      = 1/(m*s^2+c*s+k); 
controller = 400; 
sys        = series(controller,plant); 
sys        = feedback(sys,1); 
[Y,T]      = step(sys,0:.01:10); 
plot(T,Y); 
xlabel('time (sec)'); 
ylabel('y(t)'); 
title('response of closed loop');
 

Another way to do the above is

m=1; 
c=1; 
k=20; 
s=tf('s'); 
sys3=1/(m*s^2+c*s+k); 
sys2=400; 
sys1=1; 
sys=append(sys1,sys2,sys3); 
Q=[2 1 -3;3 2 0]; 
input=[1]; 
output=[2 3]; 
sys=append(sys1,sys2,sys3); 
sys=connect(sys,Q,input,output); 
T=0:.01:10; 
[Y,T,X]=step(sys,T);
 

pict