[Date Index] [Thread Index] [Author Index]
Re: Using "=" vs ":="
The arguments of all Functions in Mathematica must be enclosed by [ ... ] not ( ... ) You should therefore have: In:= f[x_, y_]:=1-Sin[x^2+y^2] Else what Mathematica does is to treat Sin(x^2+y^2) as the variable Sin multiplied by the Expression (x^2+y^2), the latter evaluating to 5 for x=1 and y=2 Sin 5 is equivalent to 5 Sin Graham M "misha" <iamisha1 at comcast.net> wrote in message news:ehf1ks$5ds$1 at smc.vnet.net... > I'm going through Mathematic by Example, 2nd ed., (Abell and Braselton), > and have come across something that puzzles me. > > Chapter 2, Section 2, Example 8 > Define f(x,y)=1-sin(x^2+y^2) > > So I first try, > In:= f[x_, y_]:=1-Sin(x^2+y^2) > No problem so far... > Then, > In:= f[x,y] > Out:=1-Sin(x^2+y^2) > Still no problem... > Then, > In:=f[1,2] > Out:=1-5 Sin > > Huh? > > I noticed that rather than using ":=" to "simply define" this function, > as opposed to (just) "=" to "define and compute" this function, I get > different subsequent behavior. Specifically, doing the above with just > "=", works fine. > In:= f[x_, y_]=1-Sin(x^2+y^2) > .... > In:=f[1,2] > Out:=1-Sin > > My question is, Why? What's the difference between ":=" and "=" for > defining functions? > > Thanks! > Misha >