I have several lists containing variables, e.g. list1={x1,x2,x3}, list2={y1,y2,y3}, etc. I would like to define a function in those variables, i.e. f[x1,x2,x3,y1,y2,y3]. I have tried to use Do and AppendTo but this seems to reset f at every iteration. Any help is appreciated.

f@@(list1 ~Join~ list2)

Or, more generally, use @@ to "open" the structure of List:

list1 = {x1, x2, x3}; list2 = {y1, y2, y3};
f @@ (list1~Join~list2)

f[x1, x2, x3, y1, y2, y3]

For a list of lists:

listOflists = {list1, list2}
f @@ (Flatten@listOflists)

f[x1, x2, x3, y1, y2, y3]

  • $\begingroup$ Yes, it does. Thanks. I will accept your answer. $\endgroup$ – Bran Apr 2 '19 at 12:34
  • $\begingroup$ @Bran it gives exactly what you asked for, f[x1, x2, x3, y1, y2, y3]... $\endgroup$ – Kuba Apr 2 '19 at 12:35
  • $\begingroup$ @Bran I'm not understand. They are! Try it, pls. $\endgroup$ – Slepecky Mamut Apr 2 '19 at 12:36
  • $\begingroup$ @SlepeckyMamut How can I add more variables to the function not from a list? Like f[z1,z2,x1,x2,x3,y1,y2,y3]. $\endgroup$ – Bran Apr 2 '19 at 12:39
  • 1
    $\begingroup$ @Bran f[whatever, ##, whatever2]& @@ ... $\endgroup$ – Kuba Apr 2 '19 at 12:44

Not the answer you're looking for? Browse other questions tagged or ask your own question.