How to maintain integer values ​​in dynamically linked sliders?

I want to use a pair of sliders to set integer values ​​for two variables nLo and nHi , each of which can vary from 1 to 100, but subject to the limitation nHi> = nLo . Therefore, I adjust the slider for each variable that has a range that dynamically depends on another variable:

nLo = 1; nHi = 100; Column[ { Labeled[Slider[Dynamic[nLo], {1, Dynamic[nHi], 1}, Appearance -> "Labeled"], "nLo", Left ], Labeled[Slider[Dynamic[nHi], {Dynamic[nLo], 100, 1}, Appearance -> "Labeled"], "nHi", Left ], Dynamic[{nLo, nHi}] } ] 

The problem is that as soon as I adjust nHi , its value becomes real (displayed with a decimal point), and not an integer. I believe this is because the slider for nHi cannot say that its first argument to the range Dynamic [nLo] is actually an integer and therefore it uses real values ​​by default. Any suggestions on how to get nHi to remain integer? (Linux Mathematica v8.0.1)

+6
source share
2 answers

Alternatively, you can do something like

 nLo = 1; nHi = 100; Column[{Labeled[ Slider[Dynamic[nLo], {1, Dynamic[nHi], 1}, Appearance -> "Labeled"], "nLo", Left], Labeled[Slider[ Dynamic[nHi, (nHi = Round[#]) &], {Dynamic[nLo], 100, 1}, Appearance -> "Labeled"], "nHi", Left], {Dynamic[nLo], Dynamic[nHi]}}] 
+6
source

Either I do not understand the requirements of the solution, or this code can only work correctly in Mathematica 7.


An interesting problem. It works:

 nLo = 1; nHi = 100; Column[{Labeled[ Slider[Dynamic[nLo], {1, Dynamic[nHi], 1}, Appearance -> "Labeled"], "nLo", Left], Labeled[Slider[ Dynamic[nHi], {Dynamic[ Unevaluated@Round @nLo], 100, 1}, Appearance -> "Labeled"], "nHi", Left], Dynamic[{nLo, nHi}]}] 
+3
source

Source: https://habr.com/ru/post/895017/


All Articles