7
$\begingroup$

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?

$\endgroup$
2
  • $\begingroup$ I wouldn't consider it a duplicate since the other post wouldn't have gotten me all the way there. $\endgroup$
    – bdforbes
    Commented Jul 18, 2013 at 16:15
  • $\begingroup$ I agree, I have revised my thoughts. Closely related $\endgroup$
    – Kuba
    Commented Jul 18, 2013 at 17:32

1 Answer 1

5
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ 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 $\endgroup$
    – Kuba
    Commented Jul 18, 2013 at 11:06

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.