Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Possible Duplicate:
How to create interrelated sliders?
locking a value when manipulating variables

I need to create a Manipulate with two control parameters which are linked by some mathematical relationship. So the user can decide to use either control and when that control is changed, the other will change too.

The example below works as required, using If statements to determine if one of the parameters has been changed and setting the other parameter appropriately.

Although this code works, I suspect there is a better/neater approach which avoids the need to "manually" keep track of oldx and oldy. What is the best way to do it?

oldx = oldy = 0;
Manipulate[
If[x != oldx, y = 1/x; oldx = x];
If[y != oldy, x = 1/y; oldy = y];
{x, y},
{x, 0.1, 10}, {y, 0.1, 10}]
share|improve this question
    
I am almost positive this question is a duplicate yet I cannot find it. Does this seem overly familiar to anyone else? –  Mr.Wizard May 10 '12 at 14:23
4  
I suppose I was thinking of this: mathematica.stackexchange.com/q/1373/121 –  Mr.Wizard May 10 '12 at 14:25
3  
@Mr.Wizard I would say this is similar to this one: mathematica.stackexchange.com/questions/4212/… –  FJRA May 10 '12 at 14:36
    
Thanks for the links. I did search before I posted the question, but didn't come up with anything. –  Simon Woods May 11 '12 at 19:35
add comment

marked as duplicate by acl, rcollyer, Sjoerd C. de Vries May 13 '12 at 11:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3 Answers

up vote 10 down vote accepted

Not sure if this is the best way, but you could consider something like this:

Manipulate[
 {x, y},
 {x, Manipulator[Dynamic[x, (x = #; y = 1/#) &], {.1, 10}] &},
 {y, Manipulator[Dynamic[y, (y = #; x = 1/#) &], {.1, 10}] &},
 Initialization :> ({x, y} = {1, 1})]
share|improve this answer
    
Thanks Heike, this is exactly what I need. –  Simon Woods May 11 '12 at 19:35
add comment

You could also build a custom Manipulate-like object using sliders

Panel[DynamicModule[{x, y},
    Column[{
        Grid[{
            {"x", Slider[Dynamic[x, (x = #; y = 1/#) &], {0.1, 10}], Dynamic[x]},
            {"y", Slider[Dynamic[y, (y = #; x = 1/#) &], {0.1, 10}], Dynamic[y]}
        }],
        Panel[{Dynamic[x], Dynamic[y]}, ImageSize -> 300, Background -> White]
    }], ImageSize -> 300
]

enter image description here

share|improve this answer
add comment

This?

{Slider[Dynamic[x], {0.1, 10}], 
 Slider[Dynamic[1/ x, Set[x, 1/#] &], {0.1, 10}]}
Dynamic[x]

Mathematica graphics

share|improve this answer
add comment

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