How to find First Zagreb Entropy using Matlab code?

3 ビュー (過去 30 日間)
Imran Khan
Imran Khan 2021 年 12 月 20 日
回答済み: Rushil 2025 年 1 月 24 日
I have a Graph, and I want to find First Zagreb index and Entropy using Matlab code. Please suggest.

回答 (1 件)

Rushil
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

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by