       Re: Map-like behaviour for functions of more than a single argument?

• To: mathgroup at smc.vnet.net
• Subject: [mg64528] Re: [mg64519] Map-like behaviour for functions of more than a single argument?
• From: Bob Hanlon <hanlonr at cox.net>
• Date: Mon, 20 Feb 2006 22:31:02 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```Your function f can be written in shorter form.

Clear[f,g];

f[z_,func_]:=Module[{result},
result=func[Complex[Sequence@@z]];
{Re[result],Im[result]}];

f2[z_,func_]:=Module[
{result=func[Complex@@z]},
{Re[result],Im[result]}];

f3[z_,func_]:=
{Re[#],Im[#]}&[func[Complex@@z]];

g[z_]:=f[z,#^2&];

data={{x1,y1},{x2,y2},{x3,y3},{x4,y4}};

s1=g/@data;

s2=f[#,#^2&]&/@data;

s3=f2[#,#^2&]&/@data;

s4=f3[#,#^2&]&/@data;

s1==s2==s3==s4

True

data=Table[{Random[],Random[]},{4}];

s1=g/@data;

s2=f[#,#^2&]&/@data;

s3=f2[#,#^2&]&/@data;

s4=f3[#,#^2&]&/@data;

s1==s2==s3==s4

True

Bob Hanlon

>
> From: "Matt" <anonmous69 at netscape.net>
To: mathgroup at smc.vnet.net
> Subject: [mg64528] [mg64519] Map-like behaviour for functions of more than a single
argument?
>
> 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
>
>

```

• Prev by Date: Re: Statistical Analysis & Pattern Matching
• Next by Date: Re: Re: Re: Using a text editor like interface for Mathematica?
• Previous by thread: Re: Map-like behaviour for functions of more than a single argument?
• Next by thread: Statistical Analysis & Pattern Matching