RE: Applying multiple functions to multiple sets of arguements
- To: mathgroup at smc.vnet.net
- Subject: [mg42661] RE: [mg42608] Applying multiple functions to multiple sets of arguements
- From: "David Park" <djmp at earthlink.net>
- Date: Sat, 19 Jul 2003 03:19:46 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Rishi, Use Outer Outer[#1[#2] &, {f1, f2, f3, f4}, {x1, x2, x3, x4}] {{f1[x1], f1[x2], f1[x3], f1[x4]}, {f2[x1], f2[x2], f2[x3], f2[x4]}, {f3[x1], f3[x2], f3[x3], f3[x4]}, {f4[x1], f4[x2], f4[x3], f4[x4]}} For multiple arguments... Outer[#1 @@ #2 &, {f1, f2, f3, f4}, {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}}, 1] {{f1[x1, y1], f1[x2, y2], f1[x3, y3], f1[x4, y4]}, {f2[x1, y1], f2[x2, y2], f2[x3, y3], f2[x4, y4]}, {f3[x1, y1], f3[x2, y2], f3[x3, y3], f3[x4, y4]}, {f4[x1, y1], f4[x2, y2], f4[x3, y3], f4[x4, y4]}} Functional programming commands like Outer are generally much more powerful, more efficient, and easier to understand than procedural programming with loops - once you get the hang of them. David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Rishi Roy [mailto:rishiroy at umich.edu] To: mathgroup at smc.vnet.net 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