"feedback" function example in Matlab documentation doesn't seem to work?
4 views (last 30 days)
Show older comments
I am trying to reproduce Example 2 in the documentation for the function "feedback" in Matlab2014a.
The example :
Consider a state-space plant P with five inputs and four outputs and a state-space feedback controller K with three inputs and two outputs. To connect outputs 1, 3, and 4 of the plant to the controller inputs, and the controller outputs to inputs 4 and 2 of the plant, use
feedin = [4 2];
feedout = [1 3 4];
Cloop = feedback(P,K,feedin,feedout)
My code :
P = rss(4,4,5);
K = rss(2,2,3);
feedin = [4 2];
feedout = [1 3 4];
Cloop = feedback(P,K,feedin,feedout);
size(Cloop)
Result:
Instead of returning a 3 input, 1 output closed-loop system, Matlab gives a system of the same size as P:
State-space model with 4 outputs, 5 inputs, and 6 states.
Why isn't this working properly?
1 Comment
Answers (1)
Sam Chak
on 8 May 2024
Hi @Mark
Using the 'feedback()' command to compute the closed-loop model with the specified input and output connections doesn't affect the number of inputs and outputs. However, if there are any cancellable poles and zeros, some states will be eliminated. The number of outputs and inputs is reflected in the tiled chart layout, which has the number of rows (outputs) by columns (inputs) of tiles in the response plot.
%% State-space Proces
Ap = [0, 1; -1, -2];
Bp = [0; 1];
Cp = eye(size(Ap));
Dp = 0*Cp*Bp;
P = ss(Ap, Bp, Cp, Dp);
size(P)
%% State-space Kontroler
Ak = [0, 1; 0, -2];
Bk = [0; 1];
Ck = [1, 0];
Dk = 1;
K = ss(Ak, Bk, Ck, Dk);
size(K)
%% Closed-loop system (before pole-zero cancellation)
feedin = [1]; % feed [Pin(1)] from [Kout(1)]
feedout = [1]; % feed [Pout(1)] to [Kin(1)]
Cloop = feedback(K*P, 1, feedin, feedout, -1);
size(Cloop)
%% Closed-loop system (after pole-zero cancellation)
Cloop = minreal(Cloop)
size(Cloop)
%% Step response
step(Cloop), grid on
0 Comments
See Also
Categories
Find more on Dynamic System Models in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!