Message Boards Message Boards

Avoid control variable in Manipulate displaying unexpected values?

GROUPS:

I have a Manipulate command in which the control variable runs over an interval which includes zero and with a specific increment. When the slider value is near zero, the value displayed can be an exact zero or an approximate zero depending upon how it was approached. Try the following and note that "sliding" onto zero is no problem, but incrementing to zero from either direction gives an inexact zero representation. This can be overcome with a Chop command, but I can't seem to change the actual display of the value that way. Here's a simplified command to try:

Manipulate[N[c,20],{{c,0,"(-0.5,2)"},-0.5,2.0,0.01,Appearance->{"Labeled","Open"}}];

Is there any way to "manipulate" the control variable to avoid this behavior?

POSTED BY: William Vaughn
Answer
4 months ago

William,

Sometimes Manipulate is limiting. Since Manipulate is build on Dynamic you can add your custom functionality by doing something like this:

Panel[Column[{Row[{Slider[Dynamic[x], {-.5, 2.0, 0.01}], Dynamic[x]}],
    ButtonBar[{"-" :> (x = Chop[x - .01]), 
     "+" :> (x = Chop[x + .01])}], Dynamic[N[x, 20]]}]]

Naturally, you can clean it up and make it nicer looking and add more functionality.

Regards

POSTED BY: Neil Singer
Answer
4 months ago

Group Abstract Group Abstract