Mathematica for Poincaré sections - or maybe a different tool?

  • Context: Mathematica 
  • Thread starter Thread starter keenPenguin
  • Start date Start date
  • Tags Tags
    Mathematica Poincare
Click For Summary

Discussion Overview

The discussion revolves around the challenges of computing Poincaré sections using Mathematica, particularly focusing on the limitations of the EventHandler and EventLocator functions in handling specific conditions for integration. Participants explore alternative approaches, including the potential use of other programming languages like Fortran.

Discussion Character

  • Technical explanation
  • Exploratory
  • Debate/contested

Main Points Raised

  • One participant describes difficulties in using EventHandler for a Poincaré map that requires both counting iterations and aborting integration after a certain condition is met.
  • Another participant provides a code example for generating a Lorenz attractor and constructing a Poincaré map, noting its complexity and suggesting running it in Mathematica for better understanding.
  • Links to external demonstrations of Poincaré sections are shared, allowing others to view and download relevant code.
  • A participant expresses success with existing code but encounters issues when attempting to modify it to analyze intersections in the xy plane instead of the original conditions.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach to compute Poincaré sections, with multiple competing views on the effectiveness of Mathematica versus other programming languages and methods. The discussion remains unresolved regarding the optimal solution.

Contextual Notes

Participants highlight limitations in the current Mathematica functions, particularly in handling nested conditions and counters, which may affect the implementation of their proposed solutions.

keenPenguin
Messages
20
Reaction score
3
Hi,

I have a system of ODE's for which I want to compute points for a Poincaré section. I used NDSolve and EventHandler in Mathematica but EventHandler appears rather messy/limited for my condition: Suppose I want to save 4 iterations of a Poincaré map and then abort integration imediately. It's an ugly task in Mathematica because one EventHandler condition is, say, psi mod 2pi = 0 while the other is "abort integration when the first condition has been met 4 times". The latter condition is hard to do using EventHandler because it refers to the first condition (so I have to introduce a counter in the first condition...)

Do you know any solution?

Maybe it's a good idea to leave Mathematica at this point and write the whole thing in a language capable of handling loops ;-) I would use Fortran probably.

EDIT: Sorry, by EventHandler I always mean EventLocator
 
Physics news on Phys.org
You good with Mathematica programming? Here's code to generate the Lorenz attractor and then construct the Poincare map representing where the flow passes through the manifold x[t]==0 shown as the light-red plane in the plot below. It's kinda messy. You may wish to cut and paste the code into your Mathematica and then run it to see what it looks like. In the first plot below, the Poincare section is superimposed onto the attractor. The second plot is the actual Poincare section but you should run it in Mathematica so you can rotate it interactively (ver 6 or better).

Code:
mysol = NDSolve[{x'[t] == -3 (x[t] - y[t]), 
   y'[t] == -x[t] z[t] + 26.5 x[t] - y[t], z'[t] == x[t] y[t] - z[t], 
   x[0] == z[0] == 0, y[0] == 1}, {x, y, z}, {t, 0, 200}, 
  MaxSteps -> 100000]

myx[t_] := Evaluate[x[t] /. mysol];

myplot = Plot[myx[t], {t, 0, 200}]

pp1 = ParametricPlot3D[
  Evaluate[{x[t], y[t], z[t]} /. mysol], {t, 0, 200}, 
  AxesLabel -> {"x", "y", "z"}, PlotPoints -> 150]
cp1 = ContourPlot3D[x == 0, {x, -20, 20}, {y, -20, 20}, {z, 0, 50}, 
  Mesh -> None, ContourStyle -> {LightPurple, Opacity[0.4]}]

(* get line segments from plot *)
pts = Cases[myplot, Line[{t__}] -> t, \[Infinity]];

(* from set above, select all pairs which exhibit a sign change to \
identify a root *)
myselection = 
  Select[Split[pts, Sign[Last[#2]] == -Sign[Last[#1]] &], 
   Length[#1] == 2 &];

(* get first element of the array *)
mymap = Map[First, myselection, {2}];

(* find in line segments where each changes sign *)
mymap2 = Map[FindRoot[myx[t] == 0, {t, #[[1]], #[[2]]}] &, mymap];
mypoints = t /. mymap2;

(* plot Poincare map  where x[t]=0 *)
myplots = 
  Point@ {First[Evaluate[x[#] /. mysol]], 
      First[Evaluate[y[#] /. mysol]], 
      First[Evaluate[z[#] /. mysol]]} & /@ mypoints;
sg1 = Show[Graphics3D[{Red, PointSize[0.008], myplots}]]

(* show everything *)
Show[{pp1, cp1, sg1}]
 

Attachments

  • poincare map.jpg
    poincare map.jpg
    37.3 KB · Views: 1,971
  • lorenz flow.jpg
    lorenz flow.jpg
    6 KB · Views: 1,038
Last edited:
The below code works great. However, I can't seem to change it, to look at the intersection in the xy plane. I changed myx, myplot and cp1 (to look where z=27) and those work there is something down the line that i am not changing correctly. Any pointers


jackmell said:
You good with Mathematica programming? Here's code to generate the Lorenz attractor and then construct the Poincare map representing where the flow passes through the manifold x[t]==0 shown as the light-red plane in the plot below. It's kinda messy. You may wish to cut and paste the code into your Mathematica and then run it to see what it looks like. In the first plot below, the Poincare section is superimposed onto the attractor. The second plot is the actual Poincare section but you should run it in Mathematica so you can rotate it interactively (ver 6 or better).

Code:
mysol = NDSolve[{x'[t] == -3 (x[t] - y[t]), 
   y'[t] == -x[t] z[t] + 26.5 x[t] - y[t], z'[t] == x[t] y[t] - z[t], 
   x[0] == z[0] == 0, y[0] == 1}, {x, y, z}, {t, 0, 200}, 
  MaxSteps -> 100000]

myx[t_] := Evaluate[x[t] /. mysol];

myplot = Plot[myx[t], {t, 0, 200}]

pp1 = ParametricPlot3D[
  Evaluate[{x[t], y[t], z[t]} /. mysol], {t, 0, 200}, 
  AxesLabel -> {"x", "y", "z"}, PlotPoints -> 150]
cp1 = ContourPlot3D[x == 0, {x, -20, 20}, {y, -20, 20}, {z, 0, 50}, 
  Mesh -> None, ContourStyle -> {LightPurple, Opacity[0.4]}]

(* get line segments from plot *)
pts = Cases[myplot, Line[{t__}] -> t, \[Infinity]];

(* from set above, select all pairs which exhibit a sign change to \
identify a root *)
myselection = 
  Select[Split[pts, Sign[Last[#2]] == -Sign[Last[#1]] &], 
   Length[#1] == 2 &];

(* get first element of the array *)
mymap = Map[First, myselection, {2}];

(* find in line segments where each changes sign *)
mymap2 = Map[FindRoot[myx[t] == 0, {t, #[[1]], #[[2]]}] &, mymap];
mypoints = t /. mymap2;

(* plot Poincare map  where x[t]=0 *)
myplots = 
  Point@ {First[Evaluate[x[#] /. mysol]], 
      First[Evaluate[y[#] /. mysol]], 
      First[Evaluate[z[#] /. mysol]]} & /@ mypoints;
sg1 = Show[Graphics3D[{Red, PointSize[0.008], myplots}]]

(* show everything *)
Show[{pp1, cp1, sg1}]
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
6K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 11 ·
Replies
11
Views
17K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 3 ·
Replies
3
Views
7K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K