Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: Re: How to find which variable caused the trigger in Manipulate[]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg103847] Re: [mg103821] Re: How to find which variable caused the trigger in Manipulate[]
  • From: "David Park" <djmpark at comcast.net>
  • Date: Fri, 9 Oct 2009 07:15:54 -0400 (EDT)
  • References: <hafbgr$j4r$1@smc.vnet.net> <33000296.1255005115092.JavaMail.root@n11>

I know that the Demonstrations project is very popular and it does get users
turned on to dynamic presentations. That is all to the good. But it is too
restricted.

What we really need to be able to do is use Mathematica as an active and
dynamic technical writing medium and to be able to send the notebooks to
anyone and know that they could read and evaluate them (but perhaps not do
anything else) just as with PDF documents.

Nothing would do more to turn Mathematica into a "must learn, must have"
application. Nothing would do more to promote better scientific
communication.

Otherwise, what could is all this fancy dynamic stuff except for our own
private enjoyment or within restricted groups? It's a shame because all the
pieces are there within regular Mathematica.


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




From: Nasser Abbasi [mailto:nma at 12000.org] 


"Nasser Abbasi" <nma at 12000.org> wrote in message 
news:hafbgr$j4r$1 at smc.vnet.net...

>> Again, I want something like this
>>
>> Manipulate[
>> process[( pickTheCorrectControlVariableWhichChanged ],
>> {a, 0, 1}, {b, 0, 1}, Initialization :>
>>
>>   (process[arg_] := Module[{}, Plot[Sin[arg*x], {x, -Pi, Pi}]])
>> ]
>>
>>
>

> I made some progress and I think I have a solution.
>
> I save the old value of each control variable in a global variable, then 
> in
> the Manipulate expression, I check, using an If statement which current
> value of the control variable is different from the old value. I got it to
> work ok finally.
>
> Here is an example:
>
> olda = 999;
> oldb = 999;
>
> Manipulate[
>   If[olda != a, {olda = a; Style[StringJoin["a=", ToString[a]]]},
>
>   If[oldb != b, {oldb = b; Style[StringJoin["b=", ToString[b]]]},
>
>    Text["this message should NOT show up!"]]], {a, 0, 1}, {b, 0, 1},
>
>  LocalizeVariables -> True, TrackedSymbols -> {a, b}]
>
>

It is me again, with the same problem.

I found out that I can NOT use global variables in a demo, and I also can't 
wrap the whole Manipulate inside a module. Any one of the above method will 
have solved this problem, but rules are rules, so now I have to find another

solution.  So I am stuck again.

Before I recode everything again, which I would hate to do, I thought I'll 
ask one more time, may be some expert can have a solution. But this one is 
really hard.

I'll explain again the problem to make sure we are all clear on it.

I need to write a Manipulate where inside the Manipulate I need to detect 
which slider or in other words, which control variable was changed. i.e. 
which slider the user just changed to cause the Manipulate expression to be 
generated. (I need to do this so I can do different processing based on the 
slider that was selected)

We all know that Manipulate generates a new version of its expression when 
one of the control variables changes value.  I need to know which control 
variable changed.

There is the general layout

Manipulate[

  (*   expression that uses control variables *)

   ,

  (* controls here which update the control variables values *)
]

But there are restriction on the solution, since this will be for a demo. 
Again, there can NOT be global variables used, (i.e. no variables in the 
Manipulate initialization section, since these are global), and there can 
NOT be a module around Manipulate[], i.e. no  Module[{...}, Manipulate[...]]

allowed.

Here is a small code to show the problem

Manipulate[
    Text[StringJoin["you moved the ", "x or y", " slider"]],
   {x, 0, 1},
   {y, 0, 1}
]

Could someone modify the above, so that the code above will tell which 
slider the user _just_ moved?

It seems like an impossible problem for me to solve without the use of 
global variables or a module around Manipulate.

Here is what I tried so far, and this fail:

Manipulate[
   Which[

   x != oldx,
   {oldx = x; Text[StringJoin["you moved the ", "x ",  " slider"]]},

   y != oldy,
   {oldy = y; Text[StringJoin["you moved the ", "y ", " slider"]]},

   True, Text["why Ami here??"]
  ],

  {x, 0, 1},
  {y, 0, 1},
  {oldx, -999,  ControlType -> None},
  {oldy, -999,  ControlType -> None}
]

The reason it fail is because oldx and oldy are updated to the same value of

x and y whenever x or y changes before I get the chance to do the 
comparison. I.e. when the new version of the expression is generated, oldx=x

and oldy=y each time.  This seems to consequences of Manipulate generating 
DynamicModule[] for the whole thing. You can see this by using the SnapShot 
option on the Manipulate output. This will generate the whole expression 
form. (Nice tool).

If someone can make it so that the above will display the correct message 
each time, then I would declare that person to be the Mathematica Guru of 
the year.

I think I have reached the limit of my current Mathematica understanding 
when it comes to internals of Manipulate and Dynamics to be to solve this 
one. But I'll keep on looking.

Thank you,
--Nasser 





  • Prev by Date: Re: generating submultisets with repeated elements
  • Next by Date: Re: Re: confused about == vs === in this equality
  • Previous by thread: Re: How to find which variable caused the trigger in Manipulate[]
  • Next by thread: Re: Re: How to find which variable caused the trigger in Manipulate[]