I am using Mathematica to simulate a simple pendulum. I used the Animate command to create an animation of the pendulum, which runs smootly. But when i run any other Manipulate, Animate or ListAnimate command simultaneously to the first one, both of them become very laggy. My intention was to create a plot that traced the angular displacement of the pendulum at each moment. What i noticed is that this happens also if I run a very simple Manipulate command, even only a slider. What I also noticed is that if I run the two animations on separate Notebooks, they run perfectly, which shows that the problem is not my hardware. Does anyone know why this happens? Thanks in advance.
This is the pendulum animation, which runs smoothly.
Animate[
Graphics[{},
(*Epilog*)
Epilog -> {
Thickness[0.025], RGBColor[0.38, 0.38, 0.38],
Line[{{0, 0}, {l*Sin[sol1[a]], -l*Cos[sol1[a]]}}],
RGBColor[0., 0.29, 0.22], EdgeForm[{Thickness[Medium], Black}],
Disk[{l*Sin[sol1[a]], -l*Cos[sol1[a]]}, 0.07 l],
White, EdgeForm[{Thin, Black}], Disk[{0, 0}, 0.017 l]
},
(*Graphics options*)
PlotRange -> {{-l - 0.405 l, l + 0.405 l}, {-l - 0.35 l,
Which[absmax1 < \[Pi]/2, 0.3 l, \[Pi]/2 < absmax1 < \[Pi],
l Sin[absmax1 - \[Pi]/2] + 0.1 l, absmax1 > \[Pi], l + 0.2 l]}},
Axes -> True,
AxesStyle -> Arrowheads[Automatic],
LabelStyle -> {15, Black, FontFamily -> "Kalam Light", Bold},
AxesOrigin -> {0, 0},
ImageSize -> 600,
Frame -> False
],
(*Animate options*)
{a, 0, 60, Appearance -> "Labeled"},
RefreshRate -> 144,
DefaultDuration -> 60,
AnimationRunning -> False
]
This is the second one, which I noticed lags even on its own, I was trying to figure out a way to make it run smoothly, maybe using Dynamics or other methods. ListAnimate works but it takes way too much to execute. I just started using Mathemathica so I am not familiar with it.
Animate[
Plot[{sol1[t]}, {t, 10^-10, a},
(*Plot options*)
ImageSize -> 1000,
PlotRange -> {{0, 60}, {min1, max1}},
Axes -> True,
AxesStyle -> Arrowheads[0.02, 0.02],
AxesLabel -> {"t", "\[Theta](t)"},
AxesOrigin -> {0, 0},
LabelStyle -> {18, Black, FontFamily -> "Kalam Light", Bold},
Ticks -> {Automatic,
Which[absmax1 >= 11 \[Pi], Range[-60 \[Pi], 60 \[Pi], 2 \[Pi]],
15.6 <= absmax1 < 11 \[Pi], Range[-60 \[Pi], 60 \[Pi], \[Pi]],
8.3 <= absmax1 < 15.6, Range[-60 \[Pi], 60 \[Pi], \[Pi]/2],
2 <= absmax1 < 8.3, Range[-60 \[Pi], 60 \[Pi], \[Pi]/4],
absmax1 < 2, Range[-20 \[Pi], 20 \[Pi], \[Pi]/8]]},
TicksStyle ->
Directive[Black, FontFamily -> "Kalam Light", 14, Bold],
GridLines -> {Automatic,
Which[absmax1 > 11 \[Pi], Range[-60 \[Pi], 60 \[Pi], 2 \[Pi]],
15.6 < absmax1 < 11 \[Pi], Range[-60 \[Pi], 60 \[Pi], \[Pi]],
8.3 < absmax1 < 15.6, Range[-60 \[Pi], 60 \[Pi], \[Pi]/2],
2 < absmax1 < 8.3, Range[-60 \[Pi], 60 \[Pi], \[Pi]/4],
absmax1 < 2, Range[-20 \[Pi], 20 \[Pi], \[Pi]/8]]},
GridLinesStyle -> Directive[Dashed, LightGray],
PlotLabel ->
Style[Framed["Angular displacement"], FontFamily -> "Kalam Light",
15]
],
(*Animate options*)
{a, 0, 60},
Paneled -> False,
AnimationRunning -> False
]
This is the setup code I used.
(*Initial conditions*)
mu := 0.1
cd1 := y[0] == 1
cd2 := y'[0] == 1
l := 8
g := 9.81
(*Differential equation*)
eq = y''[t] == -mu*y'[t] - (g/l)*Sin[y[t]];
sol1 = NDSolveValue[{eq, cd1, cd2}, y, {t, 0, 200}];
max1 = NMaxValue[{sol1[t], 0 < t < 60}, t, Method -> "NelderMead"];
min1 = NMinValue[{sol1[t], 0 < t < 60}, t, Method -> "NelderMead"];
absmax1 = Max[Abs[max1], Abs[min1]];
sol2 = NDSolveValue[{eq, cd1, cd2}, y', {t, 0, 200}];