Two, now three, ways: I think I'd recommend the first -- strike that -- maybe the third one at the end, but perhaps you have a reason for using SetPrecision
, in which case, use the second.
This first one works as is. One caveat: if the label is used as an input field, the number k
will be set to a machine-precision number.
Manipulate[
Plot[Cos[k x], {x, 0, 2 Pi}],
{{k, 1}, 0.`22, 4.`22, 0.1`22, Appearance -> "Labeled"}]
The second way is to make your own label. Here editing the label still maintains the desired precision.
Manipulate[
Plot[Cos[k x], {x, 0, 2 Pi}],
{{k, 1}, SetPrecision[0., 22], SetPrecision[4.0, 22], SetPrecision[0.100, 22],
Row[{Manipulator[##], " ",
InputField[Dynamic[Round[k, 0.1], (k = SetPrecision[#, 22]) &],
Appearance -> "Frameless", BaseStyle -> "Label"]}] &}
]
Here is a variation with a non-editable label:
Manipulate[
Plot[Cos[k x], {x, 0, 2 Pi}],
{{k, 1}, SetPrecision[0., 22], SetPrecision[4.0, 22], SetPrecision[0.100, 22],
Row[{Manipulator[##], " ", Dynamic@Round[k, 0.1]}] &}]
Both look the same.
There is a difference between setting the precision with SetPrecision
and with a backtick:
x = SetPrecision[0.1, 22]
(* 0.1000000000000000055511 *)
y = 0.1`22
(* 0.1000000000000000000000 *)
Precision /@ {x, y}
(* {22., 22.} *)
x - y
(* 5.5511*10^-18 *)
Alternatively, you can use a dummy variable and convert it to the desired precision:
Manipulate[
k = N[Round[k0, 1/10], 22];
Plot[Cos[k x], {x, 0, 2 Pi}, PlotLabel -> k],
{{k0, 1, "k"}, 0, 4, 0.1, Appearance -> "Labeled"},
{k, None},
TrackedSymbols :> {k0}]
(I included a plot label to verify that k
has the proper precision.)
SetPrecision[k,22]
in place ofk
in the body of yourManipulate
work? Positioning a slider with 22 digits precision is challenging andTable[k, {k, 0.0, SetPrecision[1, 22], SetPrecision[0.1, 22]}] == Table[SetPrecision[k, 22], {k, 0.0, 1.0, 0.1}]
givesTrue
. $\endgroup$