MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Using a variable set elsewhere within a function that has attribute

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98062] Re: Using a variable set elsewhere within a function that has attribute
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Sun, 29 Mar 2009 02:45:01 -0500 (EST)
  • References: <gqkuru$488$1@smc.vnet.net>

Hi,

ode = x'[t] == r x[t] - x[t] 2;
Manipulate[ode /. r -> \[ScriptR], {\[ScriptR], 0.1, 1}]

Regards
   Jens

Daan Gerla wrote:
> 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: rules on vector sequence
  • Next by Date: Re: Option instead of a function argument: is it possible?
  • Previous by thread: Using a variable set elsewhere within a function that has attribute
  • Next by thread: Re: Using a variable set elsewhere within a function that has attribute