1
$\begingroup$

I want to convert inputs from controls in Manipulate into exact numbers and have two kinds of inputs:

  • parameters: there are a fixed number of these
  • rates: the number of rates is controlled by the parameter n

To do this, I package the parameters into a list of rules and use SetPrecision to translate the inputs to exact numbers. But that approach doesn't see to work for rates.

You can see that I tried twice to set the precision of the rates:

  1. With (rate[mode]=SetPrecision[#,Infinity])&
  2. With SetPrecision[rate /@ Range[n],Infinity]

The figure shows that the rates -- the top line -- are not exact numbers. The parameter p is an exact number. How to get the rates to be exact?

``` 
With[{maxModes = 5},
  Manipulate[
    Manipulate[
        Evaluate[
           With[{rates = Thread[Rule[Range[n], SetPrecision[rate /@ Range[n],Infinity]]],
                 params = {p ->SetPrecision[pval, Infinity]}},
              Column[{rates,params}]]],
        Evaluate[
                 Sequence @@ (With[{mode = #},{{rate[mode], mode, Row[{"Rate ", mode}]},-10, 10,
                              Row[{Manipulator[##]," ", InputField[Dynamic[rate[mode],(rate[mode]=SetPrecision[#,Infinity])&],Appearance->"Frameless",BaseStyle->"Label"]}]&}] & /@ Range[n])]],

    {{n, 3, "Number of Modes"}, Range[maxModes], Control->SetterBar},
    {{pval, 1, "Parameter"}, -1, 1, Appearance->"Labeled"}]]
[![Precision of Rates vs Parameters][1]][1]


  [1]: https://i.sstatic.net/eN6Gn.png

$\endgroup$

1 Answer 1

1
$\begingroup$

Ah, I see at least part of the answer. Dynamic[rate[mode],(rate[mode]=SetPrecision[#,Infinity])&] Sets the precision of inputs to the InputField. Repeating that construction in the Manipulator sets the precision of the inputs via that control. I still do not understand why SetPrecision[rate /@ Range[n],Infinity] had no effect.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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