MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

DynamicModule with Animate

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113570] DynamicModule with Animate
  • From: Hugh Goyder <h.g.d.goyder at cranfield.ac.uk>
  • Date: Wed, 3 Nov 2010 02:54:03 -0500 (EST)

The working DynamicModule below shows an acoustic wave in a pipe with
a side branch. By changing the length of the side branch or the
wavelength you can see reflected waves, transmitted waves and standing
waves. The positive pressure is shown in red and the negative pressure
in brown.

The problem is that I want to do more complicated pipework and this
animation is on the limit of what I can show. In version 7 on my
machine it is jerky and I can't seem to make AnimationRate make it
smoother.

I am trying to isolate the animation from the dynamic variables by
wrapping the Animate in its own Dynamic. I would be happy for the
frames of the animation to be made first, all stored and then have
Animate show them. There would be a delay when the new wavelength is
selected and the frames built but I don't mind this if I get a smooth
animation of the system. It seems that Animate is recalculating each
frame as it goes and this is slowing down the animation.

How can I simulate far more complex systems?

Many thanks

Hugh Goyder

DynamicModule[{f1, f2, f3, lam = 2.666, L = 2, a1, a2, a3, col, sf =
0.1,
  inc = 0.1},
 f1[t_, lam_, L_, x_] := 1/(101 + 99 Cos[4 L Pi/lam]) (
    Cos[t + 2 Pi x/lam] (-1 + Cos[4 L Pi/lam]) +
     Cos[t - 2 Pi x/lam] (101 + 99 Cos[4 L Pi/lam]) +
     10 Sin[t + 2 Pi x/lam] Sin[4 L Pi/lam]);
 f2[t_, lam_, L_, x_] := 1/(101 + 99 Cos[4 L Pi/lam]) (
    10 (9 Cos[t + 2 Pi (L - x)/lam] +
       11 Cos[t - 2 Pi (L + x)/lam]) Cos[2 L Pi/lam]);
 f3[t_, lam_, L_, x_] := 1/(101 + 99 Cos[4 L Pi/lam]) (
    20 Cos[2 Pi (L - x)/lam] (10 Cos[t] Cos[2 L Pi/lam] +
       Sin[t] Sin[2 L Pi/lam]));
 Column[{
   Row[{"L", Slider[Dynamic[L], {0, 5}], Dynamic[L]}],
   Row[{"lam", Slider[Dynamic[lam], {0, 5}], Dynamic[lam]}],
   Dynamic[
    Animate[Graphics3D[{
       Line[{{-5, 0, 0}, {5, 0, 0}}], Line[{{0, 0, 0}, {0, 0, L}}],
       Table[a1 = sf f1[t, lam, L, x]; If[a1 > 0, col = Red, col =
Brown];
        {col,
         Line[Table[{x, a1 Cos[theta], a1 Sin[theta]}, {theta, 0, 2
Pi,
            Pi/4.}]]},
        {x, -5, 0, inc}],
       Table[a2 = sf f2[t, lam, L, x]; If[a2 > 0, col = Red, col =
Brown];
        {col,
         Line[Table[{x, a2 Cos[theta], a2 Sin[theta]}, {theta, 0, 2
Pi,
            Pi/4.}]]},
        {x, 0, 5, inc}],
       Table[a3 = sf f3[t, lam, L, x]; If[a3 > 0, col = Red, col =
Brown];
        {col,
         Line[Table[{ a3 Cos[theta], a3 Sin[theta], x}, {theta, 0, 2
Pi,
            Pi/4.}]]},
        {x, 0, L, inc}]
       },
      Boxed -> False, ImageSize -> 7 72,
      PlotRange -> {{-6, 6}, {-1, 1}, {-1, 6}}
      ], {t, 0, 2 Pi}]]
   }]
 ]


  • Prev by Date: Beginner question about Mathematica FinancialData
  • Next by Date: Positive amd PositiveDefiniteQ
  • Previous by thread: Re: Beginner question about Mathematica FinancialData
  • Next by thread: Positive amd PositiveDefiniteQ