| Original Message (ID '233465') By Michael: |
| 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}]
|
|