State-Space Matrix Closed Loop System C Matrix issue
19 views (last 30 days)
Show older comments
Hi, I'm trying to obtain the same output I get with the following commands on Matlab on Simulink.
In Matlab I have the following
% Sistema
A = [-1.15 -0.155 -0.005;1 0 0;0 1 0];
B = [1; 0; 0];
C=[0 0 0.3];
%Espacio de Estados
sys=ss(A,B,C,0);
%% Ecuación deseada
Ps= [1 2 1.5 0.5];
Ed=roots(Ps)
k2 = acker(A,B,Ed)
%% Lazo cerrado
Af=A-B*k2;
%% Calculando los autovalores del sistema en lazo cerrado
eig(Af);
%Condicion inicial
x0=[1 0 1];
%Sistema con realimentación en espacio de estados
slc=ss(Af,B,C,0);
%Respuesta del sistema
figure
subplot(211)
initial(sys,x0)
title('Lazo Abierto (CI)');
subplot(212)
initial(slc,x0)
title('Lazo Cerrado (CI)')
So I obtain the open loop and closed loop responses. In Simulink I've got the open loop answer by inserting a unit step followed by a derivative block.
But here comes the problem, the C matrix is [0 0 0.3] but as I have to introduce the gain, then the dimension of the matrixes on the State Space block have to match. I don't know how to set it up, in order to get the same answer I get from Matlab.
Any idea on how to get that block diagram on Simulink?![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1397954/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1397954/image.png)
1 Comment
Atsushi Ueno
on 30 May 2023
The feedback loop (gain k2) must be multiplied against state x, not the output y of the state space model.
I remember what I previously added a comment to another question.
Accepted Answer
Sam Chak
on 30 May 2023
Edited: Sam Chak
on 30 May 2023
The output of the state-space system is
. Your Ackermann's controller is full state-feedback, not output-feedback.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1398314/image.png)
Thus, the equivalent Simulink model would look something like the configuration shown in Figure 2.
- The state-space slc requires modifications in the C and D matrices.
- Set the Multiplication: Matrix(K*u) in the Gain block K2.
- This Reference input is essentially zero, not a Step signal (because it is not shown in your equation)
% Sistema
A = [-1.15 -0.155 -0.005;
1 0 0;
0 1 0];
B = [1;
0;
0];
C = [0 0 0.3];
% Espacio de Estados
sys = ss(A, B, C, 0);
% step(sys)
Ps = [1 2 1.5 0.5];
Ed = roots(Ps);
k2 = acker(A,B,Ed)
% Lazo cerrado
Af = A - B*k2;
% Calculando los autovalores del sistema en lazo cerrado
eig(Af);
% Condicion inicial
x0 = [1 0 1];
% Sistema con realimentación en espacio de estados
slc = ss(Af, B, C, 0);
%Respuesta del sistema
figure
subplot(211)
initial(sys, x0), grid on
title('Lazo Abierto (CI)');
subplot(212)
initial(slc, x0), grid on
title('Lazo Cerrado (CI)')
Figure 1: Results from MATLAB.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1398324/image.png)
Figure 2: Simulink model.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1398329/image.png)
Figure 3: Results as seen in Simulink Scope.
0 Comments
More Answers (2)
Askic V
on 30 May 2023
This is how I would simulate similar system in simulink.
First of all this is the simulation in Matlab script:
% Transfer function G = 1/((s+1)(s+2)(s+3))
num = 1;
den = conv([1 1],conv([1 2],[1 3]));
% convert to state space
[A,B,C,D] = tf2ss(num, den);
% State space model
sys = ss(A,B,C,D);
% Gain to place closed loop poles at -3,-4,-5
K = acker(A,B,[-3; -4; -5])
% Close loop matrix A
Af = A-B*K;
%eigenvalues of Af are desired pole locations
eig(Af);
%Initial condition
x0 = [1 0 2];
% State space model of closed loop system
slc = ss(Af,B,C,D);
% Plot responses
figure
subplot(211)
initial(sys, x0)
title('Open loop');
grid on
subplot(212)
initial(slc, x0)
title('Closed loop')
grid on
in order
In order to make Simulink simulation, you need to have state feednack controller, i.e. each gain in the K vector should mulitpy corresponding state variable. However, from the state space Simulink model, you have only output. In my example C vector is [0 0 1], so state variables can be chosen as: x3 = y, x2 = dy/dt, x1 = d2y/dt.
The simulation would look like this:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1398294/image.png)
Please note that in the ss model of the closed loop system, i used Af = A-B*K matrix instead of A.
The outputs are very similar though not the same. I guess it is because of the numerical calculations of derivative blocks in the state feedback loop. To make something more realistic, you should design observer for this system that will have one input (y) and three oututs or output 3x1 (state variables x), and then use gain vector K to construct state feedback loop.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1398299/image.png)
I hope I was able to, at least, give you some useful hints how to proceed further.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!