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.
$\begingroup$
$\endgroup$
Add a comment
|
1 Answer
$\begingroup$
$\endgroup$
6
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– Bran2019-04-02 12:34:05 +00:00Commented Apr 2, 2019 at 12:34
-
$\begingroup$ @Bran it gives exactly what you asked for,
f[x1, x2, x3, y1, y2, y3]... $\endgroup$Kuba– Kuba2019-04-02 12:35:33 +00:00Commented Apr 2, 2019 at 12:35 -
$\begingroup$ @Bran I'm not understand. They are! Try it, pls. $\endgroup$Slepecky Mamut– Slepecky Mamut2019-04-02 12:36:15 +00:00Commented Apr 2, 2019 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– Bran2019-04-02 12:39:20 +00:00Commented Apr 2, 2019 at 12:39 -
1$\begingroup$ @Bran
f[whatever, ##, whatever2]& @@ ...$\endgroup$Kuba– Kuba2019-04-02 12:44:57 +00:00Commented Apr 2, 2019 at 12:44