Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to be able to start, stop, and move the dynamically moving point simultaneously in both animations. The "PlayPauseButton" in the animations only controls the given animation. Indeed, I want both animations to always by synchronized.

system = {x'[t] == 2 x[t] - 0.08 x[t] y[t], x[0] == 400,
          y'[t] == -y[t] + 0.01 x[t] y[t], y[0] == 25};
sol = NDSolve[system, {x[t], y[t]}, {t, 0, 21.5}];
{x1[t_], y1[t_]} = {x[t], y[t]} /. Flatten[sol];

px4 = Plot[x1[t], {t, 0, 21.5}, PlotRange -> {0, 400}, PlotStyle -> {Black}];
py4 = Plot[y1[t], {t, 0, 21.5}, PlotRange -> {0, 400}, PlotStyle -> {Black, Dashed}];

Row[
 {Animate[
   Show[px4, py4,
    Graphics[{PointSize[Large], Red, Point[Dynamic[{t, x1[t]}]], 
              Point[Dynamic[{t, y1[t]}]]}]], {t, 0, 21.5, 
   AppearanceElements -> "PlayPauseButton"}, SaveDefinitions -> True,
   AnimationRate -> 0.251, AppearanceElements -> "PlayPauseButton", 
   BaselinePosition -> Bottom],
  Animate[
   Show[ParametricPlot[{x1[t], y1[t]},{t, 0, 5.375}, AxesLabel -> {"Prey", "Predator"}, 
                        AspectRatio -> 1, PlotRange -> {{0, 400}, {0, 80}}], 
        Graphics[{Red, PointSize[Large], Point[{x1[t], y1[t]}]}]],
   {t, 0, 5.375, AppearanceElements -> "PlayPauseButton"}, 
   SaveDefinitions -> True, AnimationRate -> 0.251, 
   BaselinePosition -> Bottom]}, Frame -> True, RoundingRadius -> 10]

The desired slider should fit into the frame space above the first "Animate". Perhaps I could have rewritten this code with Manipulate, but I don't know how to do that either.

share|improve this question
    
Stephen, thanks for the accept - you might also wait some time and see if other answers drop in (Qs with accepted answers tend to draw less new answers) and then decide to accept mine ;-) –  Yves Klett Oct 28 '13 at 13:09

1 Answer 1

up vote 2 down vote accepted

A slight rewrite of your code using Manipulate:

Manipulate[
 Column[{Show[px4, py4, 
    Graphics[{PointSize[Large], Red, Point[Dynamic[{t, x1[t]}]], 
      Point[Dynamic[{t, y1[t]}]]}]], 
   Show[ParametricPlot[{x1[t], y1[t]}, {t, 0, 5.375}, 
     AxesLabel -> {"Prey", "Predator"}, AspectRatio -> 1, 
     PlotRange -> {{0, 400}, {0, 80}}], 
    Graphics[{Red, PointSize[Large], Point[{x1[t], y1[t]}]}]]}, 
  Frame -> True], {t, 0, 21.5}]

Mathematica graphics

You have different domains for your two Animates, but it somehow seems to work out in a cyclical fashion in this case.

As noted by @MichaelE2, a closer fit to the original Animate can be achieved in this way (layout changed to accomodate larger control bar):

Manipulate[
 Grid[{{Show[px4, py4, 
     Graphics[{PointSize[Large], Red, Point[Dynamic[{t, x1[t]}]], 
       Point[Dynamic[{t, y1[t]}]]}]], 
    Show[ParametricPlot[{x1[t], y1[t]}, {t, 0, 5.375}, 
      AxesLabel -> {"Prey", "Predator"}, AspectRatio -> 1, 
      PlotRange -> {{0, 400}, {0, 80}}], 
     Graphics[{Red, PointSize[Large], Point[{x1[t], y1[t]}]}]]}}, 
  Frame -> True], {t, 0, 21.5}, ControlType -> Animator]

Mathematica graphics

share|improve this answer
    
Control type Animator for t might be more in line with the OP's wishes. –  Michael E2 Oct 28 '13 at 12:39
1  
@MichaelE2 feel free to modifiy - I just took the quickest route :-) –  Yves Klett Oct 28 '13 at 12:43
    
I'll just leave it as comment. One can always click the + and use the animator that comes with the slider. I really just meant to point out another possibility. –  Michael E2 Oct 28 '13 at 12:46
    
@MichaelE2 added - thanks for the tip (in fact I never used that Control type specifically). –  Yves Klett Oct 28 '13 at 13:07
    
The domain for the first animate reflects just 4 periods. Had I used the same domain for the second animate, errors from NDSolve creep in which are reflected in the orbit. Thus I used just one period for the second animate and cut its animation rate by 1/4. Thanks both of you for your help –  Stephen Oct 28 '13 at 13:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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