Here is how I would get your adjacency matrix (called connection matrix below).
pairs =: [: ,/ [: (2 ,/\ ])"1 (, |:) NB. Constructs left-right and up-down
arcs
CM=: #. e.~ [: i. [ , [ NB. Borrowed from 20. Directed Graphs in Dictionary
cmfp=: 3 : '(+. |:) (>:>./,y) CM y' NB. Symmetric connection matrix from
pairs
i. 3 3 NB. numerical version of your ABCDEFGHI square
0 1 2
3 4 5
6 7 8
pairs i. 3 3 NB. left-right and up-down arcs
0 1
1 2
3 4
4 5
6 7
7 8
0 3
3 6
1 4
4 7
2 5
5 8
cmfp pairs i. 3 3 NB. Symmetric connection matrix
0 1 0 1 0 0 0 0 0
1 0 1 0 1 0 0 0 0
0 1 0 0 0 1 0 0 0
1 0 0 0 1 0 1 0 0
0 1 0 1 0 1 0 1 0
0 0 1 0 1 0 0 0 1
0 0 0 1 0 0 0 1 0
0 0 0 0 1 0 1 0 1
0 0 0 0 0 1 0 1 0
NB. Rows and columns are numbered 0 to 8 in this 9 by 9 matrix
NB. cfmp pairs i. 4 4 deals with 4 by 4 case
Kip Murray
Sent from my iPad
On Feb 24, 2013, at 6:21 AM, alessandro codenotti <[email protected]> wrote:
>
> I had this network problem to solve and i wrote the code to do it, everything
> was fine until i noticed i wasn't able to compute the adjacency matric to
> work on!
>
> the network is a square network where every node is connected to is
> neighbours, for the 3x3 case it looks like this:
>
> A----B----C
> | | |
> D----E----F
> | | |
> G----H----I
>
> where A,B,C...,I are the 9 nodes and the corresponding adjacency matrix can
> be easily obtained by hand, however i have to work on different networks of
> different sizes, but they are all squares and all connected like that.
> My question then is more a maths question than a programming one (well, is
> there any J programmer that doesn't love maths?), if i need the adjacency
> matrich of such networks, is there an easy way to find it knowing the
> propertiese of the network given above? and how can i do it in J?
>
> thank in advice for the help!
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm