MathGroup Archive 1995

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Functional programming puzzle



"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