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

In summary, the conversation is about using Mathematica to generate a Poincare section of a system of ODE's. The code provided involves using NDSolve and EventHandler, but the latter is limited for the given conditions. The idea of using a different programming language, such as Fortran, is suggested. Additional code is also provided for generating Poincare sections in the xy plane.
  • #1
keenPenguin
21
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
  • #2
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,850
  • lorenz flow.jpg
    lorenz flow.jpg
    6 KB · Views: 962
Last edited:
  • #4
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}]
 
  • #5
.I understand the frustration of encountering limitations in tools that we use for our research. In this case, it seems like Mathematica's EventHandler function may not be the best option for your specific task of computing points for a Poincaré section. While Mathematica is a powerful tool for many scientific applications, it may not always be the best choice for every task.

I would suggest exploring other software options that may better suit your needs. For example, there are specific programs designed for analyzing dynamical systems and generating Poincaré sections, such as XPPAUT or AUTO. These programs are specifically designed for handling the types of calculations and conditions you are describing, and may be a better fit for your task than trying to work around the limitations of Mathematica.

Alternatively, if you are comfortable with Fortran, you could certainly write your own code to handle the task. This may require more effort and time, but it would allow you to have complete control over the calculations and conditions without any limitations imposed by a specific software program.

In conclusion, while Mathematica may be a useful tool for many scientific applications, it may not always be the best choice for every task. It is important to explore different options and choose the best tool for the specific task at hand. I hope this helps and wish you success in your research.
 

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

1. What is Mathematica and how is it used for Poincaré sections?

Mathematica is a powerful computational software program that is commonly used by scientists and mathematicians for data analysis, visualization, and modeling. It has built-in functions and tools that make it ideal for creating Poincaré sections, which are graphical representations of the behavior of a dynamical system over time.

2. Can Mathematica be used for any type of Poincaré section?

Yes, Mathematica has the capabilities to create Poincaré sections for any type of dynamical system, including non-linear and chaotic systems. It also allows for customization of the parameters and variables used in the Poincaré section, making it a versatile tool for analysis.

3. What are the benefits of using Mathematica for Poincaré sections?

One of the main benefits of using Mathematica for Poincaré sections is its efficiency and accuracy. Its built-in algorithms and functions allow for quick and precise calculations, making it ideal for analyzing complex systems. Additionally, Mathematica has a user-friendly interface and a variety of visualization options, making it easy to interpret and present the results of Poincaré sections.

4. Are there any tutorials or resources available for using Mathematica for Poincaré sections?

Yes, there are many online tutorials and resources available for using Mathematica for Poincaré sections. Wolfram Research, the company behind Mathematica, offers a comprehensive online tutorial and a dedicated support team for any questions or issues that may arise. There are also many user-created tutorials and forums where users can share tips and techniques for using Mathematica for Poincaré sections.

5. Can Mathematica be used for other types of data analysis besides Poincaré sections?

Yes, Mathematica has a wide range of capabilities for data analysis, including statistical analysis, machine learning, and image processing. It can also be used for creating dynamic models and simulations, making it a versatile tool for various scientific and mathematical applications.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
11
Views
16K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
7K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Back
Top