Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: distance function

  • To: mathgroup at
  • Subject: [mg68772] Re: distance function
  • From: Jens-Peer Kuska <kuska at>
  • Date: Fri, 18 Aug 2006 03:12:20 -0400 (EDT)
  • References: <> <ec1aub$ou9$>
  • Sender: owner-wri-mathgroup at

Hi Murray,

at least you should compute the distances not twice
because the matrix is symmetric with zero diagonal ...

d[{q_,p_}]/; OrderedQ[{q,p}]:=d[{q,p}]= Norm[p - q]


Murray Eisenberg wrote:
> 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.

  • Prev by Date: Re: product formula in mathematica
  • Next by Date: Re: "Skip this Input cell" module?
  • Previous by thread: Re: distance function
  • Next by thread: Re: Re: distance function