Message Boards Message Boards

0
|
2760 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Avoid control variable in Manipulate displaying unexpected values?

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

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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract