Re: Using "=" vs ":="
- To: mathgroup at smc.vnet.net
- Subject: [mg70690] Re: [mg70664] Using "=" vs ":="
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Mon, 23 Oct 2006 02:50:38 -0400 (EDT)
- Reply-to: hanlonr at cox.net
In either case, the definition of f should use square brackets for the Sin function. As shown in your output, you multiplied Sin times (x^2 + y^2) Clear[f]; f[x_, y_]:=1-Sin[x^2+y^2]; f[1,2] 1 - Sin Look in the Help browser for Set (=) and SetDelayed (:=) Bob Hanlon ---- misha <iamisha1 at comcast.net> wrote: > 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 > -- Bob Hanlon hanlonr at cox.net