# How to build a Poincaré section for a 6th order system?

**URL:** <https://discourse.julialang.org/t/how-to-build-a-poincare-section-for-a-6th-order-system/77694>\
**Category:** General Usage\
**Created:** [March 10, 2022, 3:45pm UTC](https://discourse.julialang.org/t/how-to-build-a-poincare-section-for-a-6th-order-system/77694 "2022-03-10T15:45:19Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![egor](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@egor](https://discourse.julialang.org/u/egor)\
**Post date:** [March 10, 2022, 3:45pm UTC](https://discourse.julialang.org/t/how-to-build-a-poincare-section-for-a-6th-order-system/77694/1 "2022-03-10T15:45:19Z")

</div>

Hello everyone, I want to plot the Poincaré section for the system:

![FireShot Capture 001 - VNM poster (1.0) - Online LaTeX Editor Overleaf - www.overleaf.com](https://global.discourse-cdn.com/julialang/original/3X/9/f/9f1b7fb6d22d04290e3de39c231f57fb17b00612.png)

Following the example of [this tutorial](https://juliadynamics.github.io/DynamicalSystems.jl/dev/chaos/orbitdiagram/#Advanced-hyperplane), I wrote the following code:

```julia
plane = (3, 0.0)

fig = Figure(resolution = (600,300))
axx = Axis(fig[1,1]; xlabel = L"x_1", ylabel = L"x_2")
axy = Axis(fig[1,2]; xlabel = L"y_1", ylabel = L"y_2")
for i in 1:100
    rng = MersenneTwister(i);
    u0 = randn!(rng, zeros(6))
    psos = poincaresos(hr, plane, 20000.0; u0 = u0)
    scatter!(axx, psos[:, 1], psos[:, 4]; marketsize = 2.0)
    scatter!(axy, psos[:, 2], psos[:, 5]; marketsize = 2.0)
end

fig

```

And the same for plane = (6, 0.0). But I want to get a cross section when both the third variable (h\_1) and the sixth variable (h\_2) are zero at the same time.

Can I do it somehow? I tried to draw a plane through 2 six-dimensional points as in the example, but in this case the cross() function does not work.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 10, 2022, 6:33pm UTC](https://discourse.julialang.org/t/how-to-build-a-poincare-section-for-a-6th-order-system/77694/2 "2022-03-10T18:33:11Z")

</div>

Share your whole code.

---

<div class="post-metadata">

**Author:** ![egor](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@egor](https://discourse.julialang.org/u/egor)\
**Post date:** [March 14, 2022, 11:54am UTC](https://discourse.julialang.org/t/how-to-build-a-poincare-section-for-a-6th-order-system/77694/4 "2022-03-14T11:54:18Z")

</div>

[Here is my code](https://github.com/SemenutaEgor/Extreme-events-in-phenomenological-neural-networks-with-different-types-of-connections/blob/master/poincare_2hr.ipynb)

---

<div class="post-metadata">

**Author:** ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)\
**Post date:** [March 14, 2022, 1:37pm UTC](https://discourse.julialang.org/t/how-to-build-a-poincare-section-for-a-6th-order-system/77694/5 "2022-03-14T13:37:19Z")

</div>

An easy way to do this is with polynomial interpolation. If your Poincare section is defined as h(x) = 0, integrate until h(x) changes sign. Then, for an nth-order integration scheme, make an nth-order polynomial interpolant of each the component of x as a function of h values, and interpolate to h=0.

If you use the `Polynomial.jl` package you can do this in a few lines of code. It’ll be allocating, and maybe there’ll be some cost to tracking h(x). Probably `DifferentialEquations.jl` has a slcik and efficient method.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [March 14, 2022, 2:06pm UTC](https://discourse.julialang.org/t/how-to-build-a-poincare-section-for-a-6th-order-system/77694/6 "2022-03-14T14:06:08Z")

</div>

> [@John\_Gibson](#):
>
> If you use the `Polynomial.jl` package you can do this in a few lines of code. It’ll be allocating, and maybe there’ll be some cost to tracking h(x). Probably `DifferentialEquations.jl` has a slcik and efficient method.

You just make it a ContinuousCallback with the `h(x)` as the condition function.

---

<div class="post-metadata">

**Author:** ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)\
**Post date:** [March 14, 2022, 3:00pm UTC](https://discourse.julialang.org/t/how-to-build-a-poincare-section-for-a-6th-order-system/77694/7 "2022-03-14T15:00:25Z")

</div>

Something I didn’t understand from your first post was the goal of finding a Poincare section satisfying _two_ conditions, `h1(x) = 0` and `h2(x) = 0`. In general there’s no reason to expect that with only one independent variable (time `t`) you’ll be able to find points `x(t)` that satisfy two conditions simultaneously.

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [March 14, 2022, 7:42pm UTC](https://discourse.julialang.org/t/how-to-build-a-poincare-section-for-a-6th-order-system/77694/8 "2022-03-14T19:42:20Z")

</div>

By definition, a Poincare section for the flow associated to a system of n first order differential equations is a (n-1)-dimensional surface (usually a hyperplane in `R^n`), that is transversal to the flow.  
To choose a right Poincare section, not just a hyperplane of equation x\_i =0 (or y\_i=0 or zi\_0) you should associate the 6d vector field,  
V(x\_1, x\_2, y\_1, y\_2, z\_1, z2), having as coordinates the right-hand sides of your system.

The general equation of a hyperplane in `R^6` is Ax\_1+B\_x\_2+Cy\_1+Dy\_2+Ez\_1+Fz\_2+G=0, and its normal is the vector, N, of coordinates [A, B, C, D, E, F]. If the dot product  
of the vector field V and the normal, N, is nonzero  
at any point of the hyperplane, ` <V(x_1, x_2, y_1, y_2, z_1, z_2), N> \neq 0`, then that hyperplane is a right choice as a Poincare section.  
Hence assigning particular values to A,B, C, D, E, F, you should find a Poincare section, if any.
