Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Bear with me, I'm a noob; I simply want to create a radio button bar that selects whether I want to add or subtract two numbers:

{RadioButtonBar[Dynamic[stringvar], {"*" -> "Multiply Numbers", "+" -> "Add Numbers"}]}

And my equation might simply be:

2 + 2

And I just want to change the + to a * interactively. Not sure if this is the right way to do it. Thanks.

share|improve this question
Create a Dynamic variable that is the Head of an expression, and can take the values Plus or Times – Verbeia Apr 19 '13 at 14:02
up vote 5 down vote accepted

From the documentation:

Manipulate[operator[x, y], 
 {{x, 2}, InputField}, 
 {{y, 2}, InputField}, 
 {operator, {Plus, Times, Subtract, Divide}}, 
 SaveDefinitions -> True]


share|improve this answer


 {Row[{InputField[Dynamic[x]], InputField[Dynamic[y]]}],
   Dynamic[op], {Times -> "Multiply Numbers", 
    Plus -> "Add Numbers"}],
  Dynamic@op[x, y]

enter image description here

Notice how code and data are the same thing in Mathematica, so I can use the fact that the operators Plus and Times can be stored in variables to construct the interface.

You can also use arbitrary dynamic controls here

 {Column[{InputField[Dynamic[x]], InputField[Dynamic[y]]},
   Frame -> True,
   FrameStyle -> Directive[Orange, Thick, Dashed]],
  PopupMenu[Dynamic[op], {Plus, Times, Subtract, Divide}],
  Dynamic@op[x, y]

enter image description here

share|improve this answer
you're quick today, I just copied mine :) – cormullion Apr 19 '13 at 14:02
I just happened to come here when the question was asked :) – acl Apr 19 '13 at 14:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.