Re: how uncouple dynamic objects?

*To*: mathgroup at smc.vnet.net*Subject*: [mg109508] Re: how uncouple dynamic objects?*From*: Murray Eisenberg <murray at math.umass.edu>*Date*: Sun, 2 May 2010 05:36:07 -0400 (EDT)

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}, {x[t],y[t]}/.First@DSolve[ {Thread[{x'[t],y'[t]}==F[x[t],y[t]]],Thread[{x[0],y[0]}==xy0]}, {x[t],y[t]},t]]; Manipulate[ ParametricPlot[Evaluate[trajectory[t,xy0]],{t,-3,3}, PlotRange->{{-4,4},{-4,4}}],{xy0,{-4,-4},{4,4}}, ControlType->Locator,TrackedSymbols:>{xy0}]] (* first call inputs *) A={{2,3},{3,2}} F[x_,y_] = A.{x,y}; phasePortrait[F] (* second call inputs *) A={{-2,3},{-3,-2}}; F[x_,y_] = A.{x,y}; phasePortrait[F] 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 math.umass.edu 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