2
$\begingroup$

I want to have a Manipulate where the user can adjust two sliders with two values which are coherent depending on which value he actually knows.

Look at this calculator for the area of a square. The user can decide if he wants to tell the calculator the area of a square or the length of one side. Since sideLength ^ 2 = area applies one slider should automatically be adjusted when the other was set.

Manipulate[
"calculate the area of a square",
{sideLength, 1, 10, Appearance -> "Open"},
{area, 1, 100, Appearance -> "Open"}
]

enter image description here

Im aware that this might not be the usual way of using the Manipulate function. Im working on a calculator which calculates certain values for different camera sensors. Since all my sensors have an 3:2 aspect ratio I can do my calculations based on the amount of megapixels or the actual count of pixels along the long side. If you have one value you can get the other easily. It would be nice if the sliders would automatically adjust themselves.

$\endgroup$
4
$\begingroup$

You can add the option TrackingFunction to the two controls:

Manipulate[Grid[{{"sideLength", "area"}, {sideLength, area}}], 
 {sideLength, 1, 10, Appearance -> "Open", 
  TrackingFunction -> (sideLength = #; area = #^2; &)},
 {area, 1, 100, Appearance -> "Open", 
  TrackingFunction -> (area = #; sideLength = Sqrt[#]; &)}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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