Greetings. I’m trying to solve a problem of plotting a Poincare map for the Henon Heiles’s system. But the figure is completely painted over, but should have cavities. Maybe I’m using the Julia commands incorrectly somehow. Thank you in advance.
using DifferentialEquations, CairoMakie, LaTeXStrings, Symbolics
E=4e-2
T=1e2
tspan=(0,T)
f = Figure()
ax = Axis(f[1, 1],
title = L"H=\frac{1}{2}(p_1^2+p_2^2)+\frac{1}{2}(q_1^2+q_2^2)+q_1^2 q_2 -\frac{1}{3}q_2^3",
subtitle=latexstring("E=$E"),
xlabel = L"q_2",
ylabel = L"p_2",
)
function henon(du,u,p,t)
du[1]=u[3]
du[2]=u[4]
du[3]=-(u[1]+2*u[1]*u[2])
du[4]=-u[2]-u[1]^2+u[2]^2
end
q10=0
for q20 in -0.5:1e-2:0.5
for p20 in -0.4:1e-2:0.4
if (2*E-p20^2-(q10^2+q20^2)-2*(q10^2*q20)+(2/3)*q20^3)>0
u0=[q10,q20,sqrt(2*E-p20^2-(q10^2+q20^2)-2*(q10^2*q20)+(2/3)*q20^3),p20]
prob=ODEProblem(henon,u0,tspan)
sol=solve(prob,RK4())
# scatter!(axe,sol[1,:],(sol[3,:].^2+sol[4,:].^2)./2+(sol[1,:].^2+sol[2,:].^2)./2+(sol[1,:].^2).*sol[2,:]-(sol[2,:].^3)./3)
#Q1=sol[1,:]; Q2=sol[2,:]; P1=sol[3,:]; P2=sol[4,:]
for i in 1:(length(sol[:])-1)
if (sol[1,i]<0) && (sol[1,i+1])>0
scatter!(ax, (sol[2,i]+sol[2,i+1])/2, (sol[4,i]+sol[4,i+1])/2,color=:blue, markersize=4)
end
end
end
end
end
f
UPD1: For T=1e4 and q20,p20 variables range -0.5:1e-1:-0.5 it turns out to be something right. But Dataseris’s figure(see below) is much more attractive.