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.

Here's a simple Manipulate example:

f[x_, a_, b_] := a x + b
Manipulate[
 Plot[f[x, u[[1]], u[[2]]], {x, -1, 1}, 
 PlotRange -> {-1, 1}], {{u, {1, 0}, "a/b"}, {-1, -1}, {1, 1}}]

enter image description here

I would like to be able to control a and b with individual 1D sliders as well, such that all controls are dynamically updated. How can I achieve this?

share|improve this question
    
I wouldn't consider it a duplicate since the other post wouldn't have gotten me all the way there. –  bdforbes Jul 18 '13 at 16:15
    
I agree, I have revised my thoughts. Closely related –  Kuba Jul 18 '13 at 17:32
add comment

1 Answer 1

up vote 4 down vote accepted

You can put almost any object into the controller area of a Manipulate, even separately from the controls automatically managed by Manipulate. In other words, in that case you can do something like

Manipulate[
           Plot[f[x, u[[1]], u[[2]]], {x, -1, 1}, PlotRange -> {-2, 2}],
           {{u, {1, 0}, "a/b"}, {-1, -1}, {1, 1}},
           Column[{Labeled[Slider[Dynamic[u[[1]]], {-1, 1}], "a = " Dynamic[u[[1]]], Left],
                   Labeled[Slider[Dynamic[u[[2]]], {-1, 1}], "b = " Dynamic[u[[2]]], Left]
                  }],
           Initialization :> {f[x_, a_, b_] := a x + b}]

enter image description here

So, you don't really need to manually specify the Slider2D control, just add a couple of Dynamic sliders with same values of the original controller managed by Manipulate. As you can see I also included the function f definitions inside the Manipulate box by means of the Initialization options. So, the box is fully independent by the external definitions. Otherwise a SaveDefinitions->True should be used.

share|improve this answer
    
I should have tried this. It is much better this way if we do not want to use DynamicModule. I will delete my answer since there is nothing new over the link I've added. Yours should be accepted :) +1 –  Kuba Jul 18 '13 at 11:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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