I am trying to plot for binary entropy
4 ビュー (過去 30 日間)
古いコメントを表示
I am trying to plot binary entropy and the value of entropy is coming as NaN but, it shouldn't be NaN, it should be 0.
Here's my code:
%Question No 1
%H(p) versus probability of binary logic 1 (p)
p= 0:0.5:1
h= p.*(abs(log2(p)))+ (1-p).*(abs(log(1-p)))
plot(p,h);
1 件のコメント
yair mazal
2021 年 3 月 17 日
Obviously you also miss the "2" in the second call to the log function. You're using log in the base of 10.
回答 (1 件)
Walter Roberson
2018 年 1 月 31 日
If your equations are correct then nan is the correct answer for p values of 0 and p values of 1.
Suppose p = 0. Then log2(p) is -infinity. p.*log2(p) is 0 * -infinity which is nan.
For p=1 something similar takes place.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Log Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!