Simulation Functions

simpahs
% SIMPAHS simulates a controlled pahs using a trapezoid ODE solver
%
% Usage [X,T,M,L]=SIMPAHS(PAHS,CTCAT,X0,L0,M0,TIME,EVENTS,STEP)
%
% PAHS the pahs to be controlled
% CTCAT the controller catelog (SEE SOL2CTRL)
% X0 initial continous state
% L0 the initial location X0 belongs to
% M0 the initial mode
% TIME the simulation time
% EVENTS externally triggerd event times
%  EVENTS{i}.TIME=10 time of the event
%  EVENTS{i}.mode=2 the destination mode of the transition
%  Note that the time of event i must be grater than the time of event i-1
% STEP the step size used by the solver
%
% X a vector of states
% T the time corresponding to the state vector
% M a vector of modes
% L a vector of locations
%
% Example:

 pahs=demopahs2();
 dgabs=finddiscgame(pahs);
 req=demoreq2();
 spec=req2spec(pahs,req);
 [win,sol]=finddgsol(dgabs,spec);
 if(win)
    disp('Winning')
    ctcat=sol2ctrl(pahs,dgabs,sol);
    l0=req.init{1}.loc;
    m0=req.init{1}.modes(1);
    x0=mean(horzcat(pahs.mode{m0}.loc{l0}.s.vertices{:}),2);
    events{1}.time=3;
    events{1}.mode=2;
    simtime=1000;
    step=.5;
    [x,t,m,l]=simpahs(pahs,ctcat,x0,l0,m0,simtime,events,step);
 end

% See also PLOTPAHS and SOL2CTRL