MathGroup Archive 2008

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

Search the Archive

Re: Dynamic problem (possibly simple)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg92905] Re: Dynamic problem (possibly simple)
  • From: "David Park" <djmpark at comcast.net>
  • Date: Sat, 18 Oct 2008 06:23:57 -0400 (EDT)
  • References: <gd9lh6$egl$1@smc.vnet.net>

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: ListPlot Problem
  • Next by Date: Dynamic tangential plane - how?
  • Previous by thread: Dynamic problem (possibly simple)
  • Next by thread: RE: Re: Dynamic problem (possibly simple)