Poincaré maps in CL/SMALL>_MATCONT

When computing an orbit $(t,y(t))$ in Matlab an event can be defined as going through a zero of a given scalar function $G(t,y).$ If $G$ does not explicitly depend on time in an autonomous dynamical system, this feature can be used to detect Poincaré intersections. One does this by setting the Events property to a function handle, e.g. @events, creating a function [value,isterminal,direction] = events(t,y) and calling

[t,Y,TE,YE,IE] = solver(odefun,tspan,y0,options).

For the $i$-th event function:

Corresponding entries in TE, YE, and IE return, respectively, the time at which an event occurs, the solution at the time of the event, and the index $i$ of the event function that vanishes.

Example

Let a set of two event functions be introduced by defining the function testEV:

function [value,isterminal,direction]= testEV(t,y,varargin)
value=[y(1)-0.2;y(2)-0.3];
isterminal=zeros(2,1);
direction=ones(2,1);
end
This event function requires that the system is at least two-dimensional and defines two events, namely $y(1)=0.2$ and $y(2)=0.3$. The integration will not be terminated if an event is detected and all zeros will be detected regardless of the direction of $y$ (increasing or decreasing).

We now consider the system adaptx in the directory Testruns/TestSystems of MATCONT with three state variables and two parameters. By runnning the script testPoincare:

TSTP=@testEV;
OPTIONS = odeset('RelTol',1e-8,'Events',TSTP);
hls = adaptx;
[t,y,TE,YE,IE] = ode45(hls{2},[0 300],[0.3 0.5 -0.1],OPTIONS,1,0.8);
x0 = y(end,:);
[t,y,TE,YE,IE] = ode45(hls{2},[0 10],x0,OPTIONS,1,0.8);
we integrate the system adaptx from $0$ to $300$ and then further from $300$ to $310$ starting from the point $[0.3;0.5;-0.1]$ with parameter values $1,0.8$ and we detect the points in the second run where $y(1)=0.2$ or $y(2)=0.3.$ The output is given by

TE =

    5.6334
    6.6979

YE =

   -0.2247    0.3000    0.3131
    0.2000    0.4213   -0.1059

IE =

     2
     1

The test is run by typing testPoincare in the command line.