Mathematica Asked by dbx on July 14, 2021
I’ve found two other similar questions:
Plot of the Mod of NDSolve solutions sometimes connects discontinuous jumps
and
How can I remove horizontal lines on a phase plot for a pendulum?
Neither contains a solution to my problem, but in an answer to the first there is a tantalizing note: This seems to have been fixed in V11. Alas I’m running V11 and getting a very similar issue that I would love to get rid of. Here’s my code:
Manipulate[
Animate[sol =
NDSolve[{x'[t] == w1 + k1*Sin[y[t] - x[t]],
y'[t] == w2 + k2*Sin[x[t] - y[t]], x[0] == x0, y[0] == y0}, {x,
y}, {t, 0, tmax}];
ParametricPlot[Mod[{x[t], y[t]} /. sol, 2 Pi], {t, 0, tplot},
PlotRange -> {{0, 2 Pi}, {0, 2 Pi}}], {tplot, 0, tmax}],
{{w1, 1}, -2, 2}, {{w2, 1}, -2, 2}, {{k1, 0.1}, 0, 2}, {{k2, 0.1}, 0,
2}, {{x0, 0}, 0, 2 Pi}, {{y0, 0.2}, 0, 2 Pi}, {{tmax, 10}, 0, 100}
]
This is a simple coupled oscillator problem; the phase space is naturally the torus, i.e. the square with opposite edges identified. The obvious way to plot the solution then is Mod[], but we get the following:
The horizontal and vertical line shouldn’t be there. I understand why they’re added by ParametricPlot but I would like to get rid of them. I have tried using Exclusions; I have tried using WhenEvent within the NDSolve to reset x and y to zero so that the Mod[] is unnecessary and I get exactly the same output. Surely there’s a solution? Perhaps ParametricPlot can be told to ignore jumps greater than $varepsilon$? I don’t need it to be perfect.
Manipulate[Animate[sol = NDSolveValue[{x'[t] == w1 + k1*Sin[y[t] - x[t]],
y'[t] == w2 + k2*Sin[x[t] - y[t]], x[0] == x0, y[0] == y0}, {x, y}, {t, 0, tmax}];
ParametricPlot[Mod[Through@sol@t, 2 Pi], {t, 0, tplot},
PlotRange -> {{0, 2 Pi}, {0, 2 Pi}}, PerformanceGoal -> "Quality",
ImageSize -> 300], {tplot, 0, tmax}, Alignment -> Center],
{{w1, 1}, -2, 2}, {{w2, 1}, -2, 2}, {{k1, 0.1}, 0, 2}, {{k2, 0.1}, 0, 2},
{{x0, 0}, 0, 2 Pi}, {{y0, 0.2}, 0, 2 Pi}, {{tmax, 10}, 0, 100},
Alignment -> Center, ContentSize -> 500]
Update: You can also use:
Manipulate[Animate[sol = NDSolve[{x'[t] == w1 + k1*Sin[y[t] - x[t]],
y'[t] == w2 + k2*Sin[x[t] - y[t]], x[0] == x0, y[0] == y0}, {x, y}, {t, 0, tmax}];
m[t_] := Mod[{x[t], y[t]} /. sol, 2 Pi];
ParametricPlot[m[t], {t, 0, tplot}, PlotRange -> {{0, 2 Pi}, {0, 2 Pi}},
PerformanceGoal -> "Quality"], {tplot, 0, tmax}],
{{w1, 1}, -2, 2}, {{w2, 1}, -2, 2}, {{k1, 0.1}, 0, 2}, {{k2, 0.1}, 0, 2},
{{x0, 0}, 0, 2 Pi}, {{y0, 0.2}, 0, 2 Pi}, {{tmax, 10}, 0, 100}]
Correct answer by kglr on July 14, 2021
As a workaround you can use ListPlot
instead of ParametricPlot
Manipulate[
sol = NDSolve[{x'[t] == w1 + k1*Sin[y[t] - x[t]],
y'[t] == w2 + k2*Sin[x[t] - y[t]], x[0] == x0, y[0] == y0}, {x,
y}, {t, 0, tmax}]; Animate[
ListPlot[
Table[Mod[{x[t], y[t]} /. sol, 2 Pi], {t, 0, tplot, 0.05}],
PlotRange -> {{0, 2 Pi}, {0, 2 Pi}},
PlotStyle -> {Blue, PointSize[Tiny]}],
{tplot, 0, tmax}], {{w1, 1}, -2, 2}, {{w2, 1}, -2, 2}, {{k1, 0.1},
0, 2}, {{k2, 0.1}, 0, 2}, {{x0, 0}, 0, 2 Pi}, {{y0, 0.2}, 0,
2 Pi}, {{tmax, 10}, 0, 100}]
Answered by ulvi on July 14, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP