Re: Evaluation Question
- To: mathgroup at smc.vnet.net
- Subject: [mg76523] Re: Evaluation Question
- From: Szabolcs <szhorvat at gmail.com>
- Date: Wed, 23 May 2007 05:33:29 -0400 (EDT)
- Organization: University of Bergen
- References: <f2u57d$k2n$1@smc.vnet.net>
hoffmannick wrote: > Can anyone help me solve the following problem? > > I have a function of 3 variables, let's say > f[a_, b_, c_] = a + b + c > > Now I need to evaluate the function at some given points. To evaluate > at a single point I would do > f[0,0,1] > > For the point (0,0,1) > > Now here is the main question. > I need to evaluate this function at the points (0,0,0) through (1,1,1) > That would be the points: > 0,0,0 > 0,0,1 > 0,1,0 > 0,1,1 > 1,0,0 > 1,0,1 > 1,1,0 > 1,1,1 > > I'm testing these for approx 32 different functions. Is there an easy > way that I can define the function and then have it test all the > points for me? It will always be those finite points listed above. > > I looked into the mathematica documentation and it said how to do this > with a function of a single variable, but it didn't say how to do it a > function of more than one variable. > > I really appreciate your help Use Apply[] at level 1 of the list of argument-triples (look up the third argument of Apply in the docs). Apply[f, IntegerDigits[Range[2^3]-1, 2, 3], 1] or f @@@ IntegerDigits[Range[2^3]-1, 2, 3] If you have many functions, f, g, h etc., use (# @@@ IntegerDigits[Range[2^3] - 1, 2, 3]) & /@ {f, g, h} Or if you found out how to do it for a function of a single variable (I think you mean Map[]), you could define f to be such a function: f[{a_, b_, c_}] := a + b + c Now you can use /@ (Map) instead of @@@ (Apply) (# /@ IntegerDigits[Range[2^3] - 1, 2, 3]) & /@ {f, g, h} Szabolcs