% Problem 6

N = 1e6;

theta  = linspace(-pi,pi,100);
dtheta = theta(2)-theta(1);

% Roll the dice
THETA = -pi+2*pi*rand([N,1]);
p_THETA = hist(THETA,theta)/(N*dtheta);

subplot(211);
plot(theta,p_THETA,'.');
xlim([theta(1) theta(end)]);
xlabel('\theta');
ylabel('p_\theta');
title('\Theta ~ U[-\pi,\pi]');

% Definition of Y(t)
wt = 0;
y  = linspace(-1+1e-3,1-1e-3,100);
dy = y(2)-y(1);
Y = sin(wt+THETA);
p_Y = hist(Y,y)/(N*dy);

subplot(212);
plot(y,p_Y,'.');
p_Yc = 1/pi*1./sqrt(1-y.^2);
hold on;
plot(y,p_Yc,'r');