Re: setting discrete values for a function -- newbie
- To: mathgroup at smc.vnet.net
- Subject: [mg97644] Re: setting discrete values for a function -- newbie
- From: Szabolcs Horvát <szhorvat at gmail.com>
- Date: Tue, 17 Mar 2009 05:03:41 -0500 (EST)
- References: <gpld42$qj5$1@smc.vnet.net>
Karsten W. wrote: > Hello, > > my task is to set some function values f[[a], f[b], ... to zero. Is > there a nicer way to do this than this one: > > Clear[f]; > args = Partition[{a,b,c}, 1]; > Apply[(f[#] = 0 )&, args, {1}]; > > Especially, can I avoid calling Partition? > Map is what you need, not Apply: (f[#] = 0) & /@ {a, b, c} Or perhaps Scan is more appropriate (since we don't care about the return values): Scan[(f[#] = 0) &, {a, b, c}] Yet another possibility is f[x_] /; MemberQ[{a, b, c}, x] = 0