Re: Using "=" vs ":="
- To: mathgroup at smc.vnet.net
- Subject: [mg70692] Re: Using "=" vs ":="
- From: Dave Seaman <dseaman at no.such.host>
- Date: Mon, 23 Oct 2006 02:50:50 -0400 (EDT)
- Organization: Information Technology at Purdue
- References: <ehf1ks$5ds$1@smc.vnet.net>
On Sun, 22 Oct 2006 06:04:12 +0000 (UTC), 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[1]:= f[x_, y_]:=1-Sin(x^2+y^2) > No problem so far... Actually, there's a problem. Function evaluation is represented by square brackets in Mathematica, not by parentheses. What you wrote involves multiplication of a simple variable called Sin by the expression (x^2+y^2). > Then, > In[2]:= f[x,y] > Out[2]:=1-Sin(x^2+y^2) > Still no problem... > Then, > In[3]:=f[1,2] > Out[3]:=1-5 Sin > Huh? It's exactly what you told it, since (x^2+y^2) evaluates to 5 here. > 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[1]:= f[x_, y_]=1-Sin(x^2+y^2) > .... > In[3]:=f[1,2] > Out[3]:=1-Sin[5] > My question is, Why? What's the difference between ":=" and "=" for > defining functions? There is a difference, but I don't think it's relevant to your question. Try it with square brackets and then with parentheses, and compare results. -- Dave Seaman U.S. Court of Appeals to review three issues concerning case of Mumia Abu-Jamal. <http://www.mumia2000.org/>