% Tony Hyun Kim
% EE 278B, PS #7, Problem 5(c)
% Make sure that I've correctly generated Cauchy RV
close all;

a = 1;

f = 5*linspace(-1,1,1e3);
df = f(2)-f(1);
p = a./(a^2+(pi*f).^2); % Analytic formula
plot(f,p); hold on;

M = 1e5;
X = rand(M,1); % U[0,1] random variables
F = a/pi*tan(pi*(X-1/2)); % Convert to Cauchy RV
n = hist(F,f);
n = n/(df*sum(n));
plot(f,n,'r');

ylim([0 1/a]);