[Date Index]
[Thread Index]
[Author Index]
Using a variable set elsewhere within a function that has attribute
*To*: mathgroup at smc.vnet.net
*Subject*: [mg98019] Using a variable set elsewhere within a function that has attribute
*From*: Daan Gerla <daan at gerla.nl>
*Date*: Sat, 28 Mar 2009 05:41:37 -0500 (EST)
*Reply-to*: daan at gerla.nl
Hello Mathematica users,
I am trying to use a variable defined elsewhere within Manipulate. I
have assigned an expression to the variable that involves another
variable. That second variable should not be assigned to anything
outside of manipulate, however, within Manipulate, I want that second
variable to change as I drag a slider and anything that uses the first
variable to change accordingly. I am not quite sure I am saying this
right, but this example should make clear what I mean:
ode = x'[t] == r x[t] - x[t]^2;
Manipulate[
ode,
{r, 0.1, 1}
]
I do not get any warnings or errors, but the result is not as you might
expect: in the output the equation is displayed without a value for r
and the slider does nothing.
Manipulate[
Evaluate[ode],
{r, 0.1, 1}
]
does what you expect. The output contains a value for r which changes as
the slider is dragged. Now I want to use ode for something else.
Manipulate[
Plot[x[t] /. NDSolve[{Evaluate[ode], x[0] == 0.1}, x, {t, 0, 10}], {t,
0, 10}],
{r, 0, 1}
]
Here I get errors:
NDSolve::dsvar: 0.0002042857142857143` cannot be used as a variable. >>
ReplaceAll::reps: {NDSolve[{(x^\[Prime])[0.000204286]==r
x[0.000204286]-x[<<1>>]^2,x[0]==0.1},x,<<1>>]} is neither a list of
replacement rules nor a valid dispatch table, and so cannot be used for
replacing. >>
[...]
It looks like it takes a number for t when it should not, and not a
number for r when it should.
What I want is of course a plot of x vs. t that changes as I change r by
dragging the slider. I've tried many things, including changing the
attributes of Manipulate, but no good results. I am not even sure what
the problem exactly is...
How do I solve this problem? What is the best way to do what I want to do?
Regards,
Daan
Prev by Date:
**Re: pdf export problem**
Next by Date:
**Re: HoldAll for Integrate**
Previous by thread:
**Re: Looking for help with "Reduce" command for use with**
Next by thread:
**Re: Using a variable set elsewhere within a function that has attribute**
| |