0
$\begingroup$

I am trying to reproduce the graph from an incidence matrix. For eg i have Graph[{1 \[DirectedEdge] 2, 2 -> 4, 2 \[DirectedEdge] 3, 3 \[DirectedEdge] 4, 4 \[DirectedEdge] 1}, VertexLabels -> "Name"] The graph looked like this graph1

I found out the incident matrix for the above one and i again used the "IncidenceGraph" to reproduce the graph. But the two graphs are not the same. The graph looked like this graph2 Why is this so? I am using Mathematica version 10.2

$\endgroup$
  • $\begingroup$ "I found out the incident matrix for the above one" - how does it compare to the result of IncidenceMatrix[]? $\endgroup$ – J. M.'s discontentment May 12 '16 at 2:44
2
$\begingroup$

The issue here is that for IncidenceMatrix

The vertices $v_i$ are assumed to be in the order given by VertexList[g] and the edges $e_j$ are assumed to be in the order given by EdgeList[g].

So let's look at the order of the vertices in your graph,

g = Graph[{1 \[DirectedEdge] 2, 2 -> 4, 2 \[DirectedEdge] 3, 
   3 \[DirectedEdge] 4, 4 \[DirectedEdge] 1}, VertexLabels -> "Name"]
VertexList@g

Mathematica graphics

{1, 2, 4, 3}

They are not in numeric order, but when you make an IncidenceGraph the original vertex list from g is not passed, and so they are relabeled in numeric order

VertexList@IncidenceGraph@IncidenceMatrix@g

{1, 2, 3, 4}

The solution is simply to use the 2-argument form of IncidenceGraph and pass the VertexList as the first argument

IncidenceGraph[VertexList@g, IncidenceMatrix[g], 
 VertexLabels -> "Name"]

Mathematica graphics

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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