MathGroup Archive 2008

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

Search the Archive

Re: How to plot a graph, using a distance matrix

  • To: mathgroup at smc.vnet.net
  • Subject: [mg89034] Re: [mg88993] How to plot a graph, using a distance matrix
  • From: Daniel Lichtblau <danl at wolfram.com>
  • Date: Sat, 24 May 2008 03:53:50 -0400 (EDT)
  • References: <200805230707.DAA25775@smc.vnet.net>

Eric Heiman wrote:
> My dilemna is as such:
> 
> I have a matrix (it happens to be 21x21, but don't worry about that) which contains distances between points.
> So column 1 has distances from point 1 to every other point, with row 1 being 0 (because the distance to itself is zero).
> 
> What I am wondering is how I would be able to get mathematica to plot a graph of these points.
> 
> Thanks in advance!

You can use ListPlot, once you have good placement of the points. To get 
this you might proceed as follows.

Put your first point at the origin, and your second point on the 
positive x axis, with coordinate specified by mat[[1,2]] (call the 
coordinates {x2,0} for use below. That is, x2=mat[[1,2]]). Give your 
third point the positive y3 solution to the two equations given by

Norm[{x3,y3}]^2 - mat[[1,3]]^2 == 0
Norm[{x3,y3}-{x2,0}]^2 - mat[[2,3]] == 0

You now have located three points. For subsequent points 3<j<=21 you 
would do similarly, in first solving pairs of quadratics

Norm[{xj,yj}]^2 - mat[[1,j]]^2 == 0
Norm[{xj,yj}-{x2,0}]^2 - mat[[2,j]] == 0

Of the two solutions, take the one that comes closest to making the 
distances to already placed points correct.

If you require really careful layout you might use the point coordinates 
as found above as initial values for a least squares optimization. Once 
you place those first two points, your other distances give an 
overdetermined system of equations (171, if I am counting correctly) in 
38 unknowns.

Daniel Lichtblau
Wolfram Research


  • Prev by Date: Re: Sluggish performance in Save, bug?
  • Next by Date: Re: Re: Color space conversion in Mathematica v6.0
  • Previous by thread: How to plot a graph, using a distance matrix
  • Next by thread: Re: How to plot a graph, using a distance matrix