Re: Map-like behaviour for functions of more than a single argument?
- To: mathgroup at smc.vnet.net
- Subject: [mg64542] Re: [mg64519] Map-like behaviour for functions of more than a single argument?
- From: Pratik Desai <pdesai1 at umbc.edu>
- Date: Wed, 22 Feb 2006 05:58:25 -0500 (EST)
- References: <200602201129.GAA10243@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Matt wrote:
>Hello,
> I was wondering if there's a way to achieve the functionality of Map,
>but with functions of more than one argument?
>
>An example of how I'm 'working around' my perceived limitation of Map
>functionality:
>
>Clear[f, g];
>f[z_, func_] := Module[{result}, result = func[Complex[Sequence @@ z]];
>
>{Re[result], Im[result]}];
>g[z_] := f[z, #1^2 & ];
>
>
>Which, using 'g', I can use Map on a list of ordered pairs:
>
>
>g /@ {{x,y}, {x,y}, {x,y}, {x,y}, etc.}
>
>
>If I wanted to use Sin, I would redefine g as follows:
>
>
>g[z_] := f[z, Sin];
>
>
>then reapply to the list of ordered pairs. So, I'm wondering if
>there's a way to accomplish my task without the intermediary function
>definition 'g'? Also, if what I'm attempting is totally wrong, I'd
>appreciate any pointers as to the correct 'path' as well.
>
>
>Thanks,
>
>Matt
>
>
>
Here is my attempt using Table, I tested it for both the functional
form(#^2&) and symbolic forms(Sin).
In[1]:=
Clear[f,list,func]
f[z_?ListQ, func_] := Module[{list1=z},{Re[#],Im[#]}&/@
Map[func,Table[Complex[list1[[r]][[1]],list1[[r]][[2]]],{r,1,First[Dimensions[list1]],1}]]//N];
list3={{1,2},{2,4},{3,5},{7,8}}
f[list3,#^2&]
f[list3,Sin]
Out[3]=
{{1,2},{2,4},{3,5},{7,8}}
Out[4]=
{{-3.,4.},{-12.,16.},{-16.,30.},{-15.,112.}}
Out[5]=
{{3.16578,1.9596},{24.8313,-11.3566},{10.4725,-73.4606},{979.225,1123.68}}
Hope this helps
Pratik
- References:
- Map-like behaviour for functions of more than a single argument?
- From: "Matt" <anonmous69@netscape.net>
- Map-like behaviour for functions of more than a single argument?