% main4.m
global w;
y0 = [60; 70];  % initial conditions, starting point of the dog
w = 10;         % w  speed of the dog
options= odeset('RelTol',1e-5,'Events','on');
[t,Y] = ode23 ('dog', [0 20], y0, options);

J=[];
for h= 1:length(t),
   w = jogger(t(h));
   J = [J; w'];
end

xmin = min (min (Y (:, 1)), min (J (:, 1)));
xmax = max (max (Y (:, 1)), max (J (:, 1)));
ymin = min (min (Y (:, 2)), min (J (:, 2)));
ymax = max (max (Y (:, 2)), max (J (:, 2)));
clf; hold on;
axis ([xmin xmax ymin ymax]);
% axis ('equal');
title ('The Jogger and the Dog.');

for h=1:length(t)-1,
   plot ([Y(h,1), Y(h+1,1)] , [Y(h,2), Y(h+1,2)], '-', ...
         'Color', 'yellow', 'EraseMode','none');
   plot ([J(h,1), J(h+1,1)] , [J(h,2), J(h+1,2)], ':', ...
        'Color', 'green', 'EraseMode','none');
   drawnow;
   pause(1);
end
hold off;

