% reachflow.m - generate a sample flow for reachability figure
% RMM, 17 Dec 07

aminit;

% Construct the linear system
A = [0 1; 0 0];
B = [0; 1];
C = [1 0];
D = 0;
sys = ss(A, B, C, D);

% Set up a figure for holding this (to be imported into xfig)
figure(1); clf; hold on; axis off;

% Vector of switch times
Tlist = [   4   4    3    3    2   2    1    1]
Ulist = [-0.1 0.1  0.1 -0.1 -0.1 0.1  0.1 -0.1];

tstart = 0; xstart = [1 0];
for i=1:length(Tlist)
  % Simulate the system for this time interval
  Ti = 0:0.01:Tlist(i);
  Ui = ones(size(Ti)) * Ulist(i);
  [y, t, xi] = lsim(sys, Ui, Ti, xstart); 

  % Plot out the segment and print the endpoint
  plot(xi(:,1), xi(:,2), 'Linewidth', AM_data_linewidth); 
  
  % Set the initial conditions for the next run
  xstart = xi(length(y),:)
end

amprint('reachflow.eps');
