%E5_13PH is a script to produce phase portraits,  using the mouse, 
% of the linear optimal closed-loop system as well as a phase poratrait of the linear open-loop system
% In order to obtain a phase portrait of the uncontrolled system, go to the file
% HW4LIN and uncomment the equation of the opne-loop system
% and comment the closed-loop system equations.
% Here, we construct the phase portrait of the controlled closed-loop linear system.
%The result is Figure 5.18 of Example 5.13.

% last modified  by S. H. Zak on November 20, 2002

clear
clc

disp('              -------------------------------------------------------------------')
disp('You are about to construct interactively a phase portrait')
disp('of the optimal linear closed-loop system as well as a phase portrait of the open-loop,')
disp('uncontrolled, linear system.')
disp('In order to obtain a phase portrait of the uncontrolled system, go to the file')
disp('HW4LIN and uncomment the equation of the open-loop system')
disp('and comment the closed-loop system equations.')
disp('Here, we construct the phase portrait of the controlled optimal linear system.')
disp('The result is Figure 5.18 of Example 5.13.')
disp('When ready to start constructing a phase portrait, press ENTER, maximize')
disp('the figure window, select an initial condition, press the LEFT BUTTON, and')
disp('repeat the process of selecting initial condtion. To stop, press the RIGHT BUTTON.')
pause


% last modified  by S. H. Zak on November 20, 2002

%t0=0;
%tf=20;
tspan=[0 20];
x0=[-.1 .1]';
button=1;
% we now draw internal axes
p=10*[-1 0;1 0];
axis([-10 10 -10 10])
hold on
axis square
plot([-10 10],[0 0])
plot([0 0],[-10 10])
xlabel('{\it{x}}_1','Fontsize',12)
ylabel('{\it{x}}_2','Fontsize',12)
title('Phase portait of a linear system of Example 5.13.','Fontsize',12)
set(gca,'Fontsize',12)
    while(button==1)
       [t,x]=ode23s('hw4lin',tspan,x0);
      plot(x(:,1),x(:,2))
      [x1,x2,button]=ginput(1);
      x0=[x1 x2]';
    end