# How can I control the behavior of a Manipulate with check boxes and radio buttons?

I've been stuck for a long time on this problem, and I really would appreciate if somebody helps me move in the right direction.

I have two functions and each can take one of two forms. I am interested in seeing the sum of these functions. I would like to see a single plot all the time instead of the configuration I show in the code posted below. I want two checkboxes (one for AU and one for TU. If one of these boxes is checked, then I want to be able to choose with radio buttons which form (AU1 or AU2) is plotted. So my Manipulate should have two check boxes and beneath of each two radio buttons. The plot should always show the functions if both check boxes are checked. For example, if AU1 and TU2 are checked, I want to see AU1 + TU2, but if TU is not checked, I only want to see AU1. The radio buttons select which form of of AU or TU is used to form the sum when both functions are checked.

Is my problem with Control@...? I tried things like:

Style[Control@{{x, 1, ""}, {3 -> "AU1", 1 -> "AU2"}, ControlType -> RadioButtonBar}, Blue]


but that didn't get me anywhere.

I think there are two things:

1. I need to rethink the structure I built with If expressions.
2. I need to know how to build a structure with checked check boxes being able to enable and disable radio buttons.

Here is my code and an image:

 Manipulate[
Show[
If[f11, {Plot[ ( Exp[-p]), {p, 0, 1},
PlotStyle -> {Thickness[0.006], Red}, PlotPoints -> 200,
AxesLabel -> {p, U}]}, {}],
If[f12, {Plot[ (3 *p), {p, 0, 1},
PlotStyle -> {Thickness[0.006], Red}, PlotPoints -> 200,
AxesLabel -> {p, U}]}, {}],
If[f21, {Plot[ (-4) (p - 3), {p, 0, 1},
PlotStyle -> {Thickness[0.006], Green}, PlotPoints -> 200,
AxesLabel -> {p, U}]}, {}],
If[f22, {Plot[3, {p, 0, 1}, PlotStyle -> {Thickness[0.006], Green},
PlotPoints -> 200,
AxesLabel -> {p, U}]}, {}],
If[f41, {Plot[  Exp[-p] + (-4) (p - 3), {p, 0, 1},
PlotStyle -> {Thickness[0.006], Orange}, PlotPoints -> 200,
AxesLabel -> {p, U}]}, {}],
If[f42, {Plot[ (3 *p) + (-4) (p - 3), {p, 0, 1},
PlotStyle -> {Thickness[0.006], Orange}, PlotPoints -> 200,
AxesLabel -> {p, U}]}, {}],
If[f51, {Plot[( Exp[-p]) + 3 , {p, 0, 1},
PlotStyle -> {Thickness[0.006], Blue}, PlotPoints -> 200,
AxesLabel -> {p, U}]}, {}],
If[f52, {Plot[ (3 *p) + 3, {p, 0, 1},
PlotStyle -> {Thickness[0.006], Blue}, PlotPoints -> 200,
AxesLabel -> {p, U}]}, {}],
PlotRange -> All, ImageSize -> 450],

{{f11, False, Style["(AU_1)", 12, Bold, Red]}, {True, False}},
{{f12, False, Style["(AU_2)", 12, Bold, Red]}, {True, False}},
{{f21, False, Style["(TU_1)", 12, Bold, Green]}, {True, False}},
{{f22, True, Style["(TU_2)", 12, Bold, Green]}, {True, False}},
{{f41, True, Style["(AU_1 + TU_1)", 12, Bold, Orange]}, {True,False}},
{{f42, False, Style["(AU_2 + TU_1)", 12, Bold, Orange]}, {True,False}},
{{f51, False, Style["(AU_1 + TU_2)", 12, Bold, Blue]}, {True, False}},
{{f52, False, Style["(AU_2 + TU_2)", 12, Bold, Blue]}, {True, False}},

AppearanceElements -> "ResetButton",
ControlPlacement -> Left]


-
Ok, thanks for your comment. I posted a working solution which lets me see the 4 different functions and all the possible combinations of their sums. But I want another way to show it. I want to see only the plot of one function which is the sum of AU and TU. AU could be AU1, AU2 or 0. And TU could be TU1, TU2 or 0. This is basically the functionality. – Keith Smith Dec 21 '12 at 10:24
It would be, but I'm a newbie. I will see what I can do. Just for clarification: now I'm following 2 ways because I don't know a way to make it in 1. The first solution is what I posted, which shows me the functions and the different sums (It's a short version. I have parameters in each function which I want to see their influence on the function and on the sum). The other solution is what I need help with. Of course, it would be better if I can make both to one, with the option to see the functions and to see the sum function depending on which functions I check. Did I explain it clear? – Keith Smith Dec 21 '12 at 11:08
@Nasser: Thanks for helping me. I probably misguided you with my last comment. My main traget solution should have a control panel with the functionality explained in this image: link – Keith Smith Dec 21 '12 at 14:15

Here is another answer using check boxes and button that was asked for. I kept the earlier answer above as is for reference. I used one color. Color difference based on plot can be easily added and left as an exercise

Manipulate[
Plot[auf + tuf, {p, 0, 1}, PlotStyle -> {Thickness[0.006]},Frame-> True,
FrameLabel -> {{None, None}, {p, auf + tuf}},ImagePadding -> 40],

Grid[{
{
Grid[{
{Row[{"AU ",
Checkbox[Dynamic[auOn, {auOn = #; auf = If[Not[auOn], 0, auVal]} &]]}]},
Dynamic[auVal, {auVal = #; auf = #} &], {Exp[-p] -> "AU1",3*p -> "AU2"},
Appearance -> "Vertical", Enabled -> Dynamic[auOn]]}
}, Alignment -> Center, Spacings -> 0],

Grid[{
{Row[{"TU ",
Checkbox[Dynamic[tuOn, {tuOn = #; tuf = If[Not[tuOn], 0, tuVal]} &]]}]},
{RadioButtonBar[Dynamic[tuVal, {tuVal = #; tuf = tuVal} &], {-4 (p - 3) ->
"TU1", 3 -> "TU2"}, Appearance -> "Vertical",Enabled -> Dynamic[tuOn]]}
}, Alignment -> Center, Spacings -> 0]
}}],
{{auf, Exp[-p]}, None},
{{tuf, -4 (p - 3)}, None},
{{auOn, True}, None},
{{tuOn, True}, None},
{{auVal, Exp[-p]}, None},
{{tuVal, -4 (p - 3)}, None},
TrackedSymbols :> {auf, tuf}
]

-
Thanks alot. You saved me alot of time. To thank you, I want to give a small donation to a relief organization you like. I prefer something for Syria like this link or this link. But it's your choice :) – Keith Smith Dec 24 '12 at 15:39

 Manipulate[
choice;
Plot[f, {p, 0, 1}, PlotStyle -> {Thickness[0.006], color},
Frame -> True, FrameLabel -> {{f[p], None}, {p, f}},ImagePadding -> 30],
Grid[{
Which[choice === au1, color = Red; f = au1f,
choice === au2, color = Red; f = au2f,
choice === tu1, color = Green; f = tu1f,
choice === tu2, color = Green; f = tu2f,
choice === au1Andtu1, color = Orange; f = au1f + tu1f,
choice === au2Andtu1, color = Orange; f = au2f + tu1f,
choice === au1Andtu2, color = Blue; f = au1f + tu2f,
choice === au2Andtu2, color = Blue; f = au2f + tu2f
]} &],
{
au1 -> Style["(AU_1)", 12, Bold, Red],
au2 -> Style["(AU_2)", 12, Bold, Red],
tu1 -> Style["(TU_1)", 12, Bold, Green],
tu2 -> Style["(TU_2)", 12, Bold, Green],
au1Andtu1 -> Style["(AU_1 + TU_1)", 12, Bold, Orange],
au2Andtu1 -> Style["(AU_2 + TU_1)", 12, Bold, Orange],
au1Andtu2 -> Style["(AU_1 + TU_2)", 12, Bold, Blue],
au2Andtu2 -> Style["(AU_2 + TU_2)", 12, Bold, Blue]
}, ImageSize -> All, ContinuousAction -> False]
}
}],
{{color, Red}, None},
{{choice, au1}, None},
{{f, Exp[-p]}, None},
{{tu1f, -4 (p - 3)}, None},
{{tu2f, 3}, None},
{{au1f, Exp[-p]}, None},
{{au2f, 3*p}, None},
TrackedSymbols :> {choice}
]

-
I like your idea of using a pop-up menu. I think trying to control this demonstration with check boxes and radio buttons would have been a nightmare. – m_goldberg Dec 21 '12 at 17:33
Actually this is exactly the functionality I need. Thanks alot. But Im still gonna try to get the desired check boxes and radio buttons. If you have any hints in how I should precede, let me know please. – Keith Smith Dec 21 '12 at 19:12