Re: floating point, step forward issue, Manipulate Appearance
- To: mathgroup at smc.vnet.net
- Subject: [mg108785] Re: floating point, step forward issue, Manipulate Appearance
- From: Murray Eisenberg <murray at math.umass.edu>
- Date: Wed, 31 Mar 2010 05:28:17 -0500 (EST)
Ah, the incompatibility of binary computer representation of numbers and the decimal representation modern humans prefer! Try Chop. On 3/30/2010 6:02 AM, Nasser M. Abbasi wrote: > Consider the following: > > Manipulate[Null, {{a, -0.1, "a"}, -0.1, 0.1, 0.1, Appearance -> > "Labeled"}] > > Now click on the little "+" button at the end of the slider near the number > ".1" to open the animation controls. Now click on the "play" button, You > should see nothing too exciting, just a sequence of number > {-.1,0,.1,-.1,0,.1,....} as expected. > > Now try the same as above, but change the range to be -0.3,0.3,0.1, as > follows > > Manipulate[Null, {{a, -0.1, "a"}, -0.3, 0.3, 0.1, Appearance -> > "Labeled"}] > > and run it again with the play button, now you'll see this output: > > {-0.3,-0.2,-0.1, 8.32667*10^-17 ,0.1,0.2,0.3,.... and it repeats}. This is > the same output one gets by doing > Range[-.3, .3, .1] > > So, to avoid the floating point display problem on the label of the control, > I changed the code to do a step by exact fraction values as follows: > > Manipulate[Null, {{a, -1/10, "a"}, -3/10, 3/10, 1/10, Appearance -> > "Labeled"}] > > and when the above is played, you'll see that the exact values are stepped > over as I wanted. No floating point hickups. > > The problem, is that I do not want to display the values as fractions on the > slider label, but as decimals. I am talking about the label itself, on the > end of the slide, which shows the control value of the control variable. Now > this is shown as 1/10, 2/10, etc... > > So, I changed the above to the following: > > Manipulate[Null,{{a,-N[1/10],"a"},-N[3/10],3/10,1/10,Appearance->"Labeled"}] > > And now, it displays as decimal points on the label, and also I do not get > the floating point leftovers displayed anymore when it steps forward. > > I was wondering if there is a better solution than having to throws N's here > and there to get it to work as expected. I wanted to put one N[] around the > control variable itself, like this: > > Manipulate[Null,{{N[a],-1/10,"a"},-3/10,3/10,1/10,Appearance->"Labeled"}] > > But I can't ofcourse. N[a] is not valid symbol anymore. The better solution > would have been is to capture what goes to the label, so I can format it as > I want. It would be nice to be able to do this. I.e. when one types > > Appearance -> "Labeled" > > on a control, there is now no way to intercept this label, or tell > Mathematica how to format it. At least, I did not find a way. If there was, > I could have written something like this > > Manipulate[Null, {{a, -0.1, "a"}, -0.3, 0.3, 0.1, Appearance -> > {"Labeled", N[#]& }] % not valid code > > > Thanks, > --Nasser > > > -- 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