Student Support Forum: 'Manipulate with non-explicit variables' topicStudent Support Forum > General > Archives > "Manipulate with non-explicit variables"

 < Previous Comment | Next Comment > Help | Reply To Comment | Reply To Topic
 Author Comment/Response Michael 01/12/13 9:09pm Try reprule = {end -> endval}; Manipulate[ NDSolve[{y''[x] + Sin[y[x]] y[x] == 0, y[0] == 1, y'[0] == 0}, y, {x, 0, end} /. reprule], {endval, 10, 20}, LocalizeVariables -> False] By default Manipulate localizes its variables. When reprule is set outside Manipulate, endval is a Global symbol; inside the Manipulate endval is a different variable. They actually have different full names in the kernel, even though they have the same name in your input. But the above probably won't do what you want. That's because the expression inside the Manipulate does not contain "endval". Mathematica will decide that the output does not depend on endval and therefore won't update the NDSolve when endval is changed. So instead, try reprule = {end :> endval}; Manipulate[ endval; NDSolve[{y''[x] + Sin[y[x]] y[x] == 0, y[0] == 1, y'[0] == 0}, y, {x, 0, end} /. reprule], {endval, 10, 20}, LocalizeVariables -> False] It's a silly trick, putting an endval that does nothing (well, not exactly: it will be evaluated). The RuleDelayed instead of a Rule is important, though, if endval is to be a global variable. If you don't like that, you'll have to provide some way of communicating from inside the Manipulate to outside. So you could try making reprule explicitly depend endval, by making it a function: reprule[endval_] := {end -> endval}; Manipulate[ NDSolve[{y''[x] + Sin[y[x]] y[x] == 0, y[0] == 1, y'[0] == 0}, y, {x, 0, end} /. reprule[endval]], {endval, 10, 20}] URL: ,

 Subject (listing for 'Manipulate with non-explicit variables') Author Date Posted Manipulate with non-explicit variables Abed Alnaif 01/11/13 6:05pm Re: Manipulate with non-explicit variables Michael 01/12/13 9:09pm Re: Manipulate with non-explicit variables yehuda 01/13/13 05:59am
 < Previous Comment | Next Comment > Help | Reply To Comment | Reply To Topic