|
[Date Index]
[Thread Index]
[Author Index]
Re: Using "=" vs ":="
- To: mathgroup at smc.vnet.net
- Subject: [mg70697] Re: Using "=" vs ":="
- From: Peter Pein <petsie at dordos.net>
- Date: Mon, 23 Oct 2006 02:51:08 -0400 (EDT)
- References: <ehf1ks$5ds$1@smc.vnet.net>
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...
> 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?
>
> 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?
>
> Thanks!
> Misha
>
Hi Misha,
try to use Mathematica syntax while using Mathematica. Sin is just a
variable (multilyed by x²+y²) in your example.
The second part of your posting is inconsistent:
Out[3] should be 1-5 Sin, if you entered f[x_,y_]=1-Sin(x²+y²)
In[1]:= f[x_,y_]:=1-Sin[x^2+y^2] (* "=" or ":=" doesn't matter in this
case *)
In[2]:= f[1,2]
Out[2]= 1-Sin[5]
Peter
P.S.: if you don't have access to brackets on your keyboard either buy a
new one or use Sin@(x²+y²). ;-)
Prev by Date:
Re: Using "=" vs ":=" [Thanks!]
Next by Date:
Re: Re: Wolfram Workbench
Previous by thread:
Re: Using "=" vs ":="
Next by thread:
Re: Using "=" vs ":="
|