close all
clear all
clc

A = [0 1; -2 -3];
b = [1 1]';
v0 = [0 0]';
v_tau = [1 -3]';
tau = 1;

syms s 
% beta = [beta1; beta2];
X = b'*inv(s*eye(2)+A'); % x beta
fprintf('X(s) = \n')
pretty(simplify(X))
V = inv(s*eye(2)-A)*b*X; % x beta
fprintf('V(s) = \n')
pretty(simplify(V))
vt = ilaplace(V);
fprintf('v(t) = \n')
pretty(simplify(vt))


t=1;
vbar = [1; -3];
v11  = -2.5*exp(-t) + 2.5*exp(t) + exp(-2*t) - exp(2*t);
v12  = 0.5*exp(-t) - 2.5*exp(t) + 2*exp(2*t);
v21  = 2.5*exp(-t) - 0.5*exp(t) - 2*exp(-2*t);
v22  = -0.5*exp(-t) + 0.5*exp(t);
M    = [v11 v12; v21 v22]
beta = inv(M)*vbar

i=0;
for t=0:0.01:1.2
    i=i+1;
    x(i) = [3*exp(t)-2*exp(2*t) 4*exp(2.*t)-3*exp(t)]*beta;
    v11  = -2.5*exp(-t) + 2.5*exp(t) + exp(-2*t) - exp(2*t);
    v12  = 0.5*exp(-t) - 2.5*exp(t) + 2*exp(2*t);
    v21  = 2.5*exp(-t) - 0.5*exp(t) - 2*exp(-2*t);
    v22  = -0.5*exp(-t) + 0.5*exp(t);
    v(i,:)=[v11 v12; v21 v22]*beta;
end
t=0:0.01:1.2;
figure
plot(t,x)
hold on
plot(t,v(:,1),'k:')
plot(t,v(:,2),'r--')
plot(1,1,'ko','MarkerFaceColor','k','MarkerSize',10)
plot(1,-3,'ro','MarkerFaceColor','r','MarkerSize',10)

legend('x','v1','v2')
xlabel('t')
axis([0 1.5 -5 8])
grid on