2
$\begingroup$

I am solving a set of differential equations with symplecticpartitioned runge kutta method. After checking my code for a long time, I found the example code in the tutorial of Mathematica also has a similar issue.

As shown in the figure, no matter what's the order of the differential equations, I always need to use $q_1$, $q_2$, $q_3$ as the position variables. If I change them to $q_3$, $q_2$, $q_1$, then the results diverge. Thanks.(sorry for the format of the code. But it works when it is copied to Mathematica.)

eqns = {{Derivative[1][Subscript[q, 3]][t] == Subscript[p, 3][t], 
Derivative[1][Subscript[q, 1]][t] == Subscript[p, 1][t], 
Derivative[1][Subscript[q, 2]][t] == Subscript[p, 2][t], 
Derivative[1][Subscript[p, 3]][t] == 
 E^(Subscript[q, 1][t] - Subscript[q, 3][t]) - 
  E^(-Subscript[q, 2][t] + Subscript[q, 3][t]), 
Derivative[1][Subscript[p, 1]][t] == 
 E^(-Subscript[q, 1][t] + Subscript[q, 2][t]) - 
  E^(Subscript[q, 1][t] - Subscript[q, 3][t]), 
Derivative[1][Subscript[p, 2]][
  t] == -E^(-Subscript[q, 1][t] + Subscript[q, 2][t]) + 
  E^(-Subscript[q, 2][t] + Subscript[q, 3][t])}, {Subscript[q, 1][
  0] == 1, Subscript[q, 3][0] == 4, Subscript[q, 2][0] == 2, 
Subscript[p, 1][0] == 0, Subscript[p, 3][0] == 1/2, 
Subscript[p, 2][0] == 1}};
  vars = {Subscript[q, 1][t], Subscript[q, 3][t], Subscript[q, 2][t], Subscript[p, 1][t], Subscript[p, 3][t], Subscript[p, 2][t]}; 
time = {t, 0, 50}; 
sprksol = NDSolve[eqns, vars, time, Method -> {"SymplecticPartitionedRungeKutta", DifferenceOrder -> 2, 
      "PositionVariables" -> {Subscript[q, 1][t], Subscript[q, 2][t], Subscript[q, 3][t]}}, StartingStepSize -> 1/10]; 
p5 = Plot[Evaluate[Subscript[q, 1][t] /. sprksol], {t, 0, 50}, PlotRange -> {{0, 5}, {-3, 10}}, PlotStyle -> {Blue, Blue}, AxesLabel -> "q1"]; 
p6 = Plot[Evaluate[Subscript[q, 3][t] /. sprksol], {t, 0, 50}, PlotRange -> {{0, 5}, {-3, 10}}, PlotStyle -> {Blue, Blue}, AxesLabel -> "q3"]; 
p7 = Plot[Evaluate[Subscript[q, 2][t] /. sprksol], {t, 0, 50}, PlotRange -> {{0, 5}, {-3, 10}}, PlotStyle -> {Blue, Blue}, AxesLabel -> "q2"]; 
GraphicsGrid[{{p5, p6, p7}}]

Why the order of the position variables in the red box cannot be changed?

$\endgroup$
  • $\begingroup$ The former version did not work. Note that it has to be Derivative[1], not Derivative[[1]]... $\endgroup$ – Henrik Schumacher Nov 28 '17 at 7:19
  • 1
    $\begingroup$ Update: Wolfram technician has verified this issue with Mathematica 11.1.1 on either Mac or Linux. It works on Windows with 11.1.1. They confirmed that the issue is fixed in 11.2.0 on all platforms. $\endgroup$ – kanex_wu Dec 1 '17 at 4:13
  • $\begingroup$ This is for the 3-particle Toda lattice or variants thereof? Anyways, I tried using this method but the integration times are terrible compared. Can you link to Mma tutorial? $\endgroup$ – ZeroTheHero Nov 11 '18 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.