
a=-4;b=1;c=2;d=-3; % \lambda_1=-2, \lambda_2=-5

%a=2; b=2; c=-4; d=6; % \lambda=4+2i

A=[ a,b ; c,d ];
[V,D]=eig(A);   % D - eigenvalue, V- eigenvector

figure(1);
[x,y]=meshgrid(-5:0.4:5,-5:0.4:5);
xp=a*x+b*y;yp=c*x+d*y;
quiver(x,y,xp,yp);
hold on;
axis([-2 2 -2 2]);

% straightline solution

L=5;
plot([-L*V(1,1) L*V(1,1)],[-L*V(2,1) L*V(2,1)],'r'); 
plot([-L*V(1,2) L*V(1,2)],[-L*V(2,2),L*V(2,2)],'r');

F=@(t,Y)[a*Y(1)+b*Y(2); c*Y(1)+d*Y(2)];

[t,Y]=ode45(F,[0 10],[1,1]);
plot(Y(:,1),Y(:,2),'LineWidth',1);
hold off


%[t,Y]=ode45(F,[0 -5],(V(:,1)+V(:,2)));
%plot(Y(:,1),Y(:,2),'LineWidth',1);
%hold off

figure(2);
plot(t, Y);

%[t,Y]=ode45(F,[0 -5],(V(:,1)-V(:,2)));
%plot(Y(:,1),Y(:,2),'LineWidth',1);

%[t,Y]=ode45(F,[0 -5],(-V(:,1)+V(:,2)));
%plot(Y(:,1),Y(:,2),'LineWidth',1);


%[t,Y]=ode45(F,[0 -5],(-V(:,1)-V(:,2)));
%plot(Y(:,1),Y(:,2),'LineWidth',1);



hold off;

%for i=1:4
%    [t,Y]=ode45(F,[0 5],[1 2]);
%    plot(Y(:,1),Y(:,2),'LineWidth',1);
%end
%hold off;
