I'm in the desire to plot the Poincare Section of a differential equation defined by a Hamiltonian system. The Hamiltonian is as follows:
H[x_,a_,y_,b_] = (a^2+b^2)/2+f*y+(1-f-Sqrt[x^2+(1-y)^2])/2
Here x and y and generalized coordinates and a, b their respective momentum. In case you are curious, this is the Hamiltonian of a spring pendulum.
In my case, to evaluate numeric, I set f = 0.2 and H = 0.03. And after applying Hamilton equations, I have:
x''[t] = x[t]/(2*Sqrt[x^2 + (1 - y)^2])
y''[t] = -0.2 - (1 - y[t])/Sqrt[x^2 + (1 - y)^2]
while x'[t] = a[t] and y'[t] = b[t].
Now, I want to plot the Poincare Map/Section for y[t] = 0 and b[t] > 0. How am I supposed to do it? I have tried using this and this with no success. An expected graph can be seen at these 2 links: one, two.
EDIT: Following this help to plot Poincaré section for double pendulum question, I basically tried changing this to my problem. Here is my code:
equations = {x'[t] == px[t],
y'[t] == py[t],
px'[t] == x[t]/(2*Sqrt[x[t]^2 + (1 - y[t])^2]),
py'[t] == -0.2 - (1 - y[t])/Sqrt[x[t]^2 + (1 - y[t])^2]};
psect[{x0_, px0_, y0_, py0_}] :=
Reap[NDSolve[{equations, x[0] == x0, px[0] == px0, y[0] == y0,
py[0] == py0, WhenEvent[y[t] + 0x[t] + 0px[t] + 0*py[t] == 0,
If[py[t] > 0,
Sow[{px[t], x[t]}]]]}, {x, px, y, py}, {t, 0, 200},
MaxSteps -> [Infinity], MaxStepSize -> .0005]][[2, 1]];
ps = psect /@ Table[{0.01, 0.005, 0.01, i}, {i, -0.01, .01, 0.00125}]
ListLinePlot[#[[FindCurvePath[#][[1]]]] & /@ ps,
Mesh -> All, PlotRange -> All]
I got some errors at the ps and plot part:
ps = psect /@ Table[{0.01, 0.005, 0.01, i}, {i, -0.01, .01, 0.00125}]
Part::partw: Part 1 of {} does not exist. >> Part::partw: Part 1 of {} does not exist. >> Part::partw: Part 1 of {} does not exist. >> General::stop: Further output of Part::partw will be suppressed during this calculation. >>
ListLinePlot[#[[FindCurvePath[#][[1]]]] & /@ ps, Mesh -> All,
PlotRange -> All]
Part::pkspec1: The expression <<1>> cannot be used as a part specification. >> Part::pkspec1: The expression <<1>> cannot be used as a part specification. >> Part::pkspec1: The expression <<1>> cannot be used as a part specification. >> General::stop: Further output of Part::pkspec1 will be suppressed during this calculation. >>
How can I work this around?


