How to plot two point out, which is related to x*log2(x) as x->0

2 次查看(过去 30 天)
Now, I am learning Communication System 2, and I try to plot out entropy of binary memoryless source curve.
If I use following codes, there is no 2 points, (0,0) and (1,0). I guess that it is because x->0 but log2(x)->infinity so Matlab go wrong to plot out the points!
So, I want to know how you guys solve this problem, thanks!!!
p0 = 0:0.01:1 ;
p1 = 1 - p0 ;
H = (-1).*p0.*log2(p0) + (-1).*p1.*log2(p1) ;
plot(p0,H) ;

回答(2 个)

Walter Roberson
Walter Roberson 2021-5-4
p0 = 0:0.01:1;
syms P0
p1 = 1 - P0 ;
H = (-1).*P0.*log2(P0) + (-1).*p1.*log2(p1) ;
HH = arrayfun(@(P) limit(H,P0,P), p0);
plot(p0,HH) ;

Pei-I Chou
Pei-I Chou 2021-5-4
Thank!!!

类别

Help CenterFile Exchange 中查找有关 Wireless Communications 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by