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
SymplecticLeapfrog = {"SymplecticPartitionedRungeKutta", "DifferenceOrder" -> 2, "PositionVariables" :> qvars};
. Another options is NDSolvePlugIns $\endgroup$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$