2
$\begingroup$

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.

$\endgroup$

closed as off-topic by MarcoB, m_goldberg, Alex Trounev, Carl Lange, eyorble Apr 8 at 17:21

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – MarcoB, m_goldberg, Alex Trounev, Carl Lange, eyorble
If this question can be reworded to fit the rules in the help center, please edit the question.

7
$\begingroup$
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]

$\endgroup$
  • $\begingroup$ Yes, it does. Thanks. I will accept your answer. $\endgroup$ – Bran Apr 2 at 12:34
  • $\begingroup$ @Bran it gives exactly what you asked for, f[x1, x2, x3, y1, y2, y3]... $\endgroup$ – Kuba Apr 2 at 12:35
  • $\begingroup$ @Bran I'm not understand. They are! Try it, pls. $\endgroup$ – Slepecky Mamut Apr 2 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 at 12:39
  • 1
    $\begingroup$ @Bran f[whatever, ##, whatever2]& @@ ... $\endgroup$ – Kuba Apr 2 at 12:44

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