MathGroup Archive 2006

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

Search the Archive

Re: distance function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg68772] Re: distance function
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Fri, 18 Aug 2006 03:12:20 -0400 (EDT)
  • References: <200608160736.DAA06170@smc.vnet.net> <ec1aub$ou9$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Murray,

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

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

Regards
   Jens


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 yahoo.com 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