1
$\begingroup$

This question already has an answer here:

I'm making a demonstration with the following code:

a = Pi/4;
b = 3 Pi/2;
f[x_, n_] = Piecewise[{{x + Sin[x] + n, x >= Pi}, {x + Sin[x], x < Pi}}];
Manipulate[
    Plot[
        f[x, n], {x, -Pi, 2 Pi + 1},
        PlotRange -> {{-1, 2 Pi + 1}, {-1, 2 Pi}},
        Epilog -> {
            Table[{Dotted, Line[{{-1, q}, {2 Pi + 1, q}}]}, {q, {f[a, n], f[b, n]}}],
            If[n == 0, {Dashed, Line[{{-1, f[c, n]}, {2 Pi + 1, f[c, n]}}]}, {Dashed, Line[{{-1, k}, {2 Pi + 1, k}}]}]
            },
        Ticks -> False,
        Axes -> False
        ],
    {{n, 0}, {0, Pi/2}},
    {{c, Pi}, a, b},
    {{k, f[a, n], "K"}, f[a, n], f[b, n]}
    ]

When n=0 is selected, the k slider does nothing; when n=Pi/2, the c slider does nothing. Is there some way to hide the k and c sliders under the conditions for which they're inactive?

(Bonus points: For convenience, I'd like to post an animation of what happens for users who can't run it in Mathematica on their own, so if someone could post instructions or a link to where I can learn to make a screen-cap, I would greatly appreciate it!)

$\endgroup$

marked as duplicate by Dr. belisarius, dr.blochwave, m_goldberg, Bob Hanlon, Yves Klett Jun 23 '15 at 20:25

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.

  • $\begingroup$ Once you set $n=0$ and the slider is hidden, how do you expect to then alter $n$ if you so wish? $\endgroup$ – David G. Stork Jun 23 '15 at 16:35
  • $\begingroup$ I've restricted n so that it can only be toggled between 0 and Pi/2. My intention here is to demonstrate the Intermediate Value Theorem, which holds when using f[x, 0], but not when using f[x, Pi/2]. $\endgroup$ – user170231 Jun 23 '15 at 16:38
  • 1
    $\begingroup$ How about apply with Enabled like{{c, \[Pi]}, a, b, Enabled -> n == 0}, {{k, f[a, n], "K"}, f[a, n], f[b, n], Enabled -> n != 0} $\endgroup$ – Junho Lee Jun 23 '15 at 17:05
  • $\begingroup$ @JunhoLee I like your suggestion, though I was wondering if I could prevent the inactive parameter's slider from showing up at all. $\endgroup$ – user170231 Jun 23 '15 at 17:29
  • $\begingroup$ You might find something to help you in this question and answer: How to dynamically change the Appearance of a control in Manipulate? $\endgroup$ – MarcoB Jun 23 '15 at 17:59

Browse other questions tagged or ask your own question.