Skip to main content
1 of 5
Vitaliy Kaurov
  • 73.4k
  • 9
  • 206
  • 365

Put independent events in List when you need a few of them. Then to separate while Sow/Reap - use tags in Sow - for example for 2 different events:

data = Block[{δ = 0.15, γ = 0.3}, 
   Reap[NDSolve[{x''[t] + δ x'[t] - x[t] + 
        x[t]^3 == γ Cos[ t], x[0] == 0, x'[0] == 0, 
      WhenEvent[{Mod[t, 2 π] == 0, Mod[t, 2 π] == Pi}, 
       Sow[{x[t], x'[t]}, Round@Mod[t, 2 π]]]}, {}, {t, 0, 
      100000}, MaxSteps -> ∞]]];

ListPlot[data[[2]], ImageSize -> Medium, 
 PlotRange -> {{-1.5, 1.5}, All}, PlotStyle -> PointSize[0.0025]]

enter image description here

Vitaliy Kaurov
  • 73.4k
  • 9
  • 206
  • 365