MathGroup Archive 2006

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

Search the Archive

Re: distance function

  • To: mathgroup at
  • Subject: [mg68728] Re: [mg68686] distance function
  • From: Murray Eisenberg <murray at>
  • Date: Thu, 17 Aug 2006 04:18:35 -0400 (EDT)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <>
  • Reply-to: murray at
  • Sender: owner-wri-mathgroup at

If you don't mind an "extravagant" solution -- one that is conceptually 
simple and short but is probably inefficient due to redundant 
calculations -- then this works, I believe:

   d[{p_, q_}] := Norm[p - q]
   allDistances[pts_] := Union[Flatten[Outer[d, pts, pts]]]

dimmechan at wrote:
> In the book of Gaylord et al. (1996) there is one exercise which asks
> (see page 113)
> "Given a list of points in the plane, write a function that finds the
> set of all distances
> between the points."
> Although there is one solution, that solution makes use of the Table
> and Length commands.
> Is it a way to define the same function using Higher-Order functions
> like Outer, MapThread etc?
> Thanks in advance for any help.

Murray Eisenberg                     murray at
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305

  • Prev by Date: Re: namespace collision [bug]
  • Next by Date: RE: perplexed by blank sequence in pattern replacement
  • Previous by thread: distance function
  • Next by thread: Re: distance function