%% Controller Design with Pole-Placement Constraint
% Given a plant, design a controller such that the poles of the closed-loop system lie in the half-plane defined by Re(s) < –1.
% You can define this region for pole-placement using the interactive lmireg  command. To do so,
% Enter region = lmireg at the MATLAB® command line.
% Enter h to specify a half-plane constraint.
% Enter l to specify the left half-plane.
% Enter -1 to specify that the cutoff for the region is x0 =  –1.
% Enter q to exit and create the LMI region.
% The region created by this process is equivalent to the following commands. (For more information, see the lmireg reference page.)

RealPart = -1; 
region = [-2*RealPart + 1i 1]; 

%
% Specify the plant model. For this example, use a two-input, three-output plant. Assume the plant contains one control signal and one measurement signal (nmeas = ncont = 1), and is partitioned such that these signals are the last input and output, respectively.

A = [1 0;2 1]; 
B = [1 1;1 0]; 
C = [1 1;1 1;1 1]; 
D = zeros(3,2);
P = ss(A,B,C,D);

%
% Compute a controller for P using the LMI region to restrict the closed-loop pole locations. Apply an H_2 norm constraint to one signal (Nz2 = 1) and give the H_2 and H_{\infty } norms equal weight.

ncont = 1;
nmeas = 1;
Nz2 = 1 ;
Wz = [0 0];
[K,CL] = h2hinfsyn(P,nmeas,ncont,Nz2,Wz,'Region',region); 

%
% Confirm that the poles of the closed-loop system have Re(s) < –1.

pole(CL)

%
% You can push the closed-loop eigenvalues further left by changing RealPart. Or you can define other pole-placement regions. For instance, place the poles such that Re(s) falls in a strip of the complex plane –5 < Re(s) < –3. To define this region, use lmireg interactively to create reg1 specifying Re(s) > –5, and reg2 specifying Re(s) < –3. Then, enter region = lmireg(reg1,reg2) to define the intersection of these two regions. The following code is equivalent.

LeftRealPart = -5; 
RightRealPart = -3;
region = [-2*RightRealPart + 1i 0 1 0;
           0 2*LeftRealPart + 1i 0 -1];

%
% Compute the new controller and confirm the locations of the closed-loop poles.

[K,CL] = h2hinfsyn(P,nmeas,ncont,Nz2,Wz,'Region',region); 
pole(CL)

%
% Copyright 2018 The MathWorks, Inc.