MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: A short question about SetDelayed[]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg42513] RE: [mg42499] A short question about SetDelayed[]
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Sat, 12 Jul 2003 05:19:12 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

>-----Original Message-----
>From: Vadym Kulik [mailto:kulik_nospam at umn.edu]
To: mathgroup at smc.vnet.net
>Sent: Friday, July 11, 2003 8:58 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg42513] [mg42499] A short question about SetDelayed[]
>
>
>Hi guys:
>
>I work with Mathematica for 2 weeks and now I'm really stuck with the
>following problem:
>
>I'd like to generate an array of functions by the rule 
>f[i]:=g[i,x], where x
>stands for arguments some of which have been assigned 
>numerical values; i is
>an index, so that f[1]:=g[1,x], etc.
>
>Unfortunately, the following code doesn't work
>x = 5;   Do[f[i] := g[i, x], {i, 10}]
>
>... neithes does this
>x = 5;   Do[f[i] := g[Evaluate[i], x], {i, 10}]
>
>Any help?
>
>Thanks,
>Vadym
>
>

Vadym,

Not clear to me, what you want to attain, is it this:...
 
In[105]:= Clear[f]
In[106]:=
x = 5; Do[f[i] = g[i, x], {i, 3}]

In[107]:= ?f

          Global`f

          f[1] = g[1, 5]

          f[2] = g[2, 5]

          f[3] = g[3, 5]

...or this?
 
In[108]:= Clear[x, f]
In[109]:=
x = 6; Do[(f[#] := g[#, x]) &[i], {i, 3}]

In[110]:= ?f

           Global`f

           f[1] := g[1, x]

           f[2] := g[2, x]

           f[3] := g[3, x]


Why not just do

In[113]:= Clear[x, f]
In[114]:= 
x = 7; 
f[i_Integer /; 0 < i <= 3] := g[i, x]

In[116]:= f[3]
Out[116]= g[3, 7]

In[117]:= x = 8; f[2]
Out[117]= g[2, 8]


--
Hartmut Wolf


  • Prev by Date: 3 D plot
  • Next by Date: Re: Function in a package
  • Previous by thread: Re: A short question about SetDelayed[]
  • Next by thread: ListConvolve Padding Q?