% Losning til oving 2
% Fag: Prosessregulering
% DDiR, sept 2002

% Systemdefinisjoner
K=1; A1=2; A2=1;

A=[-K/A1  K/A1
   K/A2 -K/A2];

B=[1/A1 0
   0    1/A2]

C=[0; -1/A2];

% Oppg f)
x0=[1;2];
x=x0;
t=0:0.01:16; N=length(t);
for k=1:N
   X(k,1:2)=x';
   x=expm(A*t(k))*x0;
end

figure(1)
subplot(211), plot(t,X(:,1)), grid
ylabel('x_1')
title('Autonom respons ved u_1=u_2=v=0')
subplot(212), plot(t,X(:,2)), grid
ylabel('x_2'), xlabel('Tid [s]')

% Oppg g)
Aa=A+C*[0 K];

x0=[1;2];
x=x0;
t=0:0.01:16; N=length(t);
for k=1:N
   X(k,1:2)=x';
   x=expm(Aa*t(k))*x0;
end

figure(2)
subplot(211), plot(t,X(:,1)), grid
ylabel('x_1')
title('Autonom respons med u_1=u_2=0 og v=kx_2')
subplot(212), plot(t,X(:,2)), grid
ylabel('x_2'), xlabel('Tid [s]')



   