\documentclass{article}
\usepackage{graphicx}
\usepackage{fullpage}[]
\usepackage{cancel}[]
\usepackage{amssymb,amsmath}
\usepackage{url}
\begin{document}

\noindent  Homework 6 -- March 8, 2006 \hfill \textbf{Solution} prepared by Tobin Fricke\\
Physics 402 -- Probability  \hfill  Prof. S.G. Rajeev, Univ. of Rochester \\

\begin{enumerate}

\item[16.] \emph{Let $\xi_1, \xi_2$ be two independent Gaussian random variables, both of zero mean and unit variance.  What are the probability densities of the variables $\rho = (1/2)\left(\xi_1^2 + \xi_2^2\right)$ and $\theta = \arctan \frac{\xi_2}{\xi_1}$?}

\begin{equation}
\boxed{\begin{array}{l}
p_\rho(x) = 
\left\{\begin{array}{ll}
e^{-x} & 0 \leq x < \infty \\
0          & \mathrm{otherwise} 
\end{array}\right.  \\
\\
p_\theta(x) = 
\left\{\begin{array}{ll}
1/2\pi     & 0 \leq x < 2\pi \\
0          & \mathrm{otherwise} 
\end{array}\right.
\end{array}}
\end{equation}

\item[17.] \emph{Let $\eta_1, \eta_2$ be independent random variables with uniform (constant) probability density in the range $[0,1]$.  Find changes of variables $\xi_1 = f_1(\eta_1,\eta_2)$, $\xi_2 = f_2(\eta_1,\eta_2)$ which produces a pair of independent Gaussian random variables of zero mean and unit variance.}

This is known as the \textbf{Box-Muller method}.

\begin{equation}
\boxed{\begin{array}{l}
\xi_1 = f_1(\eta_1,\eta_2) = \sqrt{-2 \log \eta_1} \cos\left(2\pi \eta_2\right)\\
\xi_2 = f_2(\eta_1,\eta_2) = \sqrt{-2 \log \eta_1} \sin\left(2\pi \eta_2\right)
\end{array}}
\end{equation}

\item[18.] \emph{Generate a data set of a thousand values of a Gaussian random variable of zero mean and unit standard deviation, starting from the built-in function in most computer languages that produces uniform variables in the range $[0,1]$. Plot a histogram of the relative frequencies of this data set against the predicted probability density function}

\begin{verbatim}
% Generate the uniformly distributed random numbers
eta1 = rand(500,1);
eta2 = rand(500,1);

% Use the Box-Muller transform to get normally distributed numbers
xi1 = sqrt(-2 * log(eta1)) .* cos(2*pi*eta2);
xi2 = sqrt(-2 * log(eta1)) .* sin(2*pi*eta2);

% Produce a histogram
[rf, x] = hist([xi1; xi2], 50);

% Compute the theoretical distribution from the normal pdf
trf = (1/sqrt(2*pi)) * exp(-x.^2 /2);

% Normalize
rf = rf / sum(rf);
trf = trf / sum(trf);

% Produce the figure
h = figure;
plot(x, rf, '-x', x, trf, '-');
legend('experimental','theoretical');
title('generation of 1000 random deviates using box-muller method');
print(h, '-dpng', 'boxmuller.png');
close all;
\end{verbatim}

Here's a plot of the sample distribution and the theoretical distribution:

\includegraphics[scale=0.75]{boxmuller.pdf}
\end{enumerate}
\end{document}
