8
$\begingroup$

Bug introduced in 10.0 and persisting through 11.1.1.0 or later


Answering this question I had to realize that TrackingFunction isn't working properly if at least one value of the corresponding variable range is a mathematical constant.

For example:

Manipulate[Column[{
   {a, b, c, d},
   {lasta, lastb, lastc, lastd}
   }],
 {a, 0, Pi, TrackingFunction -> {lasta = a; &, a = #; &, a = #; &}},
 {b, 0, N[Pi], TrackingFunction -> {lastb = b; &, b = #; &, b = #; &}},
 {c, 0, GoldenRatio, TrackingFunction -> {lastc = c; &, c = #; &, c = #; &}},
 {d, Pi, N[2. Pi], TrackingFunction -> {lastd = d; &, d = #; &, d = #; &}},
 {{lasta, 0}, None}, {{lastb, 0}, None}, {{lastc, 0}, None}, {{lastd, 0}, None}]

ScreenGIF

Note that only lastb gets updated properly in this example and TrackingFunction fails to update lasta, lastc, and lastd.

Is this a bug?
What workarounds other than applying N to the mathematical constants are there?


Replacing the first TrackingFunction with

TrackingFunction -> {lasta = N@a; &, a = N@#; &, a = N@#; &}

doesn't solve the problem.


Using the second argument of Dynamic within a Manipulator seems to work correctly.

DynamicModule[{n, m = 0},
 {Manipulator[Dynamic[n, {m = n; &, n = #; &, n = #; &}], {0, Pi}], Dynamic[n], Dynamic[m]}]

enter image description here

$\endgroup$
  • $\begingroup$ An explanation why TrackingFunction fails would also be appreciated, but I don't want to make this question too broad or unanswerable. $\endgroup$ – Karsten 7. Dec 9 '15 at 22:11
6
$\begingroup$

I think it is a bug that Manipulate fails to interpret the input correctly if the parameter range contains at least one entry that is NumericQ but not NumberQ. In such a situation the default TrackingFunction is used instead of the specified one.

Another workaround is to provide the control in the form of a function, in which the second argument of Dynamic is used instead of TrackingFunction. In the following code this workaround is used to fix the behavior of the first Manipulator.

Manipulate[
 Column[{{a, b, c, d}, {lasta, lastb, lastc, lastd}}], 
 {a, 0, Pi, Manipulator[Dynamic[#, {lasta = a; &, a = #; &, a = #; &}]] &}, 
 {b, 0, N[Pi], TrackingFunction -> {lastb = b; &, b = #; &, b = #; &}}, 
 {c, 0, GoldenRatio, TrackingFunction -> {(Print["c"]; lastc = c); &, 
   (Print["c"]; c = #); &, (Print["c"]; c = #); &}},
 {{d, N[Pi]}, Pi, N[2. Pi], 0.1, Manipulator, 
   TrackingFunction -> {lastd = d; &, d = #; &, d = #; &}}, 
 {{lasta, 0}, None}, {{lastb, 0}, None}, {{lastc, 0}, None}, {{lastd, 0}, None}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.