Re: Evaluation Question
- To: mathgroup at smc.vnet.net
- Subject: [mg76475] Re: [mg76448] Evaluation Question
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Wed, 23 May 2007 05:08:37 -0400 (EDT)
- References: <200705220656.CAA20144@smc.vnet.net>
On 22 May 2007, at 15:56, 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 > > Let's first create your list of points: points = Sort[(IntegerDigits[#1, 2, 3] & ) /@ Range[8]] {{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {0, 1, 1}, {1, 0, 0}, {1, 0, 1}, {1, 1, 0}, {1, 1, 1}} Let's define two funcitons: f[a_, b_, c_] := a + b + c g[a_, b_, c_] := a*b - c This is how you can compute the values of f at all points: f @@@ points {0, 1, 1, 2, 1, 2, 2, 3} This is how to get the values of g at all points: g @@@ points {0, -1, 0, -1, 0, -1, 1, 0} And this is how to get both the values of f and of g at once: Transpose[Apply[Through[{f, g}[##]] &, points, {1}]] {{0, 1, 1, 2, 1, 2, 2, 3}, {0, -1, 0, -1, 0, -1, 1, 0}} So you can first define your points, then a list of functions, and then use the above method to apply your list of functions to your list of points. Andrzej Kozlowski
- References:
- Evaluation Question
- From: hoffmannick <hoffmannick@gmail.com>
- Evaluation Question