% Solution Exercise 1: Numerical part

U=[1 0 0 0 0]'; Y=[-1 2 -1 -1.9 -1.93]';

% Step 2) Impulse responses
H0=Y(1)/U(1);
H1=Y(2)/U(1);
H2=Y(3)/U(1);
H3=Y(4)/U(1);
H4=Y(5)/U(1);

% Step 5) Computations of O2 og C2
H12 =[H1 H2; H2 H3]

[U,S,V]=svd(H12);
% System order, n, equal to the number of singular values different from
% zero.
s=diag(S)
n=2
% Splitting up the SVD
S1=S(:,1:2); U1=U(:,1:2); V1=V(:,1:2);
O2=U1;                  % Observerbility matrix
C2=S1*V1';              % Controllability matrix
b=C2(:,1) 
d=O2(1,:)

% Computing A
H22=[H2 H3; H3 H4]
a=pinv(O2'*O2)*O2'*H22*C2'*pinv(C2*C2')

% Test: Check if the model gives the impulse responses.
h1=d*b
h2=d*a*b
h3=d*a^2*b
h4=d*a^3*b