Rather than "assigning " indices, use the actual node positions and what
is done to make a suntraction (or other) table, which is the same proplem.
In the case of all nodes being on a line at positions 0 1.5 2 2.5 3 the
matrix would be given by
dij=: |@ -/~ 0 1.5 2 2.5 3
0 1.5 2 2.5 3
1.5 0 0.5 1 1.5
2 0.5 0 0.5 1
2.5 1 0.5 0 0.5
3 1.5 1 0.5 0
Note that if positions are on a plane, this still works- using complex
numbers to represent positions
dij 0 1.5 0j_1.5 1.5j_1.5 2j2
0 1.5 1.5 2.12132 2.82843
1.5 0 2.12132 1.5 2.06155
1.5 2.12132 0 1.5 4.03113
2.12132 1.5 1.5 0 3.53553
2.82843 2.06155 4.03113 3.53553
Don Kelly
On 2019-10-22 9:35 a.m., [email protected] wrote:
Given a fully connected graph of n nodes.
The nodes are assigned indices i.n arbitrarily.
D is a distance matrix. Eg.
n =. 4
] D =. 4 4 $ 0 1.5 2 2.5 1.5 0 1.5 2 2 1.5 0 1.5 2.5 2 1.5 0
I'm not claiming this matrix fits in Euclidean geometry.
Nevertheless each element on the diagonal is 0 and
the matrix is symmetrical.
Can anyone suggest a more efficient way to create the
matrix. Only (n * (n-1))%2 elements of D are unique.
Each unique elecment should be needed only once to build
the matrix.
Thanks, Peter E.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm