%Chapter 8, problem 6
%for a Gaussian distribution with a given variance, v1, what is a uniform distribution with the same entropy
%Shuimei Zhang
function problem6d(sigma)
%% paremeter setting
a = sigma * sqrt(2*pi*exp(1))/2;
x_normal = - 5*sigma: 0.001: 5*sigma;
x_uniform = -a: 0.001: a;
x_sigma = -sigma:0.001:sigma;
p_uniform = ones(length(x_uniform), 1)/(2*a);
p_normal = exp(-x_normal.^2/2/sigma^2)/(sigma*sqrt(2*pi));
p_normal_fill = exp(-x_sigma.^2/2/sigma^2)/(sigma*sqrt(2*pi));
%% plot the figures
% figure (1);

plot(x_normal, p_normal,'k');
axis tight;
hold on
plot(x_uniform, p_uniform,'r');
ax = area(x_sigma, p_normal_fill,'LineStyle',':');
ax.FaceColor = 'yellow';
plot(x_normal, p_normal);
xlabel('x');
ylabel('probability');
legend('normal', 'uniform')
title('Given sigma =1, and the same differentical entropy')
plot([-a,-a],[0,1/(2*a)],'r');
plot([a,a],[0,1/(2*a)],'r');
