%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
% solves 2x2 systems and plots phase plane      %
%                                               %
%                                      %
%   y' = A*y                     %
%                                               % 
% requires the use of file:  harmosc.m          % 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

clear;

global c;
global m;
global k;


  c = 0;%-0.3; %.3;
  m = 1;
  k = 1;

% time span of integration
  tspan = [0 20];
% initial conditions
x0 = 0; %1.3*pi;
y0 = .2; %.1;
v0 = [x0,y0];

% solves ode using ode45 routine

[t,vout] = ode45(@odeplay_2x2,tspan,v0);

% 
%   plots y(t) for xstar=0.0 in an upper subplot
%

% note:
%%paramstring = sprintf( ', {\\itb}=%d, {\\itc}=%d,{\\itx_0}=%d', b, c, xstar);

figure(1)
clf
subplot(3,1,1)

plot( t, vout(:,1) );
xlabel( '{\itt}' );
ylabel( '{\itx}({\itt})' );
%title('Prey')
axis tight;
grid on;

subplot(3,1,2)

plot( t, vout(:,2) );
xlabel( '{\itt}' );
ylabel( '{\ity}({\itt})' );
%title( 'Predator')
axis tight;
grid on;

subplot(3,1,3)

plot( vout(:,1), vout(:,2) );
xlabel( '{\itx}' );
ylabel( '{\ity}' );
title( 'Phase plane')
%axis tight;
axis equal;
grid on;

%figure(2)

hbead=line(vout(1,1),vout(1,2),'marker','o','markersize',8,'erase','xor');
%axis([-1 1 -1 1]);
%axis('square');
for k=2:length(t)
    set(hbead,'xdata',vout(k,1),'ydata',vout(k,2));
    drawnow
    pause(.01)
end    

