1
$\begingroup$

I am plotting two functions using 'Manipulate' and I am trying to change the way the values of certain adjustable parameters are being displayed. Here is a photo of the plot so I can refer to the exact variable names: Briefly put, the plot will depend on two variables and when I display their value, I would like to display the slider value times some number (because I need it in multiples of a certain quantity).

Specifically in connection to the photo: you can see how the E_G variable (named 'g' in the Manipulate sequence) is very small ... here I would like it to be displayed in multiples of a constant kk (already defined, as you can see) times the current value of the t-variable.

The specific case aside, I guess there is a general way to manipulate the way a slider variable is displayed, I just have not found anything yet. I would really appreciate your help with that!

$\endgroup$
1
  • $\begingroup$ Please edit your question to include the actual code you are using, not an image of the code, so that readers may copy and run it themselves. $\endgroup$
    – bbgodfrey
    Commented Jun 26, 2021 at 12:53

1 Answer 1

1
$\begingroup$

The easiest way is probably to simply rescale the slider limits and variable: Let's say you want to control x between 0 and 2, but show 10*x. You would do the following:

Manipulate[
 Row@{"Value of x: ", x10/10},
 {{x10, 1, "10·x"}, 0, 10}
 ]

enter image description here

The above approach effectively delegates the transformation of the variable to the user: Every time you want to use x, you have to write x10/10. If you want a more user friendly (but more complicated internally) solution, you can take advantage of custom Manipulate controls and the second argument of Dynamic

First, we define a custom slider function:

iTransformedSlider[func_][Dynamic@var_, lims_ : {0, 1}] :=
 Manipulator[
  Dynamic[func@var, (var = InverseFunction[func][#]) &],
  func /@ lims
  ]
transformedSlider[func_] := iTransformedSlider[func][##] &

The iTransformedSlider trick is necessary since Manipulate only accepts expressions with explicit head Function. As for how it works: We construct a Manipulator using the arguments passed to us (var and lims), but the apply the transformation function func where appropriate. This means: Scaling the displayed value and the limits using func, and applying the inverse of func when setting var. We can then use it simply as:

Manipulate[
 Row@{"Value of x: ", x},
 {{x, 1, "10·x"}, 0, 1, transformedSlider[10 # &]}
 ]

enter image description here

$\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.