3
$\begingroup$

I have the next code

 Manipulate[
     Switch[x, a, If[selection =!= None, selection = None], b, 
        If[selection === None, selection = None], c, 
        If[selection === None, selection = "Hola"]
 ];
 selection, {x, {a, b, c}, ControlType -> PopupMenu},  
 {{selection, None}, 
     Switch[x, a, {"recta", "parabola"}, b, {"hiperbola", "absoluto"}, 
     c, {"Seno", "Coseno"}], ControlType -> PopupMenu}
 ]

but I need you to choose the second popupmenu I plot the function chosen.

$\endgroup$
2
  • $\begingroup$ it seems to me that something's wrong with the second Switch statement there, could you clarify? (wrong number of arguments, the If doesn't quite make sense) $\endgroup$ Commented Sep 26, 2013 at 19:17
  • $\begingroup$ Ok, I change the code, but I do not know where to put the Plot command for each that you can select the second PopUpMenu I plot the option chosen. $\endgroup$
    – Starlight
    Commented Sep 26, 2013 at 19:34

1 Answer 1

3
$\begingroup$

Actually, I have to admit I do not quite understand what you are aiming for, so here's a long shot...

I understand that you want to have values in the second control (selection) that do depend on the first control, x that is.

Also, based on the title, I added some plots in the PopupMenu. Looks fun.

I hope it helps in some way. The key issue is that I introduced a helper, called selChoice to keep track of the updated selection-list. selChoice has ControlType None, so you won't see it in the actual Manipulate.

a = "Algebraicas";
b = "Trigonometricas";
c = "Tercer Grado";

Module[{myPlot},
    myPlot[f_] := Plot[f[x], {x, -5, 5}];
    Manipulate[
       Switch[x,
          a, If[selection =!= None, selection = None],
          b, If[selection === None, selection = None],
          c, If[selection === None, selection = "Hola"]];
       selection,
       {x, {a, b, c}, ControlType -> PopupMenu}, 
       {{selection, None}, selChoice, ControlType -> SetterBar},
       {{selChoice,
           Which[x == a, myPlot /@ {# &, #^2 &},
              x == b, myPlot /@ {#^3 &, Abs@# &},
              x == c, myPlot /@ {Sin, Cos}]}, None}]]

Note that I have no clue what you want to do with the first Switch... and also note that I am fully aware that my functions do not quite make sense in the respective categories.

Output:

enter image description here

EDIT

Based on the comment, maybe this is more what you want (I am still not sure)

Module[{myPlot}, myPlot[f_] := Plot[f[x], {x, -5, 5}];
  Manipulate[
    myPlot@selection, 
      {x, {a, b, c}, ControlType -> PopupMenu}, 
      {{selection, None}, selChoice, ControlType -> SetterBar}, 
      {{selChoice, Which[
         x == a, {# &, #^2 &}, 
         x == b, {#^3 &, Abs@# &}, 
         x == c, {Sin, Cos}]}, None}]]
$\endgroup$
9
  • $\begingroup$ It's similar to what I want but do not want to appear in the PopupMenu graphs, oh and another question Why the first PopUp control does not work? $\endgroup$
    – Starlight
    Commented Sep 26, 2013 at 19:49
  • $\begingroup$ The first selection does not show up as plot because of the Switch in the body of the Manipulate (no idea why you have it there). You can just remove that Switch. The remove the graphs from the popup, just don't Map myPlot on it. Please let me know if that is what you are after and I shall edit my answer (just wanna make sure I correctly understand) $\endgroup$ Commented Sep 26, 2013 at 20:00
  • $\begingroup$ I don´t understand the question $\endgroup$
    – Starlight
    Commented Oct 2, 2013 at 14:56
  • $\begingroup$ @JennyOjeda: please see what I posted in the edit, let me know if this is what you want. I am afraid I also do have some problems understanding the "core" of the question $\endgroup$ Commented Oct 2, 2013 at 15:16
  • $\begingroup$ Effectively what I want,Thank you :D , but as I am new to Mathematica I have many doubts about the symbols such as @ and & to be used? I looked at the list of special characters but I mathematica solves my doubt. $\endgroup$
    – Starlight
    Commented Oct 2, 2013 at 15:43

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.