MathGroup Archive 2008

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

Search the Archive

RE: Re: Dynamic problem (possibly simple)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg92944] RE: [mg92905] Re: Dynamic problem (possibly simple)
  • From: "E. Martin-Serrano" <eMartinSerrano at telefonica.net>
  • Date: Mon, 20 Oct 2008 07:36:17 -0400 (EDT)
  • References: <gd9lh6$egl$1@smc.vnet.net> <200810181023.GAA15982@smc.vnet.net>

Hi,

David, your calcAll[] seems a nice idea. But, what if we had several levels
of dependent dynamic variables (some of them involving circular dependency),
Let us say, primary dynamic variables, first level dependent variables
(which depend on those in the primary level), and in general, nth-level
dependent variables which depend on those in the previous n -1 levels. I
have been thinking of proposing (to WRI) to provide a tool to extract or
construct the data dependency graph of Mathematica programs. It seems to me
that it would be a must; to let users write clean, fast and no messed
dynamic pieces of code. The data dependency graph is part of the
intermediate data structures generated by the parser to interpret the code
in the notebooks. So, it should be already available although hidden. And
ease for WRI to provide it.

Just a suggestion for WRI to think about it.

Regards.

-----Original Message-----
From: David Park [mailto:djmpark at comcast.net] 
Sent: Saturday, October 18, 2008 11:24 AM
To: mathgroup at smc.vnet.net
Subject: [mg92944] [mg92905] Re: Dynamic problem (possibly simple)

The following is a method that I use. It uses the idea that we have primary 
dynamic variables that are set by controls, in this case aufpunkt, and 
dependent variables that are calculated from the primary variables, in this 
case x and y the coordinates of the point. We then create a routine, 
calcAll, that calculates all the dependent quantities from the primary 
quantities. The second argument of Dynamic is used to assure that all the 
dependent quantities are calculated each time a primary dynamic variable is 
adjusted. It is easy to generalize this by having more primary variables 
with their controls and more arguments in calcAll. Just include the second 
Dynamic argument in every control and use calcAll. You could use Module or 
DynamicModule here depending on how you want the variables localized.

Module[
 {(* Primary dynamic variable *)
  aufpunkt = {0, 0},
  (* Dependent variables *)
  x, y,
  (* Routine to calculate dependent variables *)
  calcAll},

 calcAll[p_] := {x, y} = p;
 (* Initialize dependent variables *)
 calcAll[aufpunkt];

 Column[
  {Slider2D[
    Dynamic[aufpunkt, (aufpunkt = #; calcAll[aufpunkt]) &], {{-2, -2}, {2, 
2}}],
   Dynamic[Row[{("y")^2, Spacer[5], , y^2}]]
   }]
 ]


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


"m.g." <mg at michaelgamer.de> wrote in message 
news:gd9lh6$egl$1 at smc.vnet.net...
> Hi all,
>
> I have the following problem: I want to dynamically plot a function
> (tangential plane to a 3D Plot) One part is that I have to compute the
> gradient of the function. I could not manage this (dynamically). I
> have stripped of any unnessesary code to descripe the problem, so look
> at this:
>
> This makes a slider to select a point (works well, of course)
>
> {Slider2D[Dynamic[aufpunkt], {{-2, -2}, {2, 2}}], Dynamic[aufpunkt]}
>
> This should do a computation with "aufpunkt" (does not work)
>
> DynamicModule[{x, y, a, b},
> x = Dynamic[aufpunkt[[1]]]; y = Dynamic[aufpunkt[[2]]];
> y^2
> ]
>
> The output is not evaluated, I get, for instance, (0.5)^2, instead of
> 0.25. How can I manage to get the formula (y^2 in this case)
> evaluatet?
>
> Greetings
>
> Mike
> 




  • Prev by Date: Re: Pi Formula
  • Next by Date: Re: notation using # with exponents and &
  • Previous by thread: Re: Dynamic problem (possibly simple)
  • Next by thread: ListPlot Problem