Message Boards Message Boards

0
|
2346 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

How can I use one slider to manipulate two functions?

Posted 11 years ago
 EGPD[r_, \[Theta]_, \[Lambda]_] := \[Theta] (r \[Lambda] + \
 \[Theta])^(r - 1) (E^(-r \[Lambda] - \[Theta]))/r!
 EGPDdist[\[Theta]_, \[Lambda]_, n_] :=
  Table[EGPD[r, \[Theta], \[Lambda]], {r, 0, n}] // N
 (*  distribution of EGPD  omitting EGPD=0*)
 EGPDdistdrop[\[Theta]_, \[Lambda]_, n_] :=
  Drop[Table[EGPD[r, \[Theta], \[Lambda]], {r, 0, n}], 1] // N
 (* EGPD for r>1 conditioned on r not zero *)
 EGPDdistcond[\[Theta]_, \[Lambda]_, n_] :=
EGPDdistdrop[\[Theta], \[Lambda], n]/(1 - E^(-\[Theta]))
plotpdfGPD =
Manipulate[
  ListLogLogPlot[EGPDdistcond[\[Lambda], \[Lambda], 2000],
   Joined -> True,
   PlotRange -> {All, {0.0001, 1}}], {{\[Lambda], .1, "Lamda"}, 0.1,
   1}]


nextstage[thisstage_, \[Lambda]_] :=
RandomInteger[PoissonDistribution[ \[Lambda]]]
nsamples = 50;
samples = Manipulate[Grid[Table[
    NestWhileList[nextstage[#, Lamda] &,
     1, # != 0 &], {nsamples}]], {{Lamda, .5, "Lamda"}, 0.1, 1}]
So here I have two manipulates, one for plotpdfGPD and the other for samples. Both have slider "lamda" that  changes from 0.1 to 1.  How can I have only one slider for both the functions? is it possible?
POSTED BY: Hamzah Abeer
Hi. It's often helpful to make a simple example of the kind of problem you are looking to solve. This will help other people who come across your post understand what is going on.

Consider these two simple Manipulate statements:
Manipulate[Plot[Sin[a x], {x, 0, 10}], {a, 1, 10}]
Manipulate[Plot[Exp[a x], {x, 0, 10}], {a, 1, 10}]
If I understand correctly, you would like to link them together so that the sliders in each affect each other. The easiest and cleanest way of doing this is really to combine these into one Manipulate:
Manipulate[ Column@{Plot[Sin[a x], {x, 0, 10}], Plot[Exp[a x], {x, 0, 10}]}, {a, 1, 10}]

Additionally, you use the option LocalizeVariables to have the Manipulates share the values of a:
Manipulate[Plot[Exp[a x], {x, 0, 10}], {a, 1, 10}, LocalizeVariables -> False]
Manipulate[Plot[Exp[a x], {x, 0, 10}], {a, 1, 10}, LocalizeVariables -> False]

Please note that using LocalizeVariables ->False causes the slider to control the value of a always and so can lead to some confusing situations if the option isn't used carefully. This is why I would almost never use it.
POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract