0
$\begingroup$

I am trying to solve a particular system using NDsolve and specifically the leapfrog method. I have gotten NDsolve to work using NDsolve withoiut specifying a method. I tried reading the documentation on splitting methods for NDsolve but it seems I don't understand enough of it.

From my understanding NDSolve does not have a leapfrog option so we have to "code" it in using the existing options like what is done here:https://reference.wolfram.com/language/tutorial/NDSolveSplitting.html

This is my code, which doesn't work (errors NDSolve::spltdim, NDSolve::initf):

c1 = 3
k1 = -1
w = 1
x0 = -0.1
y0 = 0
u = 0
H = -0.1
v = 0.681507026554037
eq1 = x''[t] == (0.5 k1) ((((x[t]^2 + y[t]^2)^2 + 
          2 (c1) (x[t]^2 - y[t]^2) + (c1^2))^(-1.5)) (4 (x[t]^2 + 
           y[t]^2) x[t] + 4 x[t] (c1))) + 2 w y'[t]
eq2 = y''[t] == (0.5 k1) ((((x[t]^2 + y[t]^2)^2 + 
          2 (c1) (x[t]^2 - y[t]^2) + (c1^2))^(-1.5)) (4 (x[t]^2 + 
           y[t]^2) y[t] - 4 y[t] (c1))) - 2 w x'[t]
sol1 = NDSolve[{eq1, eq2, x[0] == x0, y[0] == y0, x'[0] == u, 
   y'[0] == v}, {x[t], y[t], x'[t], y'[t]}, {t, 0, 120}, 
  StartingStepSize -> 1/10, 
  Method -> {"Splitting", "DifferenceOrder" -> 2, 
    "Equations" -> {x[t], y[t], x'[t], y'[t]}, 
    "Method" -> {"ExplicitEuler"}}]

The following doesn't work either (errors NDSolve::sprkpqv, NDSolve::initf):

SymplecticLeapfrog = {"SymplecticPartitionedRungeKutta", 
  "DifferenceOrder" -> 2, "PositionVariables" :> qvars}; time = {t, 0,
   120};
qvars = {x[t], y[t], x'[t], y'[t]};
sol1 = NDSolve[{eq1, eq2, x[0] == x0, y[0] == y0, x'[0] == u, 
     y'[0] == v}, {x[t], y[t], x'[t], y'[t]}, {t, 0, 120}, 
    StartingStepSize -> 1/10, 
    Method -> SymplecticLeapfrog]; // AbsoluteTiming
$\endgroup$
9
  • $\begingroup$ Related: mathematica.stackexchange.com/a/274544/1871 $\endgroup$
    – xzczd
    Commented Jun 2, 2023 at 14:43
  • $\begingroup$ From your link SymplecticLeapfrog = {"SymplecticPartitionedRungeKutta", "DifferenceOrder" -> 2, "PositionVariables" :> qvars};. Another options is NDSolvePlugIns $\endgroup$
    – I.M.
    Commented Jun 2, 2023 at 16:35
  • $\begingroup$ @I.M. trying it out this way still seems to not work, I have included the edited code $\endgroup$ Commented Jun 4, 2023 at 15:09
  • $\begingroup$ Syntax error: qvars = {x[t], y[t], x'[t], y'[t]};. It would also be nice if semicolons where at the ends of the parameter assignments. Their output is unnecessary. $\endgroup$
    – Michael E2
    Commented Jun 4, 2023 at 15:24
  • $\begingroup$ Note that for the method "Splitting", the documentation seems to imply the problem must be cast in a first-order autonomous form $u'=F(u)$, where $u$ would be the vector $(x,y,x',y')$ in this case. OTOH "Splitting" does not complain about second-order ODEs, which leaves open the possibility that it does handle higher-order equations. But I think not.... $\endgroup$
    – Michael E2
    Commented Jun 4, 2023 at 19:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.