%
%   This script verifies the solution to ex 5.10 in MatSyst
%
A = [ 1 3 0; 2 1 1; 0 -1 2 ];
B = [ 1 1 0 ]';

%
% The pole placement algorithm
%
a = poly(eig(A));
gamma = poly(zeros(3,1));
g = a-gamma;
GAMMA = ctrb(A,B);
t = (GAMMA'\[0 0 1]')';
T = [ t;t*A;t*A^2];
K = fliplr(g(2:end))*T;

Atilde = A + B*K;
for k = 1:3
    disp(Atilde^k);
end

% >> ex5_10
%    -1.5000    1.5000    1.5000
%    -0.5000   -0.5000    2.5000
%          0   -1.0000    2.0000
% 
%     1.5000   -4.5000    4.5000
%     1.0000   -3.0000    3.0000
%     0.5000   -1.5000    1.5000
% 
%    1.0e-13 *
% 
%     0.1377    0.0355   -0.0711
%    -0.0067    0.1776   -0.0711
%    -0.0067    0.0377    0.0711