%PH_PORT.M script produces a phase portrait interactively using the mouse

% Last modified by S. H. Zak on November 19, 2002

clear
clc
disp('               -----------------------------------------------------------------------------------------')
disp('You will use the mouse to generate a phase portrait of the van der Pol equation for mu=1.')
disp('The script from page 57 of the book.')
disp('               -----------------------------------------------------------------------------------------')
disp('To generate a trajectory, use the mouse to select initial condition and click on the LEFT BUTTON.')
disp('Press the RIGHT BUTTON to quit.')
disp('You can maximize the figure window for better effect.')
disp('Press ENTER to continue.')
pause
tspan=[0 20];
x0=[-.1 .1]';
button=1;
axis(4*[-1 1 -1 1])
axis square
hold on
% we now draw internal axes
p=4*[-1 0;1 0];
p=4*[-1 0;1 0];
plot(p(:,1),p(:,2))
plot(p(:,2),p(:,1))
%grid
xlabel('{\it{x}}_1','Fontsize',12)
ylabel('{\it{x}}_2','Fontsize',12)
title('Phase portrait of the van der Pol equation for \mu=1','Fontsize',12)
set(gca,'Fontsize',12)
    while(button==1)
       [t,x]=ode23s(@php_pol,tspan,x0);
      plot(x(:,1),x(:,2))
      [x1,x2,button]=ginput(1);
      x0=[x1 x2]';
    end