## code issue

General discussion about Mathematica features and functionality...
Forum Rules
By using the Wolfram Faculty Program Forum, you agree not to post any abusive, obscene, vulgar, slanderous, hateful, threatening, or sexually oriented material. Wolfram Faculty Program Forum administrators have the right to remove, edit, move or close any topic at any time should we see fit.

Personal Information: Posts in this forum may be viewed by non-members; however, the forum prohibits non-members from viewing your profile. Although your email address is hidden from both non-members and members, your account is initially configured to allow members to contact you via email through the forum. If you wish to hide your profile, or prohibit others from contacting you directly, you may change these settings by updating your profile through the User Control Panel.

Attachments: Attachments are not currently enabled on this forum. To share a file with others on this site, simply upload your file to the online storage service of your choice and include a link to the file within your post. If your school does not offer an online file storage and sharing service, the following sites provide free basic online file storage and sharing: Mozy, FilesAnywhere, Adrive, and KeepandShare.

### code issue

Hi folks:

I'm working on a bit of code in which I want the students to choose a trig function from a drop-down menu, and then from there have some choices for viewing the graph. All is working fine except for one thing. There are a couple of constants that depend on the function they choose from the menu, and I'm trying to define the constant based on their choice for f. The basic issue I'm having boils down to the following question:

Why doesn't this code return a 2?

m = Cos;
Which[m == Sin, 5, m == Cos, 2]

Thanks for the help!

Rob

Rob_Holman

Posts: 14
Joined: Wed Feb 29, 2012 7:03 pm
Organization: The Walker School
Department: Mathematics and Science

### Re: code issue

Try

Code: Select all
`m = Cos;Which[m === Sin, 5, m === Cos, 2]`

The expression Cos == Sin remains unevaluated (in the first test), which according to the documentation on 'Which' http://reference.wolfram.com/mathematica/ref/Which.html?q=Which means the 'Which' statement will remain unevaluated. 'SameQ' (===) always returns 'True' or 'False'.

'Equal' (==) is a funny function. 'Cos == Cos' return 'True" because they're identical. But 'Equal' won't return 'False' unless the two sides are unequal numbers or "raw data" (see http://reference.wolfram.com/mathematica/ref/Equal.html?q=Equal).

Michael_Rogers

Posts: 10
Joined: Mon May 24, 2010 3:28 pm
Organization: Emory University
Department: Oxford College