I need to draw the Poincarè map of a dynamical system with $ d=2$ degrees of freedom, so I have $ 4$ dynamical variables. Two of them, $ n_2$ and $ n_3$ are “actions” while the others, $ \varphi_2$ and $ \varphi_3$ are “angles”, so they are defined $ \mathrm {mod}(2\pi)$ . The four equations of motion are too long to be listed here, but they are in the form

$ \dot{\varphi}_2=f_1(\varphi_2,\varphi_3,n_2,n_3) $

$ \dot{\varphi}_3=f_2(\varphi_2,\varphi_3,n_2,n_3) $

$ \dot{n}_2=f_3(\varphi_2,\varphi_3,n_2,n_3) $

$ \dot{n}_3=f_4(\varphi_2,\varphi_3,n_2,n_3) $

The trajectory is a curve in a 4-dimensional space.

First of all, we know that the trajectory is confined in a 3D manifold corresponding to the constraint

$ H(\varphi_2,\varphi_3,n_2,n_3)=E $

where $ H$ , the Hamiltonian of the system, is known.

The Poincarè section that I would like to draw corresponds to the additional constraint

$ n_3=\frac{N-n_2}{2} $

where $ N$ is a parameter set by the user. In agreement with the rules of the Poincarè sectioning technique, a conventional direction must be chosen: let’s say that if the trajecotry strikes the sectioning plane from the sub-space

$ n_3 > \frac{N-n_2}{2} $

then the point must be collected and added to the Poincarè map. On the contrary, if the trajectory comes from the other sub-space, then the intersection point must be discarded.

Can someone provide a working script? In particular, taking care of the following issues:

- Angle variables $ \varphi_2$ and $ \varphi_3$ must be defined up to $ 2\pi$ ;
- Poincarè map should take into account the arrival direction of the trajectory striking the sectioning plane.