Re: Map-like behaviour for functions of more than a single argument?
- To: mathgroup at smc.vnet.net
- Subject: [mg64539] Re: Map-like behaviour for functions of more than a single argument?
- From: Bill Rowe <readnewsciv at earthlink.net>
- Date: Mon, 20 Feb 2006 22:31:18 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
On 2/20/06 at 6:29 AM, anonmous69 at netscape.net (Matt) wrote: >I was wondering if there's a way to achieve the functionality of Map, >but with functions of more than one argument? Yes, several different ways. >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.} The same output can be obtained with MapThread as follows: MapThread[Complex[Sequence@##]^2&, Transpose[data]] where data = {{x,y}, {x,y}, {x,y}, {x,y}, etc.} Note, this could also be done as: MapThread[Complex[#1,#2]^2&, Transpose[data]] which I think is a bit more clear as to what is being done. But the most compact way I know to get the same result would be: (Complex@@@data)^2 Written less compactly, this last is Apply[Complex, data, {1}]^2 And using this method, I could use Sin as follows: Sin[Complex@@@data] -- To reply via email subtract one hundred and four