Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #10747
| From | RBaillie <bobbaillie@frii.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Rewrite a Manipulate to call NDSolve just once? |
| Date | 2012-07-02 09:32 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jsrps5$d4u$1@smc.vnet.net> (permalink) |
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}
]
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Rewrite a Manipulate to call NDSolve just once? RBaillie <bobbaillie@frii.com> - 2012-07-02 09:32 +0000
csiph-web