AW: Applying multiple functions to multiple sets of arguments
- To: mathgroup at smc.vnet.net
- Subject: [mg42644] AW: [mg42608] Applying multiple functions to multiple sets of arguments
- From: Matthias.Bode at oppenheim.de
- Date: Sat, 19 Jul 2003 03:19:28 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Hello Rishi,
try:
INPUT:
f[1][x_] = x^2;
f[2][x_] = Sqrt[x];
f[3][x_] = x/2;
lst[1] = {{1, 4, 9}, {25, 36, 49}};
lst[2] = {10, 20, 30};
Clear[n, r]
Table[f[n][lst[r]], {n, 1, 3}, {r, 1, 2}]
OUTPUT:
{{{{1, 16, 81}, {625, 1296,
2401}}, {100, 400,
900}}, {{{1, 2, 3},
{5, 6, 7}}, {Sqrt[10],
2*Sqrt[5], Sqrt[30]}},
{{{1/2, 2, 9/2}, {25/2, 18,
49/2}}, {5, 10, 15}}}
Best regards,
Matthias Bode.
-----Ursprüngliche Nachricht-----
Von: rishiroy at umich.edu [mailto:rishiroy at umich.edu]
Gesendet: Freitag, 18. Juli 2003 11:25
An: mathgroup at smc.vnet.net
Betreff: [mg42608] Applying multiple functions to multiple sets of
arguements
Hi all. I was hoping someone cold help me. I wanted a way to apply
an arbitrary number of functions to an arbitrary number of sets of
arguments.
Meaning if I have n functions: {f1, f2, ...,fn} and m sets of
arguments: {x1, x2, ..., xm}, how can I generate a list like:
{{f1[x1], f1[x2], ...,f1[xm]},{f2[x1], f2[x2],
.....,f2[xm]},...,{fn[x1], fn[x2], ...,fn[xm]}}?
I am currently doing this by looping throgh both lists and populating
each results one by one. As expecting this is horribly slow. I was
hoping someone could recommend a faster, functional way to do this. I
tried using map, but couldnt get a handle on it.
Any help would be greatly appreciated. Thank you in advance.
Rishi Roy