       Re: Fuction definition

• To: mathgroup at smc.vnet.net
• Subject: [mg73672] Re: [mg73635] Fuction definition
• From: Murray Eisenberg <murray at math.umass.edu>
• Date: Sat, 24 Feb 2007 02:18:46 -0500 (EST)
• Organization: Mathematics & Statistics, Univ. of Mass./Amherst
• References: <200702230942.EAA17911@smc.vnet.net>

```If you study the documentation about =: (SetDelayed) you will see that
the expression on its right in p Sin[Pi x], for example, is evaluated
not when you make the definition but rather when you subsequently
evaluate an expression involving the left-hand side f2[x].

In your example, you don't ask for f1[0.5] until AFTER you have
evaluated p = 2 (where = is Set).  Unless and until you change the value
of p, it will keep the value of 2, and so evaluating f1[0.5] is the same
thing as evaluating 2 Sin[Pi 2].

bar at ANTYSPAM.ap.krakow.pl.math.umass.edu wrote:
> Hi
>
> When I try :
> ------------------
> p = 1;
> f1[x_] := p Sin[Pi x];
> p = 2;
> f2[x_] := p Sin[Pi x];
>
> f1[0.5]
> f2[0.5]
>
> Out=2.
>
> Out=2.
> -----------------
> When I use = instead of := it works OK.
> Why ?
>
> It is safely to use "=" in function definition ?
>
> I have to integrate and differentiate such function in the future.
> In my case function depends on about 20 parameters, which are calculated
> three times, (I want to obtain three functions)
>
> I'm not sure is this good idea to use '=' ?
>
> Regards , Olaf
>
>
>

--
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

```

• Prev by Date: Re: Find index of maximal element in multi-dimensional array
• Next by Date: Re: Neural Networks add-on
• Previous by thread: Re: Fuction definition
• Next by thread: Re: Re: Fuction definition