MathGroup Archive 2007

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

Search the Archive

Using Intermediate Variables in DynamicModules

  • To: mathgroup at smc.vnet.net
  • Subject: [mg80265] Using Intermediate Variables in DynamicModules
  • From: "David Park" <djmpark at comcast.net>
  • Date: Thu, 16 Aug 2007 04:44:02 -0400 (EDT)

I am having a lot of trouble with a DynamicModule expression. I believe that 
the following examples get to the heart of the matter.

Here is a DynamicModule that uses an external function f. It has two 
internal variables a and b, which are controlled by sliders. The third 
output line gives a+b and f[a+b].

f[x_] := x^2
DynamicModule[
 {a = 0.5, b = 0.5},
 Column[{Slider[Dynamic[a], {0, 2}],
   Slider[Dynamic[b], {0, 2}], {Dynamic[a + b], Dynamic[f[a + b]]}}]]


Notice that f[a+b] is fully evaluated in the output. Now in my actual case I 
have a long and complicated expression involving a and b that is used in a 
number of different places. So to clarify the entire expression I would like 
to define an intermediate expression that can then be used in the dynamic 
output. Here is my attempt:

f[x_] := x^2
DynamicModule[
 {a = 0.5, b = 0.5, work},
 work = Dynamic[a + b];
 Column[{Slider[Dynamic[a], {0, 2}],
   Slider[Dynamic[b], {0, 2}], {work, f[work]}}]]

Now, although the output is formally correct, the output, and in particular 
f[work], is not fully evaluated. I think that may be the cause of my 
problem. Why, in the first case does the f expression become fully evaluated 
but not in the second case? Is there a simple way to force kernel evaluation 
when intermediate expressions are used? (I.ve tried many combinations of 
using Dynamic in the output expression and none of them changed the 
behavior.)

Thanks in advanced. I've always gotten great help from this group.

-- 
David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/




  • Prev by Date: Re: Completely frivolous use of new v6 Mathematica commands
  • Next by Date: Re: Serious Problem with GridLines
  • Previous by thread: Re: FindRoot and Interpolating function
  • Next by thread: Re: Using Intermediate Variables in DynamicModules