Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm trying to use Mathematica to evaluate many values of $f(x,y) $, like $f(-\pi,\pi) $ for

$$f(x,y) = \left( \frac{-1}{4}\sin \left( \frac{x-y}{2} \right)\sin y \right)\left( \frac{-5}{4}\sin \left( \frac{x-y}{2} \right)\sin y-\cos \left( \frac{x-y}{2} \right)\cos y \right) \\-\frac{1}{4}\left( \sin \left( \frac{x-y}{2} \right)\sin y+\cos \left( \frac{x-y}{2} \right)\cos y \right).$$

So I input :

f[x_, y_] := ((-1/4) sin[(x - y/2)] sin[y]) 
             ((5/4) sin[(x - y/2)] sin[y] - (-1/4) cos[(x - y/2)] cos[y]) 
             - (1/4) (sin[(x - y/2)] sin[y] + cos[(x - y/2)] cos[y])


f[-\[Pi], \[Pi]]

Mathematica then outputs :

1/4 (-cos[-((3 \[Pi])/2)] cos[\[Pi]] - 
    sin[-((3 \[Pi])/2)] sin[\[Pi]]) - 
 1/4 sin[-((3 \[Pi])/
    2)] sin[\[Pi]] (1/4 cos[-((3 \[Pi])/2)] cos[\[Pi]] + 
    5/4 sin[-((3 \[Pi])/2)] sin[\[Pi]])

But I want my final answer to be a number. Why didn't Mathematica evaluate the trigonometric functions? Thank you.

share|improve this question

closed as too localized by Mr.Wizard Jan 9 '13 at 7:11

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

I changed some "=" to "-" in the first formula but otherwise left it alone, even though it disagrees with your Mathematica input in quite a few places. You might want to check that you typed the correct formula into MMA. In particular, the two of you may disagree sharply about the interpretation of "x-y/2", because it rarely equals $\frac{x-y}{2}$. –  whuber Jan 9 '13 at 0:13

1 Answer 1

up vote 3 down vote accepted

It works for me on V 9

f[x_, y_] := ((-1/4) Sin[(x - y/2)] Sin[y]) ((5/4) Sin[(x - y/2)] Sin[y] - 
             (-1/4) Cos[(x - y/2)] Cos[y]) - (1/4) (Sin[(x - y/2)] Sin[y] + 
             Cos[(x - y/2)] Cos[y])

In[45]:= f[-Pi, Pi]
Out[45]= 0

(ps. it helped to write Sin instead of sin and Cos instead of cos :)

Mathematica's commands, symbols and functions start with UpperCase. You are on the right track of using lowerCase, but you should do that for your own variables and symbols, not for what is meant to be Mathematica's own.


 Length@Cases[UpperCaseQ[#] & /@ StringTake[Names["System`*"], 1], True]

But almost all those which are not UpperCase are actually these strange symbols and they do not really count:

Mathematica graphics

So you can see, that Mathematica uses UpperCase first letter for its own use, which is a good thing.

share|improve this answer
Thanks a lot! I can't believe I spent an hour because I didn't realize Upper Case Was Necessary. –  dresserse Jan 9 '13 at 0:04
You could have asked WolframAlpha: f[x_, y_] = ReleaseHold@ WolframAlpha[ "((-1/4) sin[(x-y/2)] sin[y]) ((5/4) sin[(x-y/2)] sin[y]-(-1/4) \ cos[(x-y/2)] cos[y])-(1/4) (sin[(x-y/2)] sin[y]+cos[(x-y/2)] \ cos[y])", {{"Input", 1}, "Input"}] Also just WolframAlpha["((-1/4) sin[(x-y/2)] sin[y]) ((5/4) sin[(x-y/2)] \ sin[y]-(-1/4) cos[(x-y/2)] cos[y])-(1/4) (sin[(x-y/2)] \ sin[y]+cos[(x-y/2)] cos[y])"] gives a nice overview of your function –  Rolf Mertig Jan 9 '13 at 0:05

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