Create Incidence matrix from Graph theory?

조회 수: 16 (최근 30일)
Sonakshi Dua
Sonakshi Dua 2020년 8월 20일
댓글: Sonakshi Dua 2020년 8월 20일
How do I create the Incidence Matrix from the given graph?
I tried the following code, but the incidence matrix formed is completly wrong:
G=digraph( [ 1 2 2 2 3 4] , [4 1 3 4 1 3]);
I=incidence(G);
The nodes are 1, 2 ,3 and 4.

채택된 답변

Binbin Qi
Binbin Qi 2020년 8월 20일
ok
>> G=digraph( [ 1 2 2 2 3 4] , [4 1 3 4 1 3]);
>> I = full(incidence(G))
I =
-1 1 0 0 1 0
0 -1 -1 -1 0 0
0 0 1 0 -1 1
1 0 0 1 0 -1

추가 답변 (2개)

Steven Lord
Steven Lord 2020년 8월 20일
The incidence matrix you posted in your comment on Binbin Qi's answer is not the correct incidence matrix for the digraph you provided in your original message.
The first column of your incidence matrix indicates the digraph has an edge from 3 to 4. Your digraph has an edge from 4 to 3, but not one from 3 to 4.
The second column indicates an edge from 3 to 2. You have an edge from 2 to 3.
Column 4 is correct; it indicates one of the edges is from 2 to 4 and that edge is indeed included in the digraph.
I think you may be using a different convention from the incidence function for digraph objects. From its documentation page " If s and t are the node IDs of the source and target nodes of the jth edge in G, then I(s,j) = -1 and I(t,j) = 1." You seem to be using 1 for the source and -1 for the target (except for in column 4.) If you want to use that convention, multiply the matrix returned by incidence by -1.
The columns of the incidence matrix you posted are also in a different order than the one returned by incidence, which returns them in the order in which the edges are stored in the Edges property in the digraph.
  댓글 수: 1
Sonakshi Dua
Sonakshi Dua 2020년 8월 20일
Okay Okay, I understood I had been taking the wrong convention. Thank You for the help.

댓글을 달려면 로그인하십시오.


Binbin Qi
Binbin Qi 2020년 8월 20일
>> G=digraph( [ 1 2 2 2 3 4] , [4 1 3 4 1 3]);
>> full(G.adjacency)
ans =
0 0 0 1
1 0 1 1
1 0 0 0
0 0 1 0
  댓글 수: 1
Sonakshi Dua
Sonakshi Dua 2020년 8월 20일
@Binbin Qi This is the adjaccency matrix, I want the incidence matrix, which contains both 1,-1 and 0 values.
The Answer :
0 0 -1 0 -1 1
0 1 1 -1 0 0
- 1 -1 0 0 1 0
1 0 0 1 0 -1

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by