Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*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 smc.vnet.net
  • Subject: [mg68826] Re: distance function
  • From: "Dana DeLouis" <dana.del at gmail.com>
  • Date: Sun, 20 Aug 2006 04:43:44 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

> "Given a list of points in the plane, write a function that finds the

> set of all distances

> between the points."

 

Just something different.  For a small number of points, if you wish to draw
a graph, here's one way.

The function "GetEdgeWeights" will list all the distances also.

 

In[1]:=

Needs["DiscreteMath`Combinatorica`"]

 

In[2]:=

pts = {{0, 0}, {3, 0}, {5, 3}, {1, 5}}; 

 

In[3]:=

Dist = Norm /@ Apply[Subtract, KSubsets[pts, 2], {1}]

 

In[4]:=

g = ChangeVertices[CompleteGraph[Length[pts]], pts]; 

g = SetEdgeWeights[g, WeightingFunction -> Euclidean]; 

GetEdgeWeights[g]

 

In[7]:=

ShowGraph[g, GridLines -> Automatic, 

  VertexNumber -> True, 

  EdgeLabel -> Dist];

 

 

> 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?




  • Prev by Date: RE: combinatorica documentation
  • Next by Date: Problem with NMaximize
  • Previous by thread: Re: distance function
  • Next by thread: Product over an arbitrary index.