MathGroup Archive 2007

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

Search the Archive

Re: Evaluation Question


Hi,

an easy way to do it is to define your functions as

f[{a_, b_, c_}] := a + b + c

instead of

f[a_, b_, c_] := a + b + c

notice the {,} that exist in the new function. Then if the data are

data = {{1, 0, 0}, {1, 0, 0}, {1, 1, 0}, {1, 0, 0}, {1, 0, 1}, {1, 1,
0}, {1, 1, 1}};

You can evaluate all 7 sets at once by typing

f[data[[#]]] & /@ Range[Length[data]]

or if you feel uncomfortable with functional programming (search for
Functional programming in the Master Index) use a Table:

Table[f[data[[i]]], {i, 1, 7}]

The result in both cases is of course the same:

{1, 1, 2, 1, 2, 2, 3}

Cheers,
psycho_dad



  • Prev by Date: Re: Plot[], Show[] and ; in Version 6
  • Next by Date: Re: Compatibility woes
  • Previous by thread: Re: Evaluation Question
  • Next by thread: Re: Evaluation Question