Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Here is an undirected graph

  m = Graph[{1 \[UndirectedEdge] 3, 2 \[UndirectedEdge] 3, 
   3 \[UndirectedEdge] 4, 4 \[UndirectedEdge] 5, 
   4 \[UndirectedEdge] 6, 5 \[UndirectedEdge] 7, 
   6 \[UndirectedEdge] 8}, GraphLayout -> "SpringEmbedding", 
  VertexLabels -> "Name", ImagePadding -> 10]

We can get the Adjacency Matrix as follows

g = AdjacencyMatrix[m]

The Normal Form of the sparse array g is as follows.

In[28]:= Normal[g]

Out[28]= {{0, 1, 0, 0, 0, 0, 0, 0}, {1, 0, 1, 1, 0, 0, 0, 0}, {0, 1, 
  0, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 1, 1, 0, 0}, {0, 0, 0, 1, 0, 0, 1, 
  0}, {0, 0, 0, 1, 0, 0, 0, 1}, {0, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0,
   0, 1, 0, 0}}

The adjacency matrix does not appear to be correct for the graph m.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

The ordering of the vertices used for AdjacencyMatrix is that given in VertexList[m]:

ordering={1, 3, 2, 4, 5, 6, 7, 8}

Thus, while it looks like the adjacency matrix is saying that 1 and 2 are joined. If you look at the ordering in VertexList You'll see that the second element is actually node number 3.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.