%% Stabilizing Controller for MIMO Plant
% Stabilize a 5-by-4 unstable plant with three states, two measurement signals, and one control signal.
% In practice, P is an augmented plant that you have constructed by combining a model of the system to control with appropriate H_2 weighting functions. For this example, use the following model.

A = [5    6    -6
     6    0     5
    -6    5     4];
B = [0     4     0     0
     1     1    -2    -2
     4     0     0    -3];
C = [-6     0     8
     0     5     0
    -2     1    -4
     4    -6    -5
     0   -15     7];
D = [0     0     0     0
     0     0     0     1
     0     0     0     0
     0     0     3     6
     8     0    -7     0];
P = ss(A,B,C,D);

%
% Confirm that P is unstable by examining its poles, some of which lie in the right half-plane.

pole(P)

%
% Design the stabilizing controller. h2syn assumes that the nmeas measurement signals and the ncont control signals are the last outputs and last inputs of P, respectively.

nmeas = 2;
ncont = 1;
[K,CL,gamma] = h2syn(P,nmeas,ncont);

%
% Examine the closed-loop system to confirm that the controller K stabilizes the plant.

pole(CL)

%
% Copyright 2015 The MathWorks, Inc.