3

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.

Starlight
  • 57
  • 6
  • 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) – Pinguin Dirk Sep 26 '13 at 19:17
  • 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. – Starlight Sep 26 '13 at 19:34

1 Answers1

3

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}]]
Pinguin Dirk
  • 6,519
  • 1
  • 26
  • 36
  • 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? – Starlight Sep 26 '13 at 19:49
  • 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) – Pinguin Dirk Sep 26 '13 at 20:00
  • I don´t understand the question – Starlight Oct 02 '13 at 14:56
  • @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 – Pinguin Dirk Oct 02 '13 at 15:16
  • 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. – Starlight Oct 02 '13 at 15:43
  • @JennyOjeda: perfect. Have a look at e.g. http://mathematica.stackexchange.com/questions/18393/what-are-the-most-common-pitfalls-awaiting-new-users/25616#25616, especially that answer and also all the others. There are many questions here that aim at that direction. Good luck! – Pinguin Dirk Oct 02 '13 at 15:57
  • Hello again and understanding that means # is used as a variable but takes value of 1, @ is a prefix and & concatenate, but I'm trying to get in equation appears as SetterBar generally TraditionalForm see in class and effectively if but now I get graph, also have declared the function before the code and I get exactly the same, what I intend to do is that in the equation for setterBar subsequently appears to change values ​​and thus move my graph. – Starlight Oct 02 '13 at 16:28
  • I am afraid I don't understand. You lost me after "&". All I can say: # is Slot, and is used together with & to create pure function. See the respective documentation. Thus, & is not used to concatenate stuff. The rest, I don't understand (the language that is, sorry) – Pinguin Dirk Oct 02 '13 at 16:35
  • I understood a little more about the special characters in Mathematica, but I want to do is to plot the function parameters will be moved. – Starlight Oct 02 '13 at 20:29