Re: Functional programming puzzle

• To: mathgroup at christensen.cybernetics.net
• Subject: [mg1861] Re: [mg1821] Functional programming puzzle
• From: Allan Hayes <hay%haystack at christensen.cybernetics.net>
• Date: Wed, 9 Aug 1995 22:38:06 -0400

```
"Wm. Martin McClain" <wmm at chem.wayne.edu>
wrote in [mg1821] Functional programming puzzle
Dear functional programers:

> Let ptList = {{1,1,2},{2,1,3},{1,3,2}};
>
> I want a matrix of distances between the points in ptList.
> Any human would think you could get it with
>
> Rij[a_,b_]:=Sqrt[(a-b).(a-b)]
>
> followed by
>
> Outer[Rij,ptList,ptList]
>
> But Mathematica returns a mess, because Outer seems
> to Flatten the ptList before running the outer
> product loops.
> ...................

Martin:

Outer has an optional, and apparently undocumented, final parameter
for setting the level at which it operates. Hence:

ptList = {{1,1,2},{2,1,3},{1,3,2}};

Rij[a_,b_]:=Sqrt[(a-b).(a-b)]

Outer[Rij,ptList,ptList,1]//MatrixForm

0         Sqrt[2]   2

Sqrt[2]   0         Sqrt[6]

2         Sqrt[6]   0

Allan Hayes
De Montfort University Leicester
hay at haystack.demon.co.uk

```

• Prev by Date: Axis direction
• Next by Date: Re: Math co-processor
• Previous by thread: Re: Functional programming puzzle
• Next by thread: Re: Functional programming puzzle