Re: Using "=" vs ":="
- To: mathgroup at smc.vnet.net
- Subject: [mg70696] Re: [mg70664] Using "=" vs ":="
- From: Murray Eisenberg <murray at math.umass.edu>
- Date: Mon, 23 Oct 2006 02:51:02 -0400 (EDT)
- Organization: Mathematics & Statistics, Univ. of Mass./Amherst
- References: <200610220520.BAA04809@smc.vnet.net>
- Reply-to: murray at math.umass.edu
There's an error in your definition of f. It should be: f[x_, y_]:=1-Sin[x^2+y^2] The punctuation around the argument of Sin should be square brackets, not parentheses. For the definition you gave, both of Mathematica's outputs are correct and consistent. In fact, Sin(x^2+y^2) to Mathematica means the product of Sin and the expression x^2+y^2. So your f[x,y] showed this product again; your f[1,2] evaluated x^2+y^2 to be 5, and the product of Sin and 5 is 5 Sin. misha 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 > > -- Murray Eisenberg murray at math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305
- Using "=" vs ":="
- From: misha <email@example.com>
- Using "=" vs ":="