Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #10747 > unrolled thread

Rewrite a Manipulate to call NDSolve just once?

Started byRBaillie <bobbaillie@frii.com>
First post2012-07-02 09:32 +0000
Last post2012-07-02 09:32 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Rewrite a Manipulate to call NDSolve just once? RBaillie <bobbaillie@frii.com> - 2012-07-02 09:32 +0000

#10747 — Rewrite a Manipulate to call NDSolve just once?

FromRBaillie <bobbaillie@frii.com>
Date2012-07-02 09:32 +0000
SubjectRewrite a Manipulate to call NDSolve just once?
Message-ID<jsrps5$d4u$1@smc.vnet.net>
Here is a nice pendulum demo from http://demonstrations.wolfram.com/NonlinearizedMotionOfASimplePendulum

Like all other demos I've seen, NDSolve[ ] is called many times.  Is
there a way to write this so that NDSolve is called once each time the
"release system" button is pressed?

Manipulate[
  If[run == time, run = 0];
  Module[
    { sol, \[Theta], t },

    sol = NDSolve[{ \[Theta]''[t] + (9.8/l)*Sin[\[Theta][t]] == 0,
                    \[Theta][0] == theta, \[Theta]'[0] ==
thetaPrime },
                    \[Theta], {t, 0, time}, Method ->
"StiffnessSwitching"];

    With[{angle = \[Theta][run] /. First[sol]},
      Graphics[
        { {Lighter[Brown], Rectangle[{-4, 0}, {4, .5}]},   (* top bar
*)
          {Darker[Red], Disk[{0, 0}, .1]},                 (* top
pivot *)
          {Line[{{0, 0}, {l*Sin[angle], -l*Cos[angle]}}]}, (* pendulum
*)
          {Blue, Disk[{l*Sin[angle], -l*Cos[angle]}, .2]}  (* mass at
bottom *)
        } ,
        PlotRange -> {{-4, 4}, {.5, -4}},
        ImageSize -> {500, 300} / 2
      ]  (* end Graphics *)
    ]  (* end With *)
  ]  (* end Module *)
  ,
  { {l, 3, "length of pendulum"}, .5, 3.5, .1, Appearance ->
"Labeled"},
  { {theta, Pi/4, "initial angle (radians)"}, 0, Pi/2, .01, Appearance
-> "Labeled"},
  { {thetaPrime, 0, "initial angular velocity"}, 0, 5, Appearance ->
"Labeled"},
  { {time, 10.00, "time to watch motion"}, 0, 20, .01, Appearance ->
"Labeled"},
  { {run, 0, "release system"}, 0, time, .001, ControlType -> Trigger,
AnimationRate -> 1},
  SynchronousUpdating -> False,
  AutorunSequencing -> {1, 2}
]

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web