MathGroup Archive 2010

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

Search the Archive

Re: how uncouple dynamic objects?

Below is the actual offending code where the problem of unwanted 
coupling of dynamic objects appeared.

To see the problem:

(a) Evaluate the expression that defines phasePortrait.

(b) Evaluate both sets of expressions in each of which a matrix A and a 
function F are defined and then the function phasePortrait is called.

On the outputs you'll see a hyperbolic arc on the first and a spiral on 
the second.

(c) And now the problem: go back and click within the FIRST output. 
You'll get a spiral rather than the desired hyperbolic arc. In other 
words, something in the 2nd call to phasePortrait is now affecting the 
output from the first call.  (And vice versa.)

This is despite now using the TrackedSymbols option in the Manipulate, 
as suggested by several respondents to my original post that had an 
oversimplified example.

In the application at hand, it's really undesirable to use different 
names for the function F each time I'm ready to call phasePortrait, and 
it's out of the question to use a pure function when defining F.  (Those 
suggestions were also proffered for the original, oversimplified example 
I posted.)

All suggestions welcome!

   (* main function that will be called *)
    phasePortrait[F_] := Module[{xy0,trajectory},
       trajectory[t_,xy0_] := Module[{x,y},

    (* first call inputs *)
    F[x_,y_] = A.{x,y};

    (* second call inputs *)
    F[x_,y_] = A.{x,y};

On 4/27/2010 7:41 AM, Albert Retey wrote:
> Am 27.04.2010 10:04, schrieb Murray Eisenberg:
>> Here's a simple example of a more complicated situation where I define a
>> function that takes a function as argument and uses Manipulate to
>> produce its output:
>>     fplot[f_]:= Manipulate[
>>                   Plot[f[x+a],{x,-2,2}],
>>                 {a,0,2}]
>>     f[x_]:= x^2
>>     fplot[f]
>>     f[x_]:=x^3
>>     fplot[f]
>> When I execute the second definition (with x^3) of f, it automatically
>> changes the f used in the still-displayed output from the first call to
>> fplot.
>> How can I isolate the two instances -- and yet still use the same name
>> for the two different functions?  (Or is this not possible?)
> Manipulate knows the TrackedSymbols-Option, if you put in everything
> that needs to be tracked except for f it will behave as you require:
> fplot[f_] :=
>   Manipulate[Plot[f[x + a], {x, -2, 2}], {a, 0, 2},
>    TrackedSymbols :>  {a}]
> It will isolate in the sense that the Manipulate just doesn't realize it
> is still using an old definition of f. I can't say whether that will
> cause problems or will isolate the two definition in every situation but
> for your example it seems to work...
>> Clearly this is an issue of the dynamic structure underlying
>> Manipulate, and I'm willing to use a "direct" definition using a
>> Dynmaic variable a with a control instead of the simpler
>> Manipulate. But of course I'd prefer to be able to do it with
>> Manipulate.

Murray Eisenberg                     murray at
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305

  • Prev by Date: Re: Sphere formula
  • Next by Date: Re: Evaluating a sum from terms generated by the Array function
  • Previous by thread: Re: how to solve for all integer solutions, linear programming
  • Next by thread: Front-end - a strange behaviour of Plot3D