Binary Entropy by MATLAB

1k Views Asked by At

Im wondering how i can find the binary entropy between 0-1 without falling in the Nan value at 1?

H0 = (-p0.*log2(p0)-(1-p0).*log2(1-p0));
plot(p0,H0,'r*')

Many thanks

1

There are 1 best solutions below

0
On

Remove the first ($p=0$) and last ($p=1$) element before plotting

p0 = linspace(0, 1, 100);
p0 = p0(2 : end - 1);
H0 = (-p0. * log2(p0) - (1 - p0). * log2(1 - p0));
plot(p0, H0, 'r*')