How to find First Zagreb Entropy using Matlab code?
조회 수: 7 (최근 30일)
이전 댓글 표시
I have a Graph, and I want to find First Zagreb index and Entropy using Matlab code. Please suggest.
댓글 수: 0
답변 (1개)
Rushil
2025년 1월 24일
Hi Imran
From the question, I assume that there is a MATLAB “graph” object in use. A typical graph object is used as follows:
s = [1 1 2 3]; % source nodes
t = [2 3 3 4]; % target nodes
G = graph(s, t);
You can read more about the "graph" object here:
Now, the first zagreb index can be computed by summing over the squares of degrees of all nodes. Also, a common way to calculate entropy is using Shannon entropy using the degrees of the nodes. Below is the implementation of the same:
degrees = degree(G);
firstZagrebIndex = sum(degrees.^2);
degreeCounts = histcounts(degrees, 'Normalization', 'probability');
entropy = -sum(degreeCounts .* log2(degreeCounts + eps)); % eps is used to avoid log(0)
To read more about Shannon entropy you can visit and scroll down on this page to "More About":
Hope it helps
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!