# Incidence matrix not reproducing the graph

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 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 Why is this so? I am using Mathematica version 10.2

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

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 {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"] 