% Problem 3.2
% Model of the system
disp(' ')
disp('Problem 3.2: System model')
A = [ 0  0  1  0;
      0  0  0  1;
     12.49 -12.54 0 0;
    -14.49 29.36 0 0]
B = [ 0; 0; -2.98; 5.98]
C = [1 0 1 0]
D=0

% 3.2(a) Eigenvalues and characteristic polynomial
[V,Dm] = eig(A);
disp(' ')
disp('3.2(a) - Eigenvalues:')
diag(Dm)

disp(' ')
disp('3.2(a) - Characteristic polynomial:')
P = poly(A)

% 3.2(b) Modal canonical form
disp(' ')
disp('3.2(b) - Modal canonical form')
Am=Dm
Bm=inv(V)*B
Cm=C*V
Dm=D

% 3.2(c) Open-loop transfer function
disp(' ')
disp('3.2(c) - Open-loop transfer function:')
[b,a]=ss2tf(A,B,C,D,1);
printsys(b,a,'s')

% 3.2(d) Controller and observer canonical form
disp(' ')
disp('3.2(d) - Controller canonical form:')
cont_form=diag(ones(3,1),1);
row4=[-a(2:5)];
Ac=[cont_form(1:3,:); row4]
Bc=[0 0 0 1]'
Cc=[b(5) b(4) b(3) b(2)]
Dc=0 

disp(' ')
disp('3.2(d) - Observer canonical form:')
obs_form=diag(ones(3,1),-1);
col4=[-a(2:5)'];
Ao=[obs_form(:,1:3) col4]
Bo=[b(5) b(4) b(3) b(2)]'
Co=[0 0 0 1]
Do=0

