I can't figure out why Mathematica behaves this way, may be someone can see the problem. I am no expert on Dynamics, so I might be overlooking something.
I show the code first and then say what the problem is.
Clear[t, s, n, z];
Grid[{
{LocatorPane[Dynamic[p], Graphics[Circle[{0, 0}, 1], ImageSize -> 200],{{-1, -1}, {1, 1}}]},
{Dynamic[{Print@Date[]; Print[ZTransform[n^2/2^n, n, z]]; p}]}}
]
When running the above, you will see that it keeps looping all the time, since it keeps printing. You will see the print messages come out without doing anything to the LocatorPane or moving the mouse.
But when I changed the function above which is ZTransform, to something else, say Laplace, then the looping stops:
Clear[t, s, n, z];
Grid[{
{LocatorPane[Dynamic[p], Graphics[Circle[{0, 0}, 1], ImageSize -> 200],{{-1, -1}, {1, 1}}]},
{Dynamic[{Print@Date[]; Print[LaplaceTransform[t^4*Sin[t], t, s]]; p}]}}
]
It seems functions related Fourier causes this, since I tried this one also and it had the same problem:
Clear[t, s, n, z,w];
Grid[{
{LocatorPane[Dynamic[p], Graphics[Circle[{0, 0}, 1], ImageSize -> 200],{{-1, -1}, {1, 1}}]},
{Dynamic[{Print@Date[]; Print[FourierSequenceTransform[(1/2)^n UnitStep[n], n, w]]; p}]}}
]
Another way of doing the above is using a Module:
process[p_] := Module[{n, z, t, s, w},
Print[Date[]];
ZTransform[n^2 2^(-n), n, z];
p
]
Grid[{
{LocatorPane[Dynamic[p],
Graphics[Circle[{0, 0}, 1],ImageSize -> 200], {{-1, -1}, {1, 1}}]},
{Dynamic[process[p]]}
}]
And again, same problem, I see the looping again. I have to wrap the call to process[p] above with Dynamics to pass the current value of 'p'.
So, my question is why when I use some functions such as ZTransform, Dynamics continue to update, but some other functions such as Laplace, I do not see this problem.
And what can I do to fix this? I do need to call ZTransform using the updated point 'p' in this example.
This is on version 8.01 on windows.
thanks
EDIT1:
I found something which might help. When I add FinishDynamic[] after the call to ZTransform[], it blocks. But not with another call such as Laplace. This means, according to documenation, that ZTransform generates a Dynamic which has not finished updating. What object is this?
Here is an example:
process[p_] := Module[{n, z},
Print[Date[]];
ZTransform[n^2 2^(-n), n, z]; (*bad*)
FinishDynamic[]; (*BLOCKS*)
p
]
Grid[{
{LocatorPane[Dynamic[p],
Graphics[Circle[{0, 0}, 1],
ImageSize -> 200], {{-1, -1}, {1, 1}}]},
{Dynamic[process[p]]}
}]
Again, changing ZTransfor开发者_C百科m[] to some other call, say Laplace[] does not have this problem.
So, it seems to me that ZTransform[] is generating some Dynamic which never finish updating or something along these lines?
EDIT2:
I found the solution. Add trackedSymbols. Here it is
process[p_] := Module[{n, z},
Print[Date[]];
ZTransform[n^2 2^(-n), n, z];(*bad*)
p]
Grid[{
{LocatorPane[Dynamic[p], Graphics[Circle[{0, 0}, 1],ImageSize -> 200], {{-1, -1}, {1, 1}}]},
{Dynamic[process[p], TrackedSymbols :> {p}]
}
}]
Not sure why it is needed when calling ZTransform and not needed with other functions. My guess is this: ZTransform generated a dynamic internally that never finished 'updating' (that is why it blocked as per EDIT1 above).
By explicitly adding TrackedSymbols only on the LocatorPane variable 'p', it now works since whatever other dynamic was causing the problem inside ZTrasnform is not tracked now.
Have you tried turning off SynchronousUpdating
? (see documentation)
I am not entirely sure why some functions are doing this and not others, but it might be that the particular kind of transform you are doing doesn't finish evaluating before the Dynamic
tries to update. If so, another thing to try would be to change the value of the SynchronousInitialization
option to False
(default is True
). Then the transform is queued even while the Dynamic
or Manipulate
construct is updating, instead of (according to the documentation), waiting until the evaluation of the initialization expression is complete before proceeding.
精彩评论