% Exercise 1b
% m-file solution task 9 in Exercise 1b
% Task 1.9

Ac=[0 1;-8 -6]; Bc=[0;1]; Dc=[1 0];  % Continuous time state space model matrices

Dt=0.1;
t=0:Dt:5;
N=length(t);

[A,B,D,E]=c2dm(Ac,Bc,Dc,0,Dt,'zoh'); % Discrete time linear state space model
                                     % Same as:
                                     % A=expm(Ac*Dt)
                                     % B=inv(Ac)*(expm(Ac*Dt)-eye(2))*Bc

U=ones(N,1);                         % Input u=1
x=[0;0];                             % Initial state

% Simulate system
for k=1:N
    y=D*x;
    
    Y(k,1)=y;
    
    u=U(k,1);
    
    x=A*x+B*u;
end

figure(1)
plot(Y), grid
title('Output y_k')
xlabel('Samples')
ylabel('y_k')