A simple digraph g
:
ClearAll[g];
g = Graph[{
1 -> 2, 1 -> 4, 1 -> 5, 2 -> 3, 2 -> 5,
3 -> 1, 3 -> 5, 3 -> 9, 4 -> 2, 4 -> 7,
5 -> 6, 6 -> 2, 6 -> 8, 7 -> 5, 8 -> 1,
8 -> 9, 9 -> 4, 9 -> 7
}, DirectedEdges -> True, VertexLabels -> "Name"];
This results in an apparently incorrect Adjacency Matrix:
AdjacencyMatrix[g]//MatrixForm
{
{0, 1, 1, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 1, 1, 0, 0, 0, 0},
{0, 1, 0, 0, 0, 0, 1, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 1, 0},
{1, 0, 0, 1, 0, 1, 0, 0, 0},
{0, 0, 1, 0, 0, 0, 1, 0, 0},
{0, 0, 0, 1, 0, 0, 0, 0, 0},
{0, 1, 0, 0, 0, 0, 0, 0, 1},
{1, 0, 0, 0, 0, 1, 0, 0, 0}
}
This adjacency matrix is not what I expected: it seems that many edges are not correctly identified in the adjacency matrix. For instance, in my graph there is no edge from vertex 1 to 3, but I see a $1$ in the (1,3) element of the adjacency matrix. There are several other edges that appear incorrectly mapped in the matrix.
I suspect that the vertices are labeled in a way I do not understand. What am I misinterpreting?
1
in the element(1,3)
of the matrix. There are several other edges not correctly mapped in the matrix. $\endgroup$VertexList[g]
and remember that in general, vertex4
is not the 4th vertex. Vertex name != vertex index. $\endgroup$AdjacencyGraph[ the matrix you find ]
you'll see a picture indistinguishable from your originalg
. $\endgroup$