2
$\begingroup$

I'm trying to model an animated wave with Animate. I put it inside a Manipulate to easily change the values of the amplitude, wavelength and velocity. Currently Animate runs over 10 sec and then repeats. But depending on the variable settings the wave may not be at the same place after those 10 sec and when Animate repeats you can see the cut, like in a poorly animated GIF. How can I set it so that Animate only restarts after the wave completed one whole oscillation?

Here is my code:

Manipulate[
  Animate[
    Plot[A*Cos[2*Pi/λ*(x - VZ*v*t)], {x, -5, 5}, 
     PlotRange -> {{-5, 5}, {-1, 1}}, 
     AxesLabel -> {"x", "ψ(x,t)"}], {t, 0, 2*Pi}], 
  {{A, 0.5}, 0, 1, Appearance -> "Labeled"}, 
  {{λ, 2*Pi}, 1, 100, Appearance -> "Labeled"}, 
  {{v, 0.5}, 0, 1, Appearance -> "Labeled"}, 
  {{VZ, 1, "Sign"}, {-1 -> "+", 1 -> "-"}}, AppearanceElements -> "ResetButton"]

The period of the wave is T = λ/v and I tried setting this as the ending time of the animation, but somehow this causes the velocity slider to not work anymore. Does anybody have an idea?

$\endgroup$
2
$\begingroup$

Make the animation run over one period and adjust the AnimationRate accordingly. If these are inside Dynamic, they will be updated automatically when the parameters change.

Manipulate[
 Animate[
  Plot[A*Cos[2*Pi/λ*(x - VZ*v*t)],
   {x, -5, 5},
   PlotRange -> {{-5, 5}, {-1, 1}}, AxesLabel -> {"x", "ψ(x,t)"}],
  {t, 0, Dynamic[If[v == 0, 1, λ/v]]}, 
  AnimationRate -> Dynamic[2 v/λ]],
 {{A, 0.5}, 0, 1, Appearance -> "Labeled"},
 {{λ, 2*Pi}, 1, 100, Appearance -> "Labeled"},
 {{v, 0.5}, 0, 1, Appearance -> "Labeled"},
 {{VZ, 1, "Sign"}, {-1 -> "+", 1 -> "-"}},
 AppearanceElements -> "ResetButton"]
$\endgroup$
  • $\begingroup$ Thanks! What is the default rate of an animation? Can you explain also why we need the factor 2 in AnimationRate? $\endgroup$ – philmcole Feb 15 '18 at 13:14
  • 1
    $\begingroup$ @philmcole Actually, the rate is determined by DefaultDuration, which is normally 5 seconds. I suppose you could solve the problem with it instead of AnimationRate. The factor 2 made it look nice, to me at least. You can replace it by any constant, and it will scale the speed. $\endgroup$ – Michael E2 Feb 15 '18 at 15:12

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.